Skip to content

Commit

Permalink
fix(qc): don't recurse into children of result nodes
Browse files Browse the repository at this point in the history
Fixes the broken query plans generated for updates and inserts where the
result of the query can satisfied with the query arguments.
  • Loading branch information
aqrln committed Feb 5, 2025
1 parent 853c875 commit d157164
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
7 changes: 6 additions & 1 deletion query-compiler/query-compiler/src/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ impl<'a, 'b> NodeTranslator<'a, 'b> {
fn translate_query(&mut self) -> TranslateResult<Expression> {
self.graph.mark_visited(&self.node);

let children = self.process_children()?;
// Don't recurse into children if the current node is already a result node.
let children = if !self.graph.is_result_node(&self.node) {
self.process_children()?
} else {
Vec::new()
};

let mut node = self.graph.pluck_node(&self.node);

Expand Down
13 changes: 13 additions & 0 deletions query-compiler/query-compiler/tests/data/update-one-returning.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"modelName": "User",
"action": "updateOne",
"query": {
"arguments": {
"where": { "email": "[email protected]" },
"data": { "email": "[email protected]" }
},
"selection": {
"email": true
}
}
}
10 changes: 10 additions & 0 deletions ...y-compiler/query-compiler/tests/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: query-compiler/query-compiler/tests/queries.rs
expression: pretty
input_file: query-compiler/query-compiler/tests/data/update-one-returning.json
---
unique (query «UPDATE "public"."User" SET "email" = $1 WHERE
("public"."User"."email" = $2 AND 1=1) RETURNING
"public"."User"."id", "public"."User"."email"»
params [const(String("[email protected]")),
const(String("[email protected]"))])

0 comments on commit d157164

Please sign in to comment.