diff --git a/pkg/sql/colexec/dedupjoin/join.go b/pkg/sql/colexec/dedupjoin/join.go index 8baa99369be9c..11852cec1b18e 100644 --- a/pkg/sql/colexec/dedupjoin/join.go +++ b/pkg/sql/colexec/dedupjoin/join.go @@ -451,7 +451,15 @@ 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 { + //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 + var srcVec *vector.Vector + if ctr.joinBat1.Vecs[rp.Pos].GetType().Oid == types.T_Rowid { + srcVec = ctr.joinBat2.Vecs[rp.Pos] + } else { + srcVec = ctr.joinBat1.Vecs[rp.Pos] + } + if err := ctr.rbat.Vecs[j].UnionOne(srcVec, 0, proc.Mp()); err != nil { return err } } else { diff --git a/pkg/sql/plan/bind_insert.go b/pkg/sql/plan/bind_insert.go index 6bb2e6ae67cea..2b70b9dd97676 100644 --- a/pkg/sql/plan/bind_insert.go +++ b/pkg/sql/plan/bind_insert.go @@ -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) diff --git a/test/distributed/cases/dml/insert/on_duplicate_key.result b/test/distributed/cases/dml/insert/on_duplicate_key.result index 2a193bd11bb83..e78aa314ce750 100644 --- a/test/distributed/cases/dml/insert/on_duplicate_key.result +++ b/test/distributed/cases/dml/insert/on_duplicate_key.result @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/test/distributed/cases/dml/insert/on_duplicate_key.sql b/test/distributed/cases/dml/insert/on_duplicate_key.sql index 4ad8ac8aa60ee..5fa5208a41b29 100644 --- a/test/distributed/cases/dml/insert/on_duplicate_key.sql +++ b/test/distributed/cases/dml/insert/on_duplicate_key.sql @@ -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; \ No newline at end of file +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; \ No newline at end of file