Skip to content

Commit

Permalink
*: do not return row not match parition error when using `update ingo…
Browse files Browse the repository at this point in the history
  • Loading branch information
lcwangchao authored and AilinKid committed Jan 17, 2024
1 parent 0a37ac7 commit 5f4a49b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
6 changes: 4 additions & 2 deletions pkg/executor/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,17 @@ func updateRecord(
memBuffer.Release(sh)
return true, nil
}(); err != nil {
if terr, ok := errors.Cause(err).(*terror.Error); sctx.GetSessionVars().StmtCtx.IgnoreNoPartition && ok && terr.Code() == errno.ErrNoPartitionForGivenValue {
if terr, ok := errors.Cause(err).(*terror.Error); sctx.GetSessionVars().StmtCtx.IgnoreNoPartition && ok && (terr.Code() == errno.ErrNoPartitionForGivenValue || terr.Code() == errno.ErrRowDoesNotMatchGivenPartitionSet) {
sctx.GetSessionVars().StmtCtx.AppendWarning(err)
return false, nil
}
return updated, err
}
} else {
// Update record to new value and update index.
if err := t.UpdateRecord(ctx, sctx, h, oldData, newData, modified); err != nil {
if terr, ok := errors.Cause(err).(*terror.Error); sctx.GetSessionVars().StmtCtx.IgnoreNoPartition && ok && terr.Code() == errno.ErrNoPartitionForGivenValue {
if terr, ok := errors.Cause(err).(*terror.Error); sctx.GetSessionVars().StmtCtx.IgnoreNoPartition && ok && (terr.Code() == errno.ErrNoPartitionForGivenValue || terr.Code() == errno.ErrRowDoesNotMatchGivenPartitionSet) {
sctx.GetSessionVars().StmtCtx.AppendWarning(err)
return false, nil
}
return false, err
Expand Down
30 changes: 29 additions & 1 deletion tests/integrationtest/r/executor/partition/write.result
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ partition by list (id*2 + b*b + b*b - b*b*2 - abs(id)) (
partition p0 values in (3,5,6,9,17),
partition p1 values in (1,2,10,11,19,20),
partition p2 values in (4,12,13,14,18),
partition p3 values in (7,8,15,16,null)
partition p3 values in (7,8,15,16,27,null)
);
analyze table t;
## Test add unique index failed.
Expand Down Expand Up @@ -812,3 +812,31 @@ select * from tIssue989;
a b
111 2
set @@session.tidb_enable_table_partition = default;
drop table if exists insert_update_ignore_test;
create table insert_update_ignore_test (a int) partition by range (a) (partition p0 values less than (100), partition p1 values less than (200));
insert ignore into insert_update_ignore_test values(1000);
show warnings where Message not like '%disable dynamic pruning%';
Level Code Message
Warning 1526 Table has no partition for value 1000
insert ignore into insert_update_ignore_test partition(p0) values(101);
show warnings where Message not like '%disable dynamic pruning%';
Level Code Message
Warning 1748 Found a row not matching the given partition set
select * from insert_update_ignore_test;
a
insert into insert_update_ignore_test values(1);
update ignore insert_update_ignore_test set a=1000;
show warnings where Message not like '%disable dynamic pruning%';
Level Code Message
Warning 1526 Table has no partition for value 1000
select * from insert_update_ignore_test;
a
1
update ignore insert_update_ignore_test partition(p0) set a=101;
show warnings where Message not like '%disable dynamic pruning%';
Level Code Message
Warning 1748 Found a row not matching the given partition set
select * from insert_update_ignore_test;
a
1
drop table insert_update_ignore_test;
4 changes: 2 additions & 2 deletions tests/integrationtest/r/executor/update.result
Original file line number Diff line number Diff line change
Expand Up @@ -521,13 +521,13 @@ analyze table t;
insert ignore into t values (1);
update ignore t set a=2 where a=1;
affected rows: 0
info: Rows matched: 1 Changed: 0 Warnings: 0
info: Rows matched: 1 Changed: 0 Warnings: 1
drop table if exists t;
create table t (a int key) partition by list (a) (partition p0 values in (0,1));
insert ignore into t values (1);
update ignore t set a=2 where a=1;
affected rows: 0
info: Rows matched: 1 Changed: 0 Warnings: 0
info: Rows matched: 1 Changed: 0 Warnings: 1
set @@session.tidb_enable_list_partition = default;
drop table if exists t;
create table t(id integer auto_increment, t1 datetime, t2 datetime, primary key (id));
Expand Down
19 changes: 18 additions & 1 deletion tests/integrationtest/t/executor/partition/write.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ create table t (id int, name varchar(10),b int generated always as (length(name)
partition p0 values in (3,5,6,9,17),
partition p1 values in (1,2,10,11,19,20),
partition p2 values in (4,12,13,14,18),
partition p3 values in (7,8,15,16,null)
partition p3 values in (7,8,15,16,27,null)
);

analyze table t;
Expand Down Expand Up @@ -602,3 +602,20 @@ replace into tIssue989(a, b) values (111, 2);
select * from tIssue989;

set @@session.tidb_enable_table_partition = default;

## test partition insert/update ignore to invalid partition
drop table if exists insert_update_ignore_test;
create table insert_update_ignore_test (a int) partition by range (a) (partition p0 values less than (100), partition p1 values less than (200));
insert ignore into insert_update_ignore_test values(1000);
show warnings where Message not like '%disable dynamic pruning%';
insert ignore into insert_update_ignore_test partition(p0) values(101);
show warnings where Message not like '%disable dynamic pruning%';
select * from insert_update_ignore_test;
insert into insert_update_ignore_test values(1);
update ignore insert_update_ignore_test set a=1000;
show warnings where Message not like '%disable dynamic pruning%';
select * from insert_update_ignore_test;
update ignore insert_update_ignore_test partition(p0) set a=101;
show warnings where Message not like '%disable dynamic pruning%';
select * from insert_update_ignore_test;
drop table insert_update_ignore_test;

0 comments on commit 5f4a49b

Please sign in to comment.