Skip to content
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
13 changes: 13 additions & 0 deletions pkg/executor/batch_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package executor

import (
"context"
"strings"

"github.com/pingcap/errors"
"github.com/pingcap/tidb/pkg/errno"
Expand All @@ -29,6 +30,7 @@ import (
"github.com/pingcap/tidb/pkg/table/tables"
"github.com/pingcap/tidb/pkg/tablecodec"
"github.com/pingcap/tidb/pkg/types"
"github.com/pingcap/tidb/pkg/util"
"github.com/pingcap/tidb/pkg/util/chunk"
"github.com/pingcap/tidb/pkg/util/codec"
"github.com/pingcap/tidb/pkg/util/logutil"
Expand Down Expand Up @@ -265,6 +267,17 @@ func dataToStrings(data []types.Datum) ([]string, error) {
if err != nil {
return nil, errors.Trace(err)
}
if datum.Kind() == types.KindBytes || datum.Kind() == types.KindMysqlBit || datum.Kind() == types.KindBinaryLiteral {
// Same as MySQL, remove all 0x00 on the tail,
// but keep one 0x00 at least.
if datum.Kind() == types.KindBytes {
str = strings.TrimRight(str, string(rune(0x00)))
if len(str) == 0 {
str = string(rune(0x00))
}
}
str = util.FmtNonASCIIPrintableCharToHex(str, len(str), true)
}
strs = append(strs, str)
}
return strs, nil
Expand Down
39 changes: 39 additions & 0 deletions tests/integrationtest/r/executor/insert.result
Original file line number Diff line number Diff line change
Expand Up @@ -2183,3 +2183,42 @@ id col1
4
5
6
drop table if exists t1;
create table t1 (id binary(20) unique);
INSERT IGNORE INTO t1 VALUES (X'0e6b4234fd0b08d4c4ec656529d94df02b37c472');
INSERT IGNORE INTO t1 VALUES (X'0e6b4234fd0b08d4c4ec656529d94df02b37c472');
show warnings;
Level Code Message
Warning 1062 Duplicate entry '\x0EkB4\xFD\x0B\x08\xD4\xC4\xECee)\xD9M\xF0+7\xC4r' for key 't1.id'
INSERT IGNORE INTO t1 VALUES (X'');
INSERT IGNORE INTO t1 VALUES (X'');
show warnings;
Level Code Message
Warning 1062 Duplicate entry '\x00' for key 't1.id'
INSERT IGNORE INTO t1 VALUES (X'7f000000');
INSERT IGNORE INTO t1 VALUES (X'7f000000');
show warnings;
Level Code Message
Warning 1062 Duplicate entry '\x7F' for key 't1.id'
drop table if exists t1;
create table t1 (id bit(20) unique);
INSERT IGNORE INTO t1 VALUES (10);
INSERT IGNORE INTO t1 VALUES (10);
show warnings;
Level Code Message
Warning 1062 Duplicate entry '\x00\x00\x0A' for key 't1.id'
INSERT IGNORE INTO t1 VALUES (65536);
INSERT IGNORE INTO t1 VALUES (65536);
show warnings;
Level Code Message
Warning 1062 Duplicate entry '\x01\x00\x00' for key 't1.id'
INSERT IGNORE INTO t1 VALUES (35);
INSERT IGNORE INTO t1 VALUES (35);
show warnings;
Level Code Message
Warning 1062 Duplicate entry '\x00\x00#' for key 't1.id'
INSERT IGNORE INTO t1 VALUES (127);
INSERT IGNORE INTO t1 VALUES (127);
show warnings;
Level Code Message
Warning 1062 Duplicate entry '\x00\x00\x7F' for key 't1.id'
Expand Down
29 changes: 29 additions & 0 deletions tests/integrationtest/t/executor/insert.test
Original file line number Diff line number Diff line change
Expand Up @@ -1649,3 +1649,32 @@ update t1 set col1 = null where id = 3;
show warnings;
insert ignore t1 VALUES (4, 4) ON DUPLICATE KEY UPDATE col1 = null;
select * from t1;

# TestIssue31639
drop table if exists t1;
create table t1 (id binary(20) unique);
INSERT IGNORE INTO t1 VALUES (X'0e6b4234fd0b08d4c4ec656529d94df02b37c472');
INSERT IGNORE INTO t1 VALUES (X'0e6b4234fd0b08d4c4ec656529d94df02b37c472');
show warnings;
INSERT IGNORE INTO t1 VALUES (X'');
INSERT IGNORE INTO t1 VALUES (X'');
show warnings;
INSERT IGNORE INTO t1 VALUES (X'7f000000');
INSERT IGNORE INTO t1 VALUES (X'7f000000');
show warnings;

drop table if exists t1;
create table t1 (id bit(20) unique);
INSERT IGNORE INTO t1 VALUES (10);
INSERT IGNORE INTO t1 VALUES (10);
show warnings;
INSERT IGNORE INTO t1 VALUES (65536);
INSERT IGNORE INTO t1 VALUES (65536);
show warnings;
INSERT IGNORE INTO t1 VALUES (35);
INSERT IGNORE INTO t1 VALUES (35);
show warnings;
INSERT IGNORE INTO t1 VALUES (127);
INSERT IGNORE INTO t1 VALUES (127);
show warnings;