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

*: do not return row not match parition error when using update ingore #50134

Merged
merged 1 commit into from
Jan 8, 2024
Merged
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
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)
Copy link
Collaborator Author

@lcwangchao lcwangchao Jan 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should append error to warning when "update/insert ignore" to keep the behavior same with mysql

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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This modification here is to make the later test stable:

update t set id=id+17 where id in (3,10);
Error 1062 (23000): Duplicate entry '20-2' for key 't.idx'

Without this line of change, there will be two errors in the statement and any of them can be returned first.

);
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;