@@ -1865,6 +1865,114 @@ $$) AS (edge_count agtype);
18651865 0
18661866(1 row)
18671867
1868+ -- Issue 1954: CREATE + WITH + MERGE causes "vertex was deleted" error
1869+ -- when the number of input rows exceeds the snapshot's command ID window.
1870+ -- entity_exists() used a stale curcid, making recently-created vertices
1871+ -- invisible on later iterations.
1872+ --
1873+ SELECT * FROM create_graph('issue_1954');
1874+ NOTICE: graph "issue_1954" has been created
1875+ create_graph
1876+ --------------
1877+
1878+ (1 row)
1879+
1880+ -- Setup: create source nodes and relationships (3 rows to trigger the bug)
1881+ SELECT * FROM cypher('issue_1954', $$
1882+ CREATE (:A {name: 'a1'})-[:R]->(:B {name: 'b1'}),
1883+ (:A {name: 'a2'})-[:R]->(:B {name: 'b2'}),
1884+ (:A {name: 'a3'})-[:R]->(:B {name: 'b3'})
1885+ $$) AS (result agtype);
1886+ result
1887+ --------
1888+ (0 rows)
1889+
1890+ -- This query would fail with "vertex assigned to variable c was deleted"
1891+ -- on the 3rd row before the fix.
1892+ SELECT * FROM cypher('issue_1954', $$
1893+ MATCH (a:A)-[:R]->(b:B)
1894+ CREATE (c:C {name: a.name + '|' + b.name})
1895+ WITH a, b, c
1896+ MERGE (a)-[:LINK]->(c)
1897+ RETURN a.name, b.name, c.name
1898+ ORDER BY a.name
1899+ $$) AS (a agtype, b agtype, c agtype);
1900+ a | b | c
1901+ ------+------+---------
1902+ "a1" | "b1" | "a1|b1"
1903+ "a2" | "b2" | "a2|b2"
1904+ "a3" | "b3" | "a3|b3"
1905+ (3 rows)
1906+
1907+ -- Verify edges were created
1908+ SELECT * FROM cypher('issue_1954', $$
1909+ MATCH (a:A)-[:LINK]->(c:C)
1910+ RETURN a.name, c.name
1911+ ORDER BY a.name
1912+ $$) AS (a agtype, c agtype);
1913+ a | c
1914+ ------+---------
1915+ "a1" | "a1|b1"
1916+ "a2" | "a2|b2"
1917+ "a3" | "a3|b3"
1918+ (3 rows)
1919+
1920+ -- Test with two MERGEs (more complex case from the original report)
1921+ SELECT * FROM cypher('issue_1954', $$
1922+ MATCH ()-[e:LINK]->() DELETE e
1923+ $$) AS (result agtype);
1924+ result
1925+ --------
1926+ (0 rows)
1927+
1928+ SELECT * FROM cypher('issue_1954', $$
1929+ MATCH (c:C) DELETE c
1930+ $$) AS (result agtype);
1931+ result
1932+ --------
1933+ (0 rows)
1934+
1935+ SELECT * FROM cypher('issue_1954', $$
1936+ MATCH (a:A)-[:R]->(b:B)
1937+ CREATE (c:C {name: a.name + '|' + b.name})
1938+ WITH a, b, c
1939+ MERGE (a)-[:LINK1]->(c)
1940+ MERGE (b)-[:LINK2]->(c)
1941+ RETURN a.name, b.name, c.name
1942+ ORDER BY a.name
1943+ $$) AS (a agtype, b agtype, c agtype);
1944+ a | b | c
1945+ ------+------+---------
1946+ "a1" | "b1" | "a1|b1"
1947+ "a2" | "b2" | "a2|b2"
1948+ "a3" | "b3" | "a3|b3"
1949+ (3 rows)
1950+
1951+ -- Verify both sets of edges
1952+ SELECT * FROM cypher('issue_1954', $$
1953+ MATCH (a:A)-[:LINK1]->(c:C)
1954+ RETURN a.name, c.name
1955+ ORDER BY a.name
1956+ $$) AS (a agtype, c agtype);
1957+ a | c
1958+ ------+---------
1959+ "a1" | "a1|b1"
1960+ "a2" | "a2|b2"
1961+ "a3" | "a3|b3"
1962+ (3 rows)
1963+
1964+ SELECT * FROM cypher('issue_1954', $$
1965+ MATCH (b:B)-[:LINK2]->(c:C)
1966+ RETURN b.name, c.name
1967+ ORDER BY b.name
1968+ $$) AS (b agtype, c agtype);
1969+ b | c
1970+ ------+---------
1971+ "b1" | "a1|b1"
1972+ "b2" | "a2|b2"
1973+ "b3" | "a3|b3"
1974+ (3 rows)
1975+
18681976--
18691977-- clean up graphs
18701978--
@@ -1888,6 +1996,11 @@ SELECT * FROM cypher('issue_1446', $$ MATCH (n) DETACH DELETE n $$) AS (a agtype
18881996---
18891997(0 rows)
18901998
1999+ SELECT * FROM cypher('issue_1954', $$ MATCH (n) DETACH DELETE n $$) AS (a agtype);
2000+ a
2001+ ---
2002+ (0 rows)
2003+
18912004--
18922005-- delete graphs
18932006--
@@ -1985,6 +2098,23 @@ NOTICE: graph "issue_1446" has been dropped
19852098
19862099(1 row)
19872100
2101+ SELECT drop_graph('issue_1954', true);
2102+ NOTICE: drop cascades to 9 other objects
2103+ DETAIL: drop cascades to table issue_1954._ag_label_vertex
2104+ drop cascades to table issue_1954._ag_label_edge
2105+ drop cascades to table issue_1954."A"
2106+ drop cascades to table issue_1954."R"
2107+ drop cascades to table issue_1954."B"
2108+ drop cascades to table issue_1954."C"
2109+ drop cascades to table issue_1954."LINK"
2110+ drop cascades to table issue_1954."LINK1"
2111+ drop cascades to table issue_1954."LINK2"
2112+ NOTICE: graph "issue_1954" has been dropped
2113+ drop_graph
2114+ ------------
2115+
2116+ (1 row)
2117+
19882118--
19892119-- End
19902120--
0 commit comments