-
Notifications
You must be signed in to change notification settings - Fork 580
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
refactor(frontend): rework UPDATE
to support subqueries
#19402
Conversation
Signed-off-by: Bugen Zhao <[email protected]>
Signed-off-by: Bugen Zhao <[email protected]>
Signed-off-by: Bugen Zhao <[email protected]>
63e80b9
to
d387ca7
Compare
Signed-off-by: Bugen Zhao <[email protected]>
Signed-off-by: Bugen Zhao <[email protected]>
Signed-off-by: Bugen Zhao <[email protected]>
UPDATE
UPDATE
to support subqueries
Signed-off-by: Bugen Zhao <[email protected]>
Signed-off-by: Bugen Zhao <[email protected]>
Signed-off-by: Bugen Zhao <[email protected]>
Signed-off-by: Bugen Zhao <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A corner case
create table t (a int, b int);
create table y (a int, b int);
insert into y values(11,11),(22,22);
insert into t values(1,1),(2,2);
update t set (a,b) = (select y.a, y.b from y);
-- PG will throw an error ERROR: more than one row returned by a subquery used as an expression
-- but RW will succeed to execute and return UPDATE 4 rows
In this case, the query I think it's because we don't enforce input of |
Oh, that cloud be the problem |
Will fix in #19452 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! The idea to use a new kind (UpdateSet) of subquery is brilliant. Please make sure the previous corner case is fixed and add it to a testcase.
Signed-off-by: Bugen Zhao <[email protected]>
I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.
What's changed and what's your intention?
Rework
UPDATE
to support subqueries. Close #2672.Previously,
Update
has a list ofindex -> expr
to calculate the updated value for each column. This means that its capability cannot exceed a singleProject
node, so that there's no way to support subquery assignments likeUPDATE (v1, v2) = (select 114, 514);
.After this PR, the input of an
Update
will calculate the old and new values for all columns, so thatUpdate
only needs to pick some columns withInputRef
to generate theU-
andU+
chunks. Complex assignments like subqueries will be handled by the optimizer, just like within a normalSELECT
statement.To support this, a new subquery kind named
UpdateSet
is added to allow returning multiple columns (still single row) by compositing them into astruct
type.An example demonstrating the plan:
Checklist
./risedev check
(or alias,./risedev c
)Documentation
Release note
If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.