vladiksun commented on issue #562:
URL: https://github.com/apache/age/issues/562#issuecomment-1693144356
@jrgemignani I'd like to give you more real life use case involving the
graph traversal.
```
SET search_path = ag_catalog, "$user", public;
--- create test graph ---
DO
$do$
BEGIN
--LOAD 'age';
SET search_path = ag_catalog, "$user", public;
BEGIN
PERFORM ag_catalog.drop_graph('test_graph', true);
EXCEPTION WHEN OTHERS
THEN -- ignore --
END;
PERFORM ag_catalog.create_graph('test_graph');
END
$do$;
--- create test label ---
select ag_catalog.create_vlabel('test_graph','domain');
--- create test label GIN index ---
CREATE INDEX domain_gin_idx ON test_graph.domain USING GIN (properties);
--- create test label BTREE functional index on 'type' property ---
DO
$do$
DECLARE
collection varchar(32);
collections TEXT[]:= '{ domain }';
graph_oid oid;
index_query text:= '
CREATE INDEX %s_btree_type_func_idx ON test_graph."%s" USING
BTREE (
ag_catalog.agtype_access_operator(VARIADIC
ARRAY[ag_catalog._agtype_build_vertex(id, ag_catalog._label_name(''%s'', id),
properties), ''"type"''::ag_catalog.agtype])
);
';
BEGIN
select graphid from ag_catalog.ag_graph where name = 'test_graph'
into graph_oid;
foreach collection in array collections
loop
EXECUTE format(index_query, collection, collection,
graph_oid);
end loop;
END
$do$;
--- create test relation ---
select ag_catalog.create_elabel('test_graph','parent');
--- create test relation GIN index---
CREATE INDEX parent_gin_idx ON test_graph.parent USING GIN (properties);
--- generate test data not hidden ---
DO
$do$
BEGIN
FOR i IN 1..10000 LOOP
EXECUTE format('
select * from ag_catalog.cypher(''test_graph'',
$$
CREATE (Org_level_1_%s: domain {`id`:"Org_level_1_%s",
`type`:"Organization", name: "Org_level_1_%s" ,`hidden`:false })
CREATE (Org_level_2_%s: domain {`id`:"Org_level_2_%s",
`type`:"Organization", name: "Org_level_2_%s" ,`hidden`:false })
CREATE (Org_level_3_%s: domain {`id`:"Org_level_3_%s",
`type`:"Organization", name: "Org_level_3_%s" ,`hidden`:false })
CREATE (Org_level_4_%s: domain {`id`:"Org_level_4_%s",
`type`:"Organization", name: "Org_level_4_%s" ,`hidden`:false })
CREATE (Dep_level_5_%s: domain {`id`:"Dep_level_5_%s",
`type`:"Department", name: "Dep_level_5_%s" ,`hidden`:false })
CREATE (Dep_level_5_%s)-[_rel1:`parent` { from:
''Dep_level_5_%s'', to: ''Org_level_4_%s'', hidden: false, toCollection:
''domain'', fromCollection: ''domain'' }]->(Org_level_4_%s)
CREATE (Org_level_4_%s)-[_rel2:`parent` { from:
''Org_level_4_%s'', to: ''Org_level_3_%s'', hidden: false, toCollection:
''domain'', fromCollection: ''domain'' }]->(Org_level_3_%s)
CREATE (Org_level_3_%s)-[_rel3:`parent` { from:
''Org_level_3_%s'', to: ''Org_level_2_%s'', hidden: false, toCollection:
''domain'', fromCollection: ''domain'' }]->(Org_level_2_%s)
CREATE (Org_level_2_%s)-[_rel4:`parent` { from:
''Org_level_2_%s'', to: ''Org_level_1_%s'', hidden: false, toCollection:
''domain'', fromCollection: ''domain'' }]->(Org_level_1_%s)
$$
) as (any_vertex ag_catalog.agtype)
', VARIADIC ARRAY(SELECT array_fill('iter_' || i::text,
'{100}')) );
END LOOP;
END
$do$;
--- take the plan ---
select properties from ag_catalog.cypher('test_graph',
$$
EXPLAIN ANALYZE
MATCH (to:`domain` {hidden: false, id:
'Org_level_1_iter_1'})<-[any_edge:`parent`*1..10 {hidden: false,
fromCollection: 'domain', toCollection: 'domain'}]-(from:`domain` {hidden:
false})
WHERE
from.type = 'Organization'
OR from.type = 'Department'
RETURN DISTINCT properties(from)
LIMIT 1000
$$
) as (properties agtype);
```
The plan I see looks like this

As I understand the **BitmapAnd** is split into **BitmapOr** that uses
functional BTREE index and **Bitmap** that uses GIN index.
Probably the assumption that WHERE operates on results of a MATCH could be
wrong in some scenarios ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]