age: MERGE incorrectly creates multiple vertices

SELECT * FROM cypher('playground', $$
unwind ["foo", "foo"] as each
merge (v:TEST {name: each})
return v
$$) AS (v agtype)

returns

[
  {
    "v": {
      "id": 3659174697238531,
      "label": "TEST",
      "properties": {
        "name": "foo"
      }
    }
  },
  {
    "v": {
      "id": 3659174697238532,
      "label": "TEST",
      "properties": {
        "name": "foo"
      }
    }
  }
]

creates two vertices when it should only create one. (confirmed with neo4j)

About this issue

  • Original URL
  • State: closed
  • Created 3 months ago
  • Comments: 16 (9 by maintainers)

Most upvoted comments

@jrgemignani Amazing. Thanks again!

@mingfang PR #1718 should address this issue once it is reviewed and merged.

@mingfang Update: I currently have a fix for this and am reviewing it, creating test cases, and cleaning up the code. If all goes well, a PR should be available Monday or Tuesday.

Sorry for the long delay, but this particular issue required a bit of a rewrite of MERGE.

@jrgemignani Thanks for the update.
I appreciate all your hard work. Thanks!

Also this is only a problem when multiple MERGE are called in the same query. e.g. this works as expected, only one vertex is created after both queries.

SELECT * FROM cypher('playground', $$
unwind ["foo"] as each
merge (v:TEST {name: each})
return v
$$) AS (v agtype)

SELECT * FROM cypher('playground', $$
unwind ["foo"] as each
merge (v:TEST {name: each})
return v
$$) AS (v agtype)

I’m guessing that multiple MERGE in the same query somehow is not seeing each statement’s “state” since the transaction is not committed yet. Totally a wild guess.