Skip to content
Permalink
Browse files
Fix Bug in WHERE clause and property contraints
When the property contraints and the where clause are used together,
the property contraints are ignored.

There was a second issue where the where clause needs to be coerced to a
boolean value before ANDed with the property constraint quals
  • Loading branch information
JoshInnis committed May 11, 2022
1 parent e36983b commit 691fb0d5e3dbd5ac9328a0b7842d0806cc124986
Showing 5 changed files with 58 additions and 3 deletions.
@@ -190,6 +190,16 @@ SELECT * FROM cypher('agload_test_graph', $$MATCH(n:Country2 {iso2 : 'AT'})
1688849860263940 | "Austria" | "AT"
(1 row)

SELECT * FROM cypher('agload_test_graph', $$
MATCH (u:Country {region : "Europe"})
WHERE u.name =~ 'Cro.*'
RETURN u.name, u.region
$$) AS (result_1 agtype, result_2 agtype);
result_1 | result_2
-----------+----------
"Croatia" | "Europe"
(1 row)

SELECT drop_graph('agload_test_graph', true);
NOTICE: drop cascades to 7 other objects
DETAIL: drop cascades to table agload_test_graph._ag_label_vertex
@@ -1064,6 +1064,26 @@ $$) as (f agtype, t agtype);
"T" | "T"
(9 rows)

--
-- Constraints and WHERE clause together
--
SELECT * FROM cypher('cypher_match', $$
CREATE ({i: 1, j: 2, k: 3}), ({i: 1, j: 3}), ({i:2, k: 3})
$$) as (a agtype);
a
---
(0 rows)

SELECT * FROM cypher('cypher_match', $$
MATCH (n {j: 2})
WHERE n.i = 1
RETURN n
$$) as (n agtype);
n
--------------------------------------------------------------------------------------
{"id": 281474976710662, "label": "", "properties": {"i": 1, "j": 2, "k": 3}}::vertex
(1 row)

--
-- Clean up
--
@@ -53,4 +53,10 @@ SELECT * FROM cypher('agload_test_graph', $$MATCH(n:Country {iso2 : 'AT'})
SELECT * FROM cypher('agload_test_graph', $$MATCH(n:Country2 {iso2 : 'AT'})
RETURN id(n), n.name, n.iso2 $$) as ("id(n)" agtype, "n.name" agtype, "n.iso2" agtype);

SELECT * FROM cypher('agload_test_graph', $$
MATCH (u:Country {region : "Europe"})
WHERE u.name =~ 'Cro.*'
RETURN u.name, u.region
$$) AS (result_1 agtype, result_2 agtype);

SELECT drop_graph('agload_test_graph', true);
@@ -536,6 +536,19 @@ SELECT * FROM cypher('cypher_match', $$
RETURN f.name, t.name
$$) as (f agtype, t agtype);

--
-- Constraints and WHERE clause together
--
SELECT * FROM cypher('cypher_match', $$
CREATE ({i: 1, j: 2, k: 3}), ({i: 1, j: 3}), ({i:2, k: 3})
$$) as (a agtype);

SELECT * FROM cypher('cypher_match', $$
MATCH (n {j: 2})
WHERE n.i = 1
RETURN n
$$) as (n agtype);

--
-- Clean up
--
@@ -2543,7 +2543,7 @@ static void transform_match_pattern(cypher_parsestate *cpstate, Query *query,
Expr *prop_qual = makeBoolExpr(AND_EXPR,
cpstate->property_constraint_quals, -1);

if (quals == NIL)
if (expr == NULL)
{
expr = prop_qual;
}
@@ -2560,13 +2560,19 @@ static void transform_match_pattern(cypher_parsestate *cpstate, Query *query,

where_qual = (Expr *)transform_cypher_expr(cpstate, where,
EXPR_KIND_WHERE);

if (quals == NIL)
if (expr == NULL)
{
expr = where_qual;
}
else
{
/*
* coerce the WHERE clause to a boolean before AND with the property
* contraints, otherwise there could be evaluation issues.
*/
where_qual = (Expr *)coerce_to_boolean(pstate, (Node *)where_qual,
"WHERE");

expr = makeBoolExpr(AND_EXPR, list_make2(expr, where_qual), -1);
}
}

0 comments on commit 691fb0d

Please sign in to comment.