Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/backend/executor/query_dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -2874,7 +2874,6 @@ static int handle_match_create_return(cypher_executor *executor, cypher_query *q
{
if (unwind_before_create(query) || create_props_need_pipeline(query))
return handle_rowwise_write(executor, query, result, flags);
(void)flags;
cypher_match *match = find_match_clause(query);
cypher_create *create = find_create_clause(query);
cypher_return *ret = find_return_clause(query);
Expand Down Expand Up @@ -3014,11 +3013,13 @@ static int handle_match_create_return(cypher_executor *executor, cypher_query *q
return 0;
}

int rc = execute_match_create_return_query(executor, match, create, ret, result);
if (rc >= 0) {
result->success = true;
}
return rc;
/* The legacy path ran MATCH + CREATE, then the MATCH again for the
* RETURN: the RETURN saw the new nodes, and a CREATE that bound no
* matched variable ran once for every row, or for no row
* (GQLITE-T-0488). The row pipeline runs the CREATE once per row and
* returns those rows. */
(void)match;
return handle_rowwise_write(executor, query, result, flags);
}

static int handle_match_return(cypher_executor *executor, cypher_query *query,
Expand Down
39 changes: 39 additions & 0 deletions tests/functional/106_create_per_row_return.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-- ========================================================================
-- Test 106: MATCH ... CREATE ... RETURN creates once per row
-- (GQLITE-T-0488)
-- ========================================================================
-- PURPOSE: when the created pattern bound no variable that the RETURN read,
-- the CREATE ran once, and the RETURN ran the MATCH again after
-- the write (it saw the new node). A MATCH with no rows and an
-- aggregate RETURN still created a node.
-- NOTE: Assertions are hard: _assert has CHECK (ok = 1), so under
-- `sqlite3 -bail` any failed expectation aborts the run.
-- ========================================================================

.load ./build/graphqlite

SELECT '=== Test 106: CREATE per row with RETURN ===' as test_section;

CREATE TEMP TABLE _assert(name TEXT, ok INTEGER CHECK (ok = 1));

SELECT cypher('CREATE (:S106 {id: 1}), (:S106 {id: 2})') as setup;

INSERT INTO _assert SELECT 'RETURN gives the MATCH rows only',
json(cypher('MATCH (a:S106) CREATE (a)-[:T]->(:N106) RETURN a.id AS id ORDER BY id'))
= json('[{"id":1},{"id":2}]');
INSERT INTO _assert SELECT 'one node per row',
json(cypher('MATCH (n:N106) RETURN count(n) AS c')) = json('[{"c":2}]');

INSERT INTO _assert SELECT 'aggregate RETURN counts the rows',
json(cypher('MATCH (a:S106) CREATE (:M106 {k: a.id}) RETURN count(*) AS c'))
= json('[{"c":2}]');
INSERT INTO _assert SELECT 'aggregate RETURN: one node per row',
json(cypher('MATCH (n:M106) RETURN count(n) AS c')) = json('[{"c":2}]');

INSERT INTO _assert SELECT 'no rows: count is 0',
json(cypher('MATCH (a:Missing106) CREATE (:Z106) RETURN count(*) AS c'))
= json('[{"c":0}]');
INSERT INTO _assert SELECT 'no rows: nothing created',
json(cypher('MATCH (n:Z106) RETURN count(n) AS c')) = json('[{"c":0}]');

SELECT 'Test 106 passed: ' || count(*) || ' assertions' AS result FROM _assert;
3 changes: 1 addition & 2 deletions tests/metamorphic/known.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@
{"relation": "^expr_context/(head|reduce|call)/", "kind": "mismatch", "task": "GQLITE-T-0482"},
{"relation": "^expr_context/.*/nested", "kind": "mismatch", "task": "GQLITE-T-0483"},
{"relation": "^expr_context/", "kind": "mismatch", "query": "reverse\\(", "task": "GQLITE-T-0483"},
{"relation": "^expr_context/", "kind": "mismatch", "query": "reduce\\(acc = ''", "task": "GQLITE-T-0481"},
{"relation": "^write_return/", "kind": "mismatch", "query": "CREATE (\\(\\w+\\)-\\[:\\w+[^\\]]*\\]->)?\\(:New", "task": "GQLITE-T-0488"}
{"relation": "^expr_context/", "kind": "mismatch", "query": "reduce\\(acc = ''", "task": "GQLITE-T-0481"}
]
Loading