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(binder): report error on update query with subquery on the set clause #19305

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions src/frontend/planner_test/tests/testdata/input/update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,10 @@
update t set a = a + 1;
expected_outputs:
- batch_distributed_plan
- name: update table with subquery in the set clause
sql: |
create table t1 (v1 int primary key, v2 int);
create table t2 (v1 int primary key, v2 int);
update t1 set v1 = (select v1 from t2 where t1.v2 = t2.v2);
expected_outputs:
- binder_error
6 changes: 6 additions & 0 deletions src/frontend/planner_test/tests/testdata/output/update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,9 @@
└─BatchUpdate { table: t, exprs: [($0 + 1:Int32), $1, $2] }
└─BatchExchange { order: [], dist: HashShard(t.a, t.b, t._row_id) }
└─BatchScan { table: t, columns: [t.a, t.b, t._row_id], distribution: UpstreamHashShard(t._row_id) }
- name: update table with subquery in the set clause
sql: |
create table t1 (v1 int primary key, v2 int);
create table t2 (v1 int primary key, v2 int);
update t1 set v1 = (select v1 from t2 where t1.v2 = t2.v2);
binder_error: 'Bind error: subquery on the right side of assignment is unsupported'
12 changes: 7 additions & 5 deletions src/frontend/src/binder/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,17 @@ impl Binder {
for Assignment { id, value } in assignments {
// FIXME: Parsing of `id` is not strict. It will even treat `a.b` as `(a, b)`.
let assignments = match (id.as_slice(), value) {
// _ = (subquery)
(_ids, AssignmentValue::Expr(Expr::Subquery(_))) => {
return Err(ErrorCode::BindError(
"subquery on the right side of assignment is unsupported".to_owned(),
)
.into())
}
// col = expr
([id], value) => {
vec![(id.clone(), value)]
}

// (col1, col2) = (subquery)
(_ids, AssignmentValue::Expr(Expr::Subquery(_))) => {
bail_not_implemented!("subquery on the right side of multi-assignment");
}
// (col1, col2) = (expr1, expr2)
// TODO: support `DEFAULT` in multiple assignments
(ids, AssignmentValue::Expr(Expr::Row(values))) if ids.len() == values.len() => id
Expand Down
Loading