Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(qe): make UpdateRecord::WithSelection nodes return RecordSelection #4508

Merged
merged 10 commits into from
Dec 4, 2023

Conversation

aqrln
Copy link
Member

@aqrln aqrln commented Nov 30, 2023

Query graph nodes that are not result nodes and fulfill the requirements of other nodes don't inherently need names because their results aren't serialized. However, we still need some name to be able to build RecordSelection because it's required there. Previously the update node with selection that has no name would return a QueryResult::Id instead of QueryResult::RecordSelection to work around that, but it caused problems as the query interpreter relied on QueryResult::Id being the primary identifier and not arbitrary fields.

This PR makes the name required for UpdateRecord::WithSelection and provides a stub name when the node doesn't directly correspond to the client's query. This is consistent with other intermediate nodes that need to build RecordSelection. Some of them use constant placeholder names (like find_children_by_parent for RelatedRecordsQuery), some of them use empty strings (e.g. CreateRecord does this).

I chose an empty string because it needs to be owned here and an empty String::new() doesn't allocate memory, and the specific value doesn't matter anyway because there's likely not even a way to observe this name (it's not used in Display and ToGraphviz impls for UpdateRecord).

Fixes: prisma/prisma#21182

@aqrln aqrln self-assigned this Nov 30, 2023
@aqrln aqrln added this to the 5.7.0 milestone Nov 30, 2023
Copy link

codspeed-hq bot commented Nov 30, 2023

CodSpeed Performance Report

Merging #4508 will not alter performance

Comparing fix-qe-regression-in-queries-with-update-returning (27b325d) with main (ff1752c)

Summary

✅ 11 untouched benchmarks

@aqrln aqrln requested a review from Weakky November 30, 2023 20:13
- Change `FieldSelection::matches` to mean that the current field
  selection is a subset of `SelectionResult` instead of a superset.

- Project the selected tuple into the expected cardinality.
`SelectionResult::new` is not generic, compiler already knows the type.
@aqrln aqrln force-pushed the fix-qe-regression-in-queries-with-update-returning branch from d5731c7 to 94c60ce Compare December 1, 2023 16:11
Even though there technically should be a need for name if the node's
results don't need to be serialized and only fulfill the requirements of
another node, we still need some name to build `RecordSelection`.

Previously the update node with selection that has no name would return
a `QueryResult::Id` instead of `QueryResult::RecordSelection` to work
around that, but it caused problems as the query interpreter relied on
`QueryResult::Id` being the primary identifier and not arbitrary fields.

This commit makes the name required for `UpdateRecord::WithSelection`
and provides a dummy name when the node doesn't directly correspond to
user's query. This is consistent with other intermediate nodes that need
to build `RecordSelection` and use dummy names (like `reload` or
`find_children_by_parent`) or empty strings.
@aqrln aqrln changed the title fix(qe): regression in queries with update returning fix(qe): make UpdateRecord::WithSelection nodes return RecordSelection Dec 1, 2023
@@ -200,7 +200,7 @@ where

Query::Write(WriteQuery::UpdateRecord(UpdateRecord::WithSelection(
UpdateRecordWithSelection {
name: Some(field.name.to_owned()),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed to_owned() because field.name is already an owned string, and we don't need it anymore here so we can just move it without cloning.

@aqrln aqrln marked this pull request as ready for review December 1, 2023 17:35
@aqrln aqrln requested a review from a team as a code owner December 1, 2023 17:35
@aqrln aqrln requested review from jkomyno and removed request for a team December 1, 2023 17:35
@aqrln aqrln requested review from miguelff and removed request for jkomyno December 1, 2023 18:15
Copy link
Contributor

@miguelff miguelff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good, and the reproduction looks solid

Copy link
Member

@Weakky Weakky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job 👍

@aqrln aqrln merged commit f9fa153 into main Dec 4, 2023
58 checks passed
@aqrln aqrln deleted the fix-qe-regression-in-queries-with-update-returning branch December 4, 2023 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants