From bf1ff21248de59da36840f9a95385bbff567c544 Mon Sep 17 00:00:00 2001 From: Chao Wang Date: Fri, 5 Jan 2024 17:30:26 +0800 Subject: [PATCH] executor: do not return row not match parition error when using `update ingore` --- pkg/executor/write.go | 6 ++-- .../r/executor/partition/write.result | 30 ++++++++++++++++++- .../integrationtest/r/executor/update.result | 4 +-- .../t/executor/partition/write.test | 19 +++++++++++- 4 files changed, 53 insertions(+), 6 deletions(-) diff --git a/pkg/executor/write.go b/pkg/executor/write.go index f609110d56b29..7360b8bd8be0c 100644 --- a/pkg/executor/write.go +++ b/pkg/executor/write.go @@ -186,7 +186,8 @@ 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 @@ -194,7 +195,8 @@ func updateRecord( } 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 diff --git a/tests/integrationtest/r/executor/partition/write.result b/tests/integrationtest/r/executor/partition/write.result index 06c6839eef19c..97d5330aa2e1c 100644 --- a/tests/integrationtest/r/executor/partition/write.result +++ b/tests/integrationtest/r/executor/partition/write.result @@ -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. @@ -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; diff --git a/tests/integrationtest/r/executor/update.result b/tests/integrationtest/r/executor/update.result index 5b11c91279039..547b159443ecd 100644 --- a/tests/integrationtest/r/executor/update.result +++ b/tests/integrationtest/r/executor/update.result @@ -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)); diff --git a/tests/integrationtest/t/executor/partition/write.test b/tests/integrationtest/t/executor/partition/write.test index 6eb3724786d05..79feccc409042 100644 --- a/tests/integrationtest/t/executor/partition/write.test +++ b/tests/integrationtest/t/executor/partition/write.test @@ -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; @@ -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;