Skip to content

Correctness: MERGE of an edge onto bound vertices stores start_id = end_id = 0 on 32-bit builds #2601

Closed

Description

@laquereric

On a build with SIZEOF_DATUM = 4 (the 32-bit support added in #2286; PGlite's wasm32 build uses it), MERGE of an edge onto vertices bound by an earlier clause stores the edge with start_id and end_id = 0:

SELECT * FROM cypher('g', $$ MERGE (a:N {k:'x'}) MERGE (b:N {k:'y'}) MERGE (a)-[:E]->(b) $$) AS (r agtype);
SELECT * FROM cypher('g', $$ MATCH (a:N {k:'x'}), (b:N {k:'y'}) MERGE (a)-[:E]->(b) $$) AS (r agtype);

The edge row is stored, but no MATCH walks it, and a second MERGE of the same edge stores a duplicate (data correctness).

Cause: path_entry's id, start_id and end_id are graphid fields, but merge_vertex and merge_edge in src/backend/executor/cypher_merge.c store Datums in them and read them back as Datums, while prebuild_path stores real graphids for already-bound vertices. On a 64-bit build the two are the same bits; with 4-byte Datums a graphid Datum is a pointer, so the edge is written with whatever that address holds.

Found by running one Cypher workload on PostgreSQL 17 (64-bit) and in PGlite 0.4.6 (wasm32): 606 of 617 statements agreed before the fix, 617 after. A fix follows as a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions