diff --git a/src/backend/rewrite/rewriteGraphTable.c b/src/backend/rewrite/rewriteGraphTable.c index 33d4e866d74..d8c364d6588 100644 --- a/src/backend/rewrite/rewriteGraphTable.c +++ b/src/backend/rewrite/rewriteGraphTable.c @@ -1152,7 +1152,11 @@ replace_property_refs(Oid propgraphid, Node *node, const List *mappings) context.mappings = mappings; context.propgraphid = propgraphid; - return expression_tree_mutator(node, replace_property_refs_mutator, &context); + /* + * Invoke the mutator directly rather than through expression_tree_mutator() + * so that a top-level GraphPropertyRef is replaced too. + */ + return replace_property_refs_mutator(node, &context); } /* diff --git a/src/test/regress/expected/graph_table.out b/src/test/regress/expected/graph_table.out index cc6d80afd82..9e62d213e38 100644 --- a/src/test/regress/expected/graph_table.out +++ b/src/test/regress/expected/graph_table.out @@ -1044,4 +1044,23 @@ SELECT src.vname, count(*) FROM v1 AS src v13 | 1 (3 rows) +-- a WHERE clause that is a bare boolean property reference (a top-level +-- GraphPropertyRef) must be rewritten just like a nested property reference +ALTER PROPERTY GRAPH g1 ALTER VERTEX TABLE v1 ALTER LABEL vl1 ADD PROPERTIES (vprop1 > 15 AS is_big); +-- bare boolean property in an element pattern WHERE clause +SELECT * FROM GRAPH_TABLE (g1 MATCH (a IS vl1 WHERE a.is_big) COLUMNS (a.vname AS self)) ORDER BY self; + self +------ + v12 + v13 +(2 rows) + +-- bare boolean property in the graph pattern WHERE clause +SELECT * FROM GRAPH_TABLE (g1 MATCH (a IS vl1) WHERE a.is_big COLUMNS (a.vname AS self)) ORDER BY self; + self +------ + v12 + v13 +(2 rows) + -- leave the objects behind for pg_upgrade/pg_dump tests diff --git a/src/test/regress/sql/graph_table.sql b/src/test/regress/sql/graph_table.sql index 0e381ec72bc..46668233e64 100644 --- a/src/test/regress/sql/graph_table.sql +++ b/src/test/regress/sql/graph_table.sql @@ -596,4 +596,12 @@ SELECT src.vname, count(*) FROM v1 AS src HAVING count(*) >= (SELECT count(*) FROM GRAPH_TABLE (g1 MATCH (a IS vl1 | vl2) COLUMNS (a.vname AS n)) WHERE n = src.vname) ORDER BY vname; +-- a WHERE clause that is a bare boolean property reference (a top-level +-- GraphPropertyRef) must be rewritten just like a nested property reference +ALTER PROPERTY GRAPH g1 ALTER VERTEX TABLE v1 ALTER LABEL vl1 ADD PROPERTIES (vprop1 > 15 AS is_big); +-- bare boolean property in an element pattern WHERE clause +SELECT * FROM GRAPH_TABLE (g1 MATCH (a IS vl1 WHERE a.is_big) COLUMNS (a.vname AS self)) ORDER BY self; +-- bare boolean property in the graph pattern WHERE clause +SELECT * FROM GRAPH_TABLE (g1 MATCH (a IS vl1) WHERE a.is_big COLUMNS (a.vname AS self)) ORDER BY self; + -- leave the objects behind for pg_upgrade/pg_dump tests