Skip to content

Commit

Permalink
Merge branch 'master' into issue-29302
Browse files Browse the repository at this point in the history
  • Loading branch information
djshow832 committed Nov 22, 2021
2 parents 7080e37 + e47f0f5 commit 001542c
Show file tree
Hide file tree
Showing 112 changed files with 8,141 additions and 6,249 deletions.
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ linters-settings:
checks: ["S1002","S1004","S1007","S1009","S1010","S1012","S1019","S1020","S1021","S1024","S1030","SA2*","SA3*","SA4009","SA5*","SA6000","SA6001","SA6005", "-SA2002"]
stylecheck:
checks: ["-ST1003"]
gosec:
excludes:
- G601
issues:
exclude-rules:
- path: _test\.go
Expand Down
9 changes: 6 additions & 3 deletions bindinfo/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ func (br *BindRecord) HasUsingBinding() bool {

// FindBinding find bindings in BindRecord.
func (br *BindRecord) FindBinding(hint string) *Binding {
for _, binding := range br.Bindings {
for i := range br.Bindings {
binding := br.Bindings[i]
if binding.ID == hint {
return &binding
}
Expand Down Expand Up @@ -160,7 +161,8 @@ func merge(lBindRecord, rBindRecord *BindRecord) *BindRecord {
return lBindRecord
}
result := lBindRecord.shallowCopy()
for _, rbind := range rBindRecord.Bindings {
for i := range rBindRecord.Bindings {
rbind := rBindRecord.Bindings[i]
found := false
for j, lbind := range lBindRecord.Bindings {
if lbind.isSame(&rbind) {
Expand All @@ -184,7 +186,8 @@ func (br *BindRecord) remove(deleted *BindRecord) *BindRecord {
return &BindRecord{OriginalSQL: br.OriginalSQL, Db: br.Db}
}
result := br.shallowCopy()
for _, deletedBind := range deleted.Bindings {
for j := range deleted.Bindings {
deletedBind := deleted.Bindings[j]
for i, bind := range result.Bindings {
if bind.isSame(&deletedBind) {
result.Bindings = append(result.Bindings[:i], result.Bindings[i+1:]...)
Expand Down
35 changes: 35 additions & 0 deletions cmd/explaintest/r/explain_generate_column_substitute.result
Original file line number Diff line number Diff line change
Expand Up @@ -523,3 +523,38 @@ b
select @@tidb_allow_function_for_expression_index;
@@tidb_allow_function_for_expression_index
lower, md5, reverse, upper, vitess_hash
CREATE TABLE `PK_S_MULTI_30_tmp` (
`COL1` double NOT NULL,
`COL2` double NOT NULL,
`COL3` double DEFAULT NULL,
PRIMARY KEY (`COL1`,`COL2`) /*T![clustered_index] NONCLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
insert into `PK_S_MULTI_30_tmp` values (-1.7976931348623157e308, 0, 0);
alter table `PK_S_MULTI_30_tmp` add index ((ceil(col1)));
alter table `PK_S_MULTI_30_tmp` add index ((floor(col1)));
insert into `PK_S_MULTI_30_tmp` values (-1.7976931348623157e308, 1, 0);
select * from `PK_S_MULTI_30_tmp` use index (expression_index) where ceil(col1) = ceil(-1.7976931348623157e+308);
COL1 COL2 COL3
-1.7976931348623157e308 0 0
-1.7976931348623157e308 1 0
select * from `PK_S_MULTI_30_tmp` ignore index (expression_index) where ceil(col1) = ceil(-1.7976931348623157e+308);
COL1 COL2 COL3
-1.7976931348623157e308 0 0
-1.7976931348623157e308 1 0
select * from `PK_S_MULTI_30_tmp` use index (expression_index) where floor(col1) = floor(-1.7976931348623157e+308);
COL1 COL2 COL3
-1.7976931348623157e308 0 0
-1.7976931348623157e308 1 0
select * from `PK_S_MULTI_30_tmp` ignore index (expression_index) where floor(col1) = floor(-1.7976931348623157e+308);
COL1 COL2 COL3
-1.7976931348623157e308 0 0
-1.7976931348623157e308 1 0
alter table PK_S_MULTI_30_tmp add index eidx ((truncate(col1, 3)));
select * from PK_S_MULTI_30_tmp ignore index (eidx) where truncate(col1, 3) <= truncate(-1.7976931348623157e308, 3);
COL1 COL2 COL3
-1.7976931348623157e308 0 0
-1.7976931348623157e308 1 0
select * from PK_S_MULTI_30_tmp use index (eidx) where truncate(col1, 3) <= truncate(-1.7976931348623157e308, 3);
COL1 COL2 COL3
-1.7976931348623157e308 0 0
-1.7976931348623157e308 1 0
8 changes: 4 additions & 4 deletions cmd/explaintest/r/new_character_set_builtin.result
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,16 @@ NULL NULL NULL
set @@tidb_enable_vectorized_expression = true;
select sha2(a, 0), sha2(b, 0), sha2(c, 0) from t;
sha2(a, 0) sha2(b, 0) sha2(c, 0)
4fc9d8955b6155d931b24a583a6ad872f7d77fd4e4562cf8f619faa9c1a2cdc7 4fc9d8955b6155d931b24a583a6ad872f7d77fd4e4562cf8f619faa9c1a2cdc7 f98670d7ccdf803dfa2f24555cfd733d626dd24f5f2bb0b91e37cc4f54a0f359
4fc9d8955b6155d931b24a583a6ad872f7d77fd4e4562cf8f619faa9c1a2cdc7 b6c1ae1f8d8a07426ddb13fca5124fb0b9f1f0ef1cca6730615099cf198ca8af f98670d7ccdf803dfa2f24555cfd733d626dd24f5f2bb0b91e37cc4f54a0f359
select sha2(a, 224), sha2(b, 224), sha2(c, 224) from t;
sha2(a, 224) sha2(b, 224) sha2(c, 224)
ae47a60dd96e1deed3988d8fff3d662165e0aac7ddf371f244d7c11e ae47a60dd96e1deed3988d8fff3d662165e0aac7ddf371f244d7c11e eb0de82dfada1205f65ac4aa6e4778d2f7730144f31688d42a316b9c
ae47a60dd96e1deed3988d8fff3d662165e0aac7ddf371f244d7c11e 2362f577783f6cd6cc10b0308f946f479fef868a39d6339b5d74cc6d eb0de82dfada1205f65ac4aa6e4778d2f7730144f31688d42a316b9c
select sha2(a, 256), sha2(b, 256), sha2(c, 256) from t;
sha2(a, 256) sha2(b, 256) sha2(c, 256)
4fc9d8955b6155d931b24a583a6ad872f7d77fd4e4562cf8f619faa9c1a2cdc7 4fc9d8955b6155d931b24a583a6ad872f7d77fd4e4562cf8f619faa9c1a2cdc7 f98670d7ccdf803dfa2f24555cfd733d626dd24f5f2bb0b91e37cc4f54a0f359
4fc9d8955b6155d931b24a583a6ad872f7d77fd4e4562cf8f619faa9c1a2cdc7 b6c1ae1f8d8a07426ddb13fca5124fb0b9f1f0ef1cca6730615099cf198ca8af f98670d7ccdf803dfa2f24555cfd733d626dd24f5f2bb0b91e37cc4f54a0f359
select sha2(a, 384), sha2(b, 384), sha2(c, 384) from t;
sha2(a, 384) sha2(b, 384) sha2(c, 384)
cdb9c8d3e2579d021116ebe9d7d7bb4f5b3a489cae84768f7b3348c9b8d716897a409ea96fd92bfb95e3fd8aa91ffc74 cdb9c8d3e2579d021116ebe9d7d7bb4f5b3a489cae84768f7b3348c9b8d716897a409ea96fd92bfb95e3fd8aa91ffc74 1b526bf926dbc53609628f145a6efe2b17eb29754ba2c6e0e33673dbd79d62ea50bbfc233252f06ba27712f8bd406963
cdb9c8d3e2579d021116ebe9d7d7bb4f5b3a489cae84768f7b3348c9b8d716897a409ea96fd92bfb95e3fd8aa91ffc74 54e75070f1faab03e7ce808ca2824ed4614ad1d58ee1409d8c1e4fd72ecab12c92ac3a2f919721c2aa09b23e5f3cc8aa 1b526bf926dbc53609628f145a6efe2b17eb29754ba2c6e0e33673dbd79d62ea50bbfc233252f06ba27712f8bd406963
select sha2(a, 514), sha2(b, 514), sha2(c, 514) from t;
sha2(a, 514) sha2(b, 514) sha2(c, 514)
NULL NULL NULL
Expand Down
23 changes: 23 additions & 0 deletions cmd/explaintest/r/new_character_set_invalid.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
set @@sql_mode = 'strict_trans_tables';
drop table if exists t;
create table t (a varchar(255) charset gbk, b varchar(255) charset ascii, c varchar(255) charset utf8);
insert into t values ('中文', 'asdf', '字符集');
insert into t values ('À', 'ø', '😂');
Error 1366: Incorrect string value '\xC3\x80' for column 'a'
insert into t values ('中文À中文', 'asdføfdsa', '字符集😂字符集');
Error 1366: Incorrect string value '\xC3\x80\xE4\xB8\xAD\xE6...' for column 'a'
insert into t values (0x4040ffff, 0x4040ffff, 0x4040ffff);
Error 1366: Incorrect string value '\xFF\xFF' for column 'a'
select * from t;
a b c
中文 asdf 字符集
set @@sql_mode = '';
insert into t values ('À', 'ø', '😂');
insert into t values ('中文À中文', 'asdføfdsa', '字符集😂字符集');
insert into t values (0x4040ffff, 0x4040ffff, 0x4040ffff);
select * from t;
a b c
中文 asdf 字符集
? ? ?
中文?中文 asdf?fdsa 字符集?字符集
@@ @@ @@
18 changes: 18 additions & 0 deletions cmd/explaintest/t/explain_generate_column_substitute.test
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,21 @@ create index eidx on t02 ((lower(a)));
select * from t02 use index(eidx) where lower(a) < 'c';

select @@tidb_allow_function_for_expression_index;

CREATE TABLE `PK_S_MULTI_30_tmp` (
`COL1` double NOT NULL,
`COL2` double NOT NULL,
`COL3` double DEFAULT NULL,
PRIMARY KEY (`COL1`,`COL2`) /*T![clustered_index] NONCLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
insert into `PK_S_MULTI_30_tmp` values (-1.7976931348623157e308, 0, 0);
alter table `PK_S_MULTI_30_tmp` add index ((ceil(col1)));
alter table `PK_S_MULTI_30_tmp` add index ((floor(col1)));
insert into `PK_S_MULTI_30_tmp` values (-1.7976931348623157e308, 1, 0);
select * from `PK_S_MULTI_30_tmp` use index (expression_index) where ceil(col1) = ceil(-1.7976931348623157e+308);
select * from `PK_S_MULTI_30_tmp` ignore index (expression_index) where ceil(col1) = ceil(-1.7976931348623157e+308);
select * from `PK_S_MULTI_30_tmp` use index (expression_index) where floor(col1) = floor(-1.7976931348623157e+308);
select * from `PK_S_MULTI_30_tmp` ignore index (expression_index) where floor(col1) = floor(-1.7976931348623157e+308);
alter table PK_S_MULTI_30_tmp add index eidx ((truncate(col1, 3)));
select * from PK_S_MULTI_30_tmp ignore index (eidx) where truncate(col1, 3) <= truncate(-1.7976931348623157e308, 3);
select * from PK_S_MULTI_30_tmp use index (eidx) where truncate(col1, 3) <= truncate(-1.7976931348623157e308, 3);
17 changes: 17 additions & 0 deletions cmd/explaintest/t/new_character_set_invalid.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
set @@sql_mode = 'strict_trans_tables';
drop table if exists t;
create table t (a varchar(255) charset gbk, b varchar(255) charset ascii, c varchar(255) charset utf8);
insert into t values ('中文', 'asdf', '字符集');
-- error 1366: Incorrect string value '\xC3\x80' for column 'a'
insert into t values ('À', 'ø', '😂');
-- error 1366: Incorrect string value '\xC3\x80\xE4\xB8\xAD\xE6...' for column 'a'
insert into t values ('中文À中文', 'asdføfdsa', '字符集😂字符集');
-- error 1366: Incorrect string value '\xFF\xFF' for column 'a'
insert into t values (0x4040ffff, 0x4040ffff, 0x4040ffff);
select * from t;

set @@sql_mode = '';
insert into t values ('À', 'ø', '😂');
insert into t values ('中文À中文', 'asdføfdsa', '字符集😂字符集');
insert into t values (0x4040ffff, 0x4040ffff, 0x4040ffff);
select * from t;
14 changes: 7 additions & 7 deletions ddl/column_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ type testColumnChangeSuite struct {
func (s *testColumnChangeSuite) SetUpSuite(c *C) {
SetWaitTimeWhenErrorOccurred(1 * time.Microsecond)
s.store = testCreateStore(c, "test_column_change")
d := testNewDDLAndStart(
d, err := testNewDDLAndStart(
context.Background(),
c,
WithStore(s.store),
WithLease(testLease),
)
c.Assert(err, IsNil)
defer func() {
err := d.Stop()
c.Assert(err, IsNil)
Expand All @@ -67,20 +67,20 @@ func (s *testColumnChangeSuite) TearDownSuite(c *C) {
}

func (s *testColumnChangeSuite) TestColumnChange(c *C) {
d := testNewDDLAndStart(
d, err := testNewDDLAndStart(
context.Background(),
c,
WithStore(s.store),
WithLease(testLease),
)
c.Assert(err, IsNil)
defer func() {
err := d.Stop()
c.Assert(err, IsNil)
}()
// create table t (c1 int, c2 int);
tblInfo := testTableInfo(c, d, "t", 2)
ctx := testNewContext(d)
err := ctx.NewTxn(context.Background())
err = ctx.NewTxn(context.Background())
c.Assert(err, IsNil)
testCreateTable(c, ctx, d, s.dbInfo, tblInfo)
// insert t values (1, 2);
Expand Down Expand Up @@ -163,12 +163,12 @@ func (s *testColumnChangeSuite) TestColumnChange(c *C) {
}

func (s *testColumnChangeSuite) TestModifyAutoRandColumnWithMetaKeyChanged(c *C) {
d := testNewDDLAndStart(
d, err := testNewDDLAndStart(
context.Background(),
c,
WithStore(s.store),
WithLease(testLease),
)
c.Assert(err, IsNil)
defer func() {
err := d.Stop()
c.Assert(err, IsNil)
Expand Down
42 changes: 21 additions & 21 deletions ddl/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ type testColumnSuite struct {

func (s *testColumnSuite) SetUpSuite(c *C) {
s.store = testCreateStore(c, "test_column")
d := testNewDDLAndStart(
d, err := testNewDDLAndStart(
context.Background(),
c,
WithStore(s.store),
WithLease(testLease),
)
c.Assert(err, IsNil)

s.dbInfo = testSchemaInfo(c, d, "test_column")
testCreateSchema(c, testNewContext(d), d, s.dbInfo)
Expand Down Expand Up @@ -185,12 +185,12 @@ func testDropColumns(c *C, ctx sessionctx.Context, d *ddl, dbInfo *model.DBInfo,
}

func (s *testColumnSuite) TestColumnBasic(c *C) {
d := testNewDDLAndStart(
d, err := testNewDDLAndStart(
context.Background(),
c,
WithStore(s.store),
WithLease(testLease),
)
c.Assert(err, IsNil)
defer func() {
err := d.Stop()
c.Assert(err, IsNil)
Expand All @@ -208,7 +208,7 @@ func (s *testColumnSuite) TestColumnBasic(c *C) {
c.Assert(err, IsNil)
}

err := ctx.NewTxn(context.Background())
err = ctx.NewTxn(context.Background())
c.Assert(err, IsNil)

i := int64(0)
Expand Down Expand Up @@ -836,16 +836,16 @@ func (s *testColumnSuite) testGetColumn(t table.Table, name string, isExist bool
}

func (s *testColumnSuite) TestAddColumn(c *C) {
d := testNewDDLAndStart(
d, err := testNewDDLAndStart(
context.Background(),
c,
WithStore(s.store),
WithLease(testLease),
)
c.Assert(err, IsNil)
tblInfo := testTableInfo(c, d, "t", 3)
ctx := testNewContext(d)

err := ctx.NewTxn(context.Background())
err = ctx.NewTxn(context.Background())
c.Assert(err, IsNil)

testCreateTable(c, ctx, d, s.dbInfo, tblInfo)
Expand Down Expand Up @@ -924,16 +924,16 @@ func (s *testColumnSuite) TestAddColumn(c *C) {
}

func (s *testColumnSuite) TestAddColumns(c *C) {
d := testNewDDLAndStart(
d, err := testNewDDLAndStart(
context.Background(),
c,
WithStore(s.store),
WithLease(testLease),
)
c.Assert(err, IsNil)
tblInfo := testTableInfo(c, d, "t", 3)
ctx := testNewContext(d)

err := ctx.NewTxn(context.Background())
err = ctx.NewTxn(context.Background())
c.Assert(err, IsNil)

testCreateTable(c, ctx, d, s.dbInfo, tblInfo)
Expand Down Expand Up @@ -1009,16 +1009,16 @@ func (s *testColumnSuite) TestAddColumns(c *C) {
}

func (s *testColumnSuite) TestDropColumn(c *C) {
d := testNewDDLAndStart(
d, err := testNewDDLAndStart(
context.Background(),
c,
WithStore(s.store),
WithLease(testLease),
)
c.Assert(err, IsNil)
tblInfo := testTableInfo(c, d, "t2", 4)
ctx := testNewContext(d)

err := ctx.NewTxn(context.Background())
err = ctx.NewTxn(context.Background())
c.Assert(err, IsNil)

testCreateTable(c, ctx, d, s.dbInfo, tblInfo)
Expand Down Expand Up @@ -1085,16 +1085,16 @@ func (s *testColumnSuite) TestDropColumn(c *C) {
}

func (s *testColumnSuite) TestDropColumns(c *C) {
d := testNewDDLAndStart(
d, err := testNewDDLAndStart(
context.Background(),
c,
WithStore(s.store),
WithLease(testLease),
)
c.Assert(err, IsNil)
tblInfo := testTableInfo(c, d, "t2", 4)
ctx := testNewContext(d)

err := ctx.NewTxn(context.Background())
err = ctx.NewTxn(context.Background())
c.Assert(err, IsNil)

testCreateTable(c, ctx, d, s.dbInfo, tblInfo)
Expand Down Expand Up @@ -1154,12 +1154,12 @@ func (s *testColumnSuite) TestDropColumns(c *C) {
}

func (s *testColumnSuite) TestModifyColumn(c *C) {
d := testNewDDLAndStart(
d, err := testNewDDLAndStart(
context.Background(),
c,
WithStore(s.store),
WithLease(testLease),
)
c.Assert(err, IsNil)
ctx := testNewContext(d)

defer func() {
Expand Down Expand Up @@ -1222,12 +1222,12 @@ func (s *testColumnSuite) TestFieldCase(c *C) {
}

func (s *testColumnSuite) TestAutoConvertBlobTypeByLength(c *C) {
d := testNewDDLAndStart(
d, err := testNewDDLAndStart(
context.Background(),
c,
WithStore(s.store),
WithLease(testLease),
)
c.Assert(err, IsNil)
// Close the customized ddl(worker goroutine included) after the test is finished, otherwise, it will
// cause go routine in TiDB leak test.
defer func() {
Expand Down
4 changes: 2 additions & 2 deletions ddl/column_type_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,13 +548,13 @@ func (s *testColumnTypeChangeSuite) TestColumnTypeChangeFromStringToOthers(c *C)
tk.MustExec("insert into t values ('123.45', '123.45', '123.45', '123.45', '123.45', '123.45', '123', '123')")
tk.MustExec("alter table t modify c decimal(7, 4)")
tk.MustExec("alter table t modify vc decimal(7, 4)")
tk.MustExec("alter table t modify bny decimal(7, 4)")
tk.MustGetErrCode("alter table t modify bny decimal(7, 4)", mysql.ErrTruncatedWrongValue)
tk.MustExec("alter table t modify vbny decimal(7, 4)")
tk.MustExec("alter table t modify bb decimal(7, 4)")
tk.MustExec("alter table t modify txt decimal(7, 4)")
tk.MustExec("alter table t modify e decimal(7, 4)")
tk.MustExec("alter table t modify s decimal(7, 4)")
tk.MustQuery("select * from t").Check(testkit.Rows("123.4500 123.4500 123.4500 123.4500 123.4500 123.4500 1.0000 1.0000"))
tk.MustQuery("select * from t").Check(testkit.Rows("123.4500 123.4500 123.45\x00\x00 123.4500 123.4500 123.4500 1.0000 1.0000"))
// double
reset(tk)
tk.MustExec("insert into t values ('123.45', '123.45', '123.45', '123.45', '123.45', '123.45', '123', '123')")
Expand Down
Loading

0 comments on commit 001542c

Please sign in to comment.