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 panic in on duplicate key update #20883

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 10 additions & 2 deletions pkg/sql/colexec/dedupjoin/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,16 @@ func (ctr *container) probe(bat *batch.Batch, ap *DedupJoin, proc *process.Proce

for j, rp := range ap.Result {
if rp.Rel == 1 {
if err := ctr.rbat.Vecs[j].UnionOne(ctr.joinBat1.Vecs[rp.Pos], 0, proc.Mp()); err != nil {
return err
//if last index is row_id, meams need fetch right child's partition column
//@FIXME should have better way to get right child's partition column
if ctr.joinBat1.Vecs[rp.Pos].GetType().Oid == types.T_Rowid {
if err := ctr.rbat.Vecs[j].UnionOne(ctr.joinBat2.Vecs[rp.Pos], 0, proc.Mp()); err != nil {
return err
}
} else {
if err := ctr.rbat.Vecs[j].UnionOne(ctr.joinBat1.Vecs[rp.Pos], 0, proc.Mp()); err != nil {
return err
}
}
} else {
if err := ctr.rbat.Vecs[j].UnionOne(bat.Vecs[rp.Pos], int64(i+k), proc.Mp()); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/sql/plan/bind_insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,9 @@ func (builder *QueryBuilder) appendDedupAndMultiUpdateNodesForBindInsert(
if tableDef.Partition != nil {
partitionTableIDs, partitionTableNames := getPartitionInfos(builder.compCtx, objRef, tableDef)
updateCtx.NewPartitionIdx = partitionExprIdx
if onDupAction == plan.Node_UPDATE {
updateCtx.OldPartitionIdx = partitionExprIdx
}
updateCtx.PartitionTableIds = partitionTableIDs
updateCtx.PartitionTableNames = partitionTableNames
dmlNode.BindingTags = append(dmlNode.BindingTags, selectTag)
Expand Down
20 changes: 19 additions & 1 deletion test/distributed/cases/dml/insert/on_duplicate_key.result
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,22 @@ internal error: do not support update primary key/unique key for on duplicate ke
delete from t1;
insert into t1 values (1,1),(3,2);
insert into t1 values (1,2) on duplicate key update a = a+2;
internal error: do not support update primary key/unique key for on duplicate key update
internal error: do not support update primary key/unique key for on duplicate key update
drop table if exists t1;
create table t1(a int primary key, b int) partition by key(a) partitions 2;
insert into t1 values (1,1),(2,2);
insert into t1 values (1,1),(3,3) on duplicate key update b = 10;
select * from t1 order by a;
a b
1 10
2 2
3 3
drop table if exists t1;
create table t1(a int, b int, c int, primary key(a,b)) partition by key(a,b) partitions 2;
insert into t1 values (1,1,1),(2,2,2);
insert into t1 values (1,1,1),(3,3,3) on duplicate key update c = 10;
select * from t1 order by a;
a b c
1 1 10
2 2 2
3 3 3
12 changes: 11 additions & 1 deletion test/distributed/cases/dml/insert/on_duplicate_key.sql
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,14 @@ insert into t1 values (1,1),(3,2);
insert into t1 values (1,2) on duplicate key update a = 10;
delete from t1;
insert into t1 values (1,1),(3,2);
insert into t1 values (1,2) on duplicate key update a = a+2;
insert into t1 values (1,2) on duplicate key update a = a+2;
drop table if exists t1;
create table t1(a int primary key, b int) partition by key(a) partitions 2;
insert into t1 values (1,1),(2,2);
insert into t1 values (1,1),(3,3) on duplicate key update b = 10;
select * from t1 order by a;
drop table if exists t1;
create table t1(a int, b int, c int, primary key(a,b)) partition by key(a,b) partitions 2;
insert into t1 values (1,1,1),(2,2,2);
insert into t1 values (1,1,1),(3,3,3) on duplicate key update c = 10;
select * from t1 order by a;
Loading