age: MERGE does not set properties involving variables
Note: This task is ONLY assigned to people in the ‘refactor create\merge’ project.
Describe the bug
If properties in the MERGE clause is set from a previous variable (i.e. .. MERGE ( {key: some_variable} ) ..
), that particular key-value pair is not persisted.
How are you accessing AGE (Command line, driver, etc.)? Command line
What data setup do we need to do?
...
SELECT * FROM cypher('xyz',
$$
CREATE (x:Label1{arr:[1,2,3,4]})
RETURN x
$$) as (a agtype);
...
What is the necessary configuration info needed? N/A
What is the command that caused the error?
SELECT * FROM cypher('xyz',
$$
MATCH (x:Label1{arr:[1,2,3,4]})
MERGE (y:Label2{key1:2, key2:x.arr, key3:3})
RETURN y
$$) as (a agtype);
Behavior
The key2: x.arr
pair is not persisted in the output.
Output:
a
-------------------------------------------------------------------------------------------
{"id": 1688849860263937, "label": "Label2", "properties": {"key1": 2, "key3": 3}}::vertex
(1 row)
Expected behavior Expected output:
a
-------------------------------------------------------------------------------------------
{"id": 1688849860263937, "label": "Label2", "properties": {"key1": 2, "key2": [1, 2, 3, 4], "key3": 3}}::vertex
(1 row)
Environment (please complete the following information): PG15.4 Master branch Ubuntu 22.04
Additional context N/A
About this issue
- Original URL
- State: closed
- Created 10 months ago
- Comments: 17 (13 by maintainers)
It appears that the merge code (including the expression evaluation) is working correctly with what it is given. It is just that sometimes it gets a NULL value instead of the variable
x
in specific cases. So, I don’t think MERGE is the issue here. Something prior to MERGE is messing upx
.It also appears that the transform logic is working correctly, at least up to the RETURN transform for -
MATCH (x:Label1{arr:[1,2,3,4]}) MERGE (y:Label2{key2: id(x)}) RETURN y
It might be possible the planner is removing the variable
x
.I compiled and tested PG11 1.1.0 and this issue exists there as well.
The query also succeeds in these cases -
@jrgemignani Thanks for the PR. The issue is resolved.
@rafsun42 PR #1441 was created to address this issue.
I traced it through the code and it appears that the variable from the MATCH is not getting to the MERGE when the variable isn’t present in the RETURN list. Unless, there isn’t a RETURN, then it works.
@ksheroz @CapnSpek
Query plans are usually useful. However, for this issue I would prefer using a debugger.
I think this file-
src/backend/executor/cypher_merge.c
may be worthwhile to step through with a debugger.Some observations:
CREATE
instead ofMERGE
works just fineMERGE
twice also works just fineNext, let us analyze the Query Plan Trees for
MATCH
-MERGE
,MATCH
-CREATE
, andMATCH
-MERGE
-MERGE
queries.MATCH
-MERGE
:MATCH
-CREATE
:MATCH
-MERGE
-MERGE
:Cannot draw a conclusion
@ksheroz What do you think?
@rafsun42 kindly assign the task to me
Kindly assign the project to me. Thanks.
@rafsun42 Assign it to me please