bitnine-oss / agensgraph

AgensGraph, a transactional graph database based on PostgreSQL
http://www.agensgraph.org
Other
1.32k stars 146 forks source link

BUG - "duplicate key value violates unique constraint" on when running merge query. #606

Open aviNrich opened 1 year ago

aviNrich commented 1 year ago

I have set my CREATE UNIQUE PROPERTY INDEX IF NOT EXISTS entities_u ON entities(text, label) I'm running the query inside a transaction:

MERGE (n:entities { text : $2::text, label : $3::text  })
       SET n.type = $1::text, n.text = $2::text, n.label = $3::text 
       RETURN n

error: duplicate key value violates unique constraint "entities_u" Merge is some sort of an UPSERT, dont you think that "duplicate key value violates unique constraint" is not suitable here? Thanks

emotionbug commented 1 year ago

I can't reproduce this issue. Can you provide more details?

CREATE UNIQUE PROPERTY INDEX entities_u ON entities(text, label);
MERGE (n:entities { text : 'ABC', label : 'DEF'  })
SET n.type = 'ABC', n.text = 'ABC', n.label = 'DEF'
RETURN n;
                              n                              
-------------------------------------------------------------
 entities[3.1]{"text": "ABC", "type": "ABC", "label": "DEF"}
(1 row)

MERGE (n:entities { text : 'ABC', label : 'DEF'  })
SET n.type = 'ABC', n.text = 'ABC', n.label = 'DEF'
RETURN n;
                              n                              
-------------------------------------------------------------
 entities[3.1]{"text": "ABC", "type": "ABC", "label": "DEF"}
(1 row)

DROP GRAPH cypher_dml2 CASCADE;
aviNrich commented 1 year ago

@emotionbug thanks for the quick reply. Its a concurrent issue, I have a lot of traffic to this node, once in 10,000 calls it throws this error....