From a1af4fa54b5eab2d452ff28c840f05c8a8e9256d Mon Sep 17 00:00:00 2001 From: Yiding Cui Date: Tue, 17 Dec 2019 15:25:06 +0800 Subject: [PATCH] *: revert #10124 and remove sql mode `PadCharToFullLength` (#14007) --- executor/distsql.go | 3 - executor/executor.go | 1 - executor/point_get.go | 5 +- executor/point_get_test.go | 180 +++----------------- expression/column.go | 11 -- go.sum | 1 + sessionctx/stmtctx/stmtctx.go | 1 - store/mockstore/mocktikv/cop_handler_dag.go | 1 - types/const_test.go | 32 ---- util/ranger/points.go | 66 ------- 10 files changed, 29 insertions(+), 272 deletions(-) diff --git a/executor/distsql.go b/executor/distsql.go index f499070c91e7e..3113052e2e7d7 100644 --- a/executor/distsql.go +++ b/executor/distsql.go @@ -154,9 +154,6 @@ func statementContextToFlags(sc *stmtctx.StatementContext) uint64 { if sc.DividedByZeroAsWarning { flags |= model.FlagDividedByZeroAsWarning } - if sc.PadCharToFullLength { - flags |= model.FlagPadCharToFullLength - } return flags } diff --git a/executor/executor.go b/executor/executor.go index a540dd8fe2f66..65b6a51a9bb12 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -1499,7 +1499,6 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) { sc.Priority = opts.Priority sc.NotFillCache = !opts.SQLCache } - sc.PadCharToFullLength = ctx.GetSessionVars().SQLMode.HasPadCharToFullLengthMode() sc.CastStrToIntStrict = true case *ast.ShowStmt: sc.IgnoreTruncate = true diff --git a/executor/point_get.go b/executor/point_get.go index 1d9d3de891f8d..0de1bb7db10e0 100644 --- a/executor/point_get.go +++ b/executor/point_get.go @@ -27,7 +27,6 @@ import ( "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/codec" - "github.com/pingcap/tidb/util/ranger" ) func (b *executorBuilder) buildPointGet(p *plannercore.PointGetPlan) Executor { @@ -157,7 +156,9 @@ func (e *PointGetExecutor) encodeIndexKey() (_ []byte, err error) { for i := range e.idxVals { colInfo := e.tblInfo.Columns[e.idxInfo.Columns[i].Offset] if colInfo.Tp == mysql.TypeString || colInfo.Tp == mysql.TypeVarString || colInfo.Tp == mysql.TypeVarchar { - e.idxVals[i], err = ranger.HandlePadCharToFullLength(sc, &colInfo.FieldType, e.idxVals[i]) + var str string + str, err = e.idxVals[i].ToString() + e.idxVals[i].SetString(str) } else { e.idxVals[i], err = table.CastValue(e.ctx, e.idxVals[i], colInfo) } diff --git a/executor/point_get_test.go b/executor/point_get_test.go index aa6a1c23a94bd..7734480b227ba 100644 --- a/executor/point_get_test.go +++ b/executor/point_get_test.go @@ -109,57 +109,36 @@ func (s *testPointGetSuite) TestPointGetCharPK(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec(`use test;`) tk.MustExec(`drop table if exists t;`) - tk.MustExec(`create table t(a char(2) primary key, b char(2));`) + tk.MustExec(`create table t(a char(4) primary key, b char(4));`) tk.MustExec(`insert into t values("aa", "bb");`) - // Test truncate without sql mode `PAD_CHAR_TO_FULL_LENGTH`. + // Test CHAR type. tk.MustExec(`set @@sql_mode="";`) tk.MustPointGet(`select * from t where a = "aa";`).Check(testkit.Rows(`aa bb`)) tk.MustPointGet(`select * from t where a = "aab";`).Check(testkit.Rows()) - // Test truncate with sql mode `PAD_CHAR_TO_FULL_LENGTH`. - tk.MustExec(`set @@sql_mode="PAD_CHAR_TO_FULL_LENGTH";`) - tk.MustPointGet(`select * from t where a = "aa";`).Check(testkit.Rows(`aa bb`)) - tk.MustPointGet(`select * from t where a = "aab";`).Check(testkit.Rows()) - tk.MustExec(`truncate table t;`) tk.MustExec(`insert into t values("a ", "b ");`) - // Test trailing spaces without sql mode `PAD_CHAR_TO_FULL_LENGTH`. tk.MustExec(`set @@sql_mode="";`) tk.MustPointGet(`select * from t where a = "a";`).Check(testkit.Rows(`a b`)) tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows()) tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows()) - // Test trailing spaces with sql mode `PAD_CHAR_TO_FULL_LENGTH`. - tk.MustExec(`set @@sql_mode="PAD_CHAR_TO_FULL_LENGTH";`) - tk.MustPointGet(`select * from t where a = "a";`).Check(testkit.Rows()) - tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows(`a b`)) - tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows()) - - // // Test CHAR BINARY. + // Test CHAR BINARY. tk.MustExec(`drop table if exists t;`) tk.MustExec(`create table t(a char(2) binary primary key, b char(2));`) tk.MustExec(`insert into t values(" ", " ");`) tk.MustExec(`insert into t values("a ", "b ");`) - // Test trailing spaces without sql mode `PAD_CHAR_TO_FULL_LENGTH`. tk.MustExec(`set @@sql_mode="";`) tk.MustPointGet(`select * from t where a = "a";`).Check(testkit.Rows(`a b`)) - tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows(`a b`)) - tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows(`a b`)) - tk.MustPointGet(`select * from t where a = " ";`).Check(testkit.Rows(` `)) - tk.MustPointGet(`select * from t where a = " ";`).Check(testkit.Rows(` `)) - tk.MustPointGet(`select * from t where a = " ";`).Check(testkit.Rows(` `)) - - // Test trailing spaces with sql mode `PAD_CHAR_TO_FULL_LENGTH`. - tk.MustExec(`set @@sql_mode="PAD_CHAR_TO_FULL_LENGTH";`) - tk.MustPointGet(`select * from t where a = "a";`).Check(testkit.Rows(`a b`)) - tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows(`a b`)) - tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows(`a b`)) - tk.MustPointGet(`select * from t where a = " ";`).Check(testkit.Rows(` `)) - tk.MustPointGet(`select * from t where a = " ";`).Check(testkit.Rows(` `)) - tk.MustPointGet(`select * from t where a = " ";`).Check(testkit.Rows(` `)) + tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows()) + tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows()) + tk.MustPointGet(`select * from t where a = "";`).Check(testkit.Rows(` `)) + tk.MustPointGet(`select * from t where a = " ";`).Check(testkit.Rows()) + tk.MustPointGet(`select * from t where a = " ";`).Check(testkit.Rows()) + } func (s *testPointGetSuite) TestPointGetAliasTableCharPK(c *C) { @@ -169,54 +148,31 @@ func (s *testPointGetSuite) TestPointGetAliasTableCharPK(c *C) { tk.MustExec(`create table t(a char(2) primary key, b char(2));`) tk.MustExec(`insert into t values("aa", "bb");`) - // Test truncate without sql mode `PAD_CHAR_TO_FULL_LENGTH`. tk.MustExec(`set @@sql_mode="";`) tk.MustPointGet(`select * from t tmp where a = "aa";`).Check(testkit.Rows(`aa bb`)) tk.MustPointGet(`select * from t tmp where a = "aab";`).Check(testkit.Rows()) - // Test truncate with sql mode `PAD_CHAR_TO_FULL_LENGTH`. - tk.MustExec(`set @@sql_mode="PAD_CHAR_TO_FULL_LENGTH";`) - tk.MustPointGet(`select * from t tmp where a = "aa";`).Check(testkit.Rows(`aa bb`)) - tk.MustPointGet(`select * from t tmp where a = "aab";`).Check(testkit.Rows()) - tk.MustExec(`truncate table t;`) tk.MustExec(`insert into t values("a ", "b ");`) - // Test trailing spaces without sql mode `PAD_CHAR_TO_FULL_LENGTH`. tk.MustExec(`set @@sql_mode="";`) tk.MustPointGet(`select * from t tmp where a = "a";`).Check(testkit.Rows(`a b`)) tk.MustPointGet(`select * from t tmp where a = "a ";`).Check(testkit.Rows()) tk.MustPointGet(`select * from t tmp where a = "a ";`).Check(testkit.Rows()) - // Test trailing spaces with sql mode `PAD_CHAR_TO_FULL_LENGTH`. - tk.MustExec(`set @@sql_mode="PAD_CHAR_TO_FULL_LENGTH";`) - tk.MustPointGet(`select * from t tmp where a = "a";`).Check(testkit.Rows()) - tk.MustPointGet(`select * from t tmp where a = "a ";`).Check(testkit.Rows(`a b`)) - tk.MustPointGet(`select * from t tmp where a = "a ";`).Check(testkit.Rows()) - // Test CHAR BINARY. tk.MustExec(`drop table if exists t;`) tk.MustExec(`create table t(a char(2) binary primary key, b char(2));`) tk.MustExec(`insert into t values(" ", " ");`) tk.MustExec(`insert into t values("a ", "b ");`) - // Test trailing spaces without sql mode `PAD_CHAR_TO_FULL_LENGTH`. tk.MustExec(`set @@sql_mode="";`) tk.MustPointGet(`select * from t tmp where a = "a";`).Check(testkit.Rows(`a b`)) - tk.MustPointGet(`select * from t tmp where a = "a ";`).Check(testkit.Rows(`a b`)) - tk.MustPointGet(`select * from t tmp where a = "a ";`).Check(testkit.Rows(`a b`)) - tk.MustPointGet(`select * from t tmp where a = " ";`).Check(testkit.Rows(` `)) - tk.MustPointGet(`select * from t tmp where a = " ";`).Check(testkit.Rows(` `)) - tk.MustPointGet(`select * from t tmp where a = " ";`).Check(testkit.Rows(` `)) - - // Test trailing spaces with sql mode `PAD_CHAR_TO_FULL_LENGTH`. - tk.MustExec(`set @@sql_mode="PAD_CHAR_TO_FULL_LENGTH";`) - tk.MustPointGet(`select * from t tmp where a = "a";`).Check(testkit.Rows(`a b`)) - tk.MustPointGet(`select * from t tmp where a = "a ";`).Check(testkit.Rows(`a b`)) - tk.MustPointGet(`select * from t tmp where a = "a ";`).Check(testkit.Rows(`a b`)) - tk.MustPointGet(`select * from t tmp where a = " ";`).Check(testkit.Rows(` `)) - tk.MustPointGet(`select * from t tmp where a = " ";`).Check(testkit.Rows(` `)) - tk.MustPointGet(`select * from t tmp where a = " ";`).Check(testkit.Rows(` `)) + tk.MustPointGet(`select * from t tmp where a = "a ";`).Check(testkit.Rows()) + tk.MustPointGet(`select * from t tmp where a = "a ";`).Check(testkit.Rows()) + tk.MustPointGet(`select * from t tmp where a = "";`).Check(testkit.Rows(` `)) + tk.MustPointGet(`select * from t tmp where a = " ";`).Check(testkit.Rows()) + tk.MustPointGet(`select * from t tmp where a = " ";`).Check(testkit.Rows()) // Test both wildcard and column name exist in select field list tk.MustExec(`set @@sql_mode="";`) @@ -260,7 +216,6 @@ func (s *testPointGetSuite) TestIndexLookupChar(c *C) { tk.MustExec(`create table t(a char(2), b char(2), index idx_1(a));`) tk.MustExec(`insert into t values("aa", "bb");`) - // Test truncate without sql mode `PAD_CHAR_TO_FULL_LENGTH`. tk.MustExec(`set @@sql_mode="";`) tk.MustIndexLookup(`select * from t where a = "aa";`).Check(testkit.Rows(`aa bb`)) tk.MustIndexLookup(`select * from t where a = "aab";`).Check(testkit.Rows()) @@ -269,58 +224,29 @@ func (s *testPointGetSuite) TestIndexLookupChar(c *C) { tk.MustIndexLookup(`select * from t tmp where a = "aa";`).Check(testkit.Rows(`aa bb`)) tk.MustIndexLookup(`select * from t tmp where a = "aab";`).Check(testkit.Rows()) - // Test truncate with sql mode `PAD_CHAR_TO_FULL_LENGTH`. - tk.MustExec(`set @@sql_mode="PAD_CHAR_TO_FULL_LENGTH";`) - tk.MustIndexLookup(`select * from t where a = "aa";`).Check(testkit.Rows(`aa bb`)) - tk.MustTableDual(`select * from t where a = "aab";`).Check(testkit.Rows()) - tk.MustExec(`truncate table t;`) tk.MustExec(`insert into t values("a ", "b ");`) - // Test trailing spaces without sql mode `PAD_CHAR_TO_FULL_LENGTH`. tk.MustExec(`set @@sql_mode="";`) tk.MustIndexLookup(`select * from t where a = "a";`).Check(testkit.Rows(`a b`)) tk.MustIndexLookup(`select * from t where a = "a ";`).Check(testkit.Rows()) tk.MustIndexLookup(`select * from t where a = "a ";`).Check(testkit.Rows()) - // Test trailing spaces with sql mode `PAD_CHAR_TO_FULL_LENGTH`. - tk.MustExec(`set @@sql_mode="PAD_CHAR_TO_FULL_LENGTH";`) - tk.MustTableDual(`select * from t where a = "a";`).Check(testkit.Rows()) - tk.MustIndexLookup(`select * from t where a = "a ";`).Check(testkit.Rows(`a b`)) - tk.MustTableDual(`select * from t where a = "a ";`).Check(testkit.Rows()) - // Test CHAR BINARY. tk.MustExec(`drop table if exists t;`) tk.MustExec(`create table t(a char(2) binary, b char(2), index idx_1(a));`) tk.MustExec(`insert into t values(" ", " ");`) tk.MustExec(`insert into t values("a ", "b ");`) - // Test trailing spaces without sql mode `PAD_CHAR_TO_FULL_LENGTH`. tk.MustExec(`set @@sql_mode="";`) tk.MustIndexLookup(`select * from t where a = "a";`).Check(testkit.Rows(`a b`)) - tk.MustIndexLookup(`select * from t where a = "a ";`).Check(testkit.Rows(`a b`)) - tk.MustIndexLookup(`select * from t where a = "a ";`).Check(testkit.Rows(`a b`)) - tk.MustIndexLookup(`select * from t where a = " ";`).Check(testkit.Rows(` `)) - tk.MustIndexLookup(`select * from t where a = " ";`).Check(testkit.Rows(` `)) - tk.MustIndexLookup(`select * from t where a = " ";`).Check(testkit.Rows(` `)) - - // Test trailing spaces with sql mode `PAD_CHAR_TO_FULL_LENGTH`. - tk.MustExec(`set @@sql_mode="PAD_CHAR_TO_FULL_LENGTH";`) - tk.MustIndexLookup(`select * from t where a = "a";`).Check(testkit.Rows(`a b`)) - tk.MustIndexLookup(`select * from t where a = "a ";`).Check(testkit.Rows(`a b`)) - tk.MustIndexLookup(`select * from t where a = "a ";`).Check(testkit.Rows(`a b`)) - tk.MustIndexLookup(`select * from t where a = " ";`).Check(testkit.Rows(` `)) - tk.MustIndexLookup(`select * from t where a = " ";`).Check(testkit.Rows(` `)) - tk.MustIndexLookup(`select * from t where a = " ";`).Check(testkit.Rows(` `)) - - // Test query with table alias in `PAD_CHAR_TO_FULL_LENGTH` mode - tk.MustExec(`set @@sql_mode="PAD_CHAR_TO_FULL_LENGTH";`) - tk.MustIndexLookup(`select * from t tmp where a = "a";`).Check(testkit.Rows(`a b`)) - tk.MustIndexLookup(`select * from t tmp where a = "a ";`).Check(testkit.Rows(`a b`)) - tk.MustIndexLookup(`select * from t tmp where a = "a ";`).Check(testkit.Rows(`a b`)) - tk.MustIndexLookup(`select * from t tmp where a = " ";`).Check(testkit.Rows(` `)) - tk.MustIndexLookup(`select * from t tmp where a = " ";`).Check(testkit.Rows(` `)) - tk.MustIndexLookup(`select * from t tmp where a = " ";`).Check(testkit.Rows(` `)) + tk.MustIndexLookup(`select * from t where a = "a ";`).Check(testkit.Rows()) + tk.MustIndexLookup(`select * from t where a = "a ";`).Check(testkit.Rows()) + tk.MustIndexLookup(`select * from t where a = "";`).Check(testkit.Rows(` `)) + tk.MustIndexLookup(`select * from t where a = " ";`).Check(testkit.Rows()) + tk.MustIndexLookup(`select * from t where a = " ";`).Check(testkit.Rows()) + tk.MustIndexLookup(`select * from t where a = " ";`).Check(testkit.Rows()) + } func (s *testPointGetSuite) TestPointGetVarcharPK(c *C) { @@ -330,60 +256,32 @@ func (s *testPointGetSuite) TestPointGetVarcharPK(c *C) { tk.MustExec(`create table t(a varchar(2) primary key, b varchar(2));`) tk.MustExec(`insert into t values("aa", "bb");`) - // Test truncate without sql mode `PAD_CHAR_TO_FULL_LENGTH`. - // `PAD_CHAR_TO_FULL_LENGTH` should not affect the result. tk.MustExec(`set @@sql_mode="";`) tk.MustPointGet(`select * from t where a = "aa";`).Check(testkit.Rows(`aa bb`)) tk.MustPointGet(`select * from t where a = "aab";`).Check(testkit.Rows()) - // Test truncate with sql mode `PAD_CHAR_TO_FULL_LENGTH`. - // `PAD_CHAR_TO_FULL_LENGTH` should not affect the result. - tk.MustExec(`set @@sql_mode="PAD_CHAR_TO_FULL_LENGTH";`) - tk.MustPointGet(`select * from t where a = "aa";`).Check(testkit.Rows(`aa bb`)) - tk.MustPointGet(`select * from t where a = "aab";`).Check(testkit.Rows()) - tk.MustExec(`truncate table t;`) tk.MustExec(`insert into t values("a ", "b ");`) - // Test trailing spaces without sql mode `PAD_CHAR_TO_FULL_LENGTH`. - // `PAD_CHAR_TO_FULL_LENGTH` should not affect the result. tk.MustExec(`set @@sql_mode="";`) tk.MustPointGet(`select * from t where a = "a";`).Check(testkit.Rows()) tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows(`a b `)) tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows()) - // Test trailing spaces with sql mode `PAD_CHAR_TO_FULL_LENGTH`. - // `PAD_CHAR_TO_FULL_LENGTH` should not affect the result. - tk.MustExec(`set @@sql_mode="PAD_CHAR_TO_FULL_LENGTH";`) - tk.MustPointGet(`select * from t where a = "a";`).Check(testkit.Rows()) - tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows(`a b `)) - tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows()) - // // Test VARCHAR BINARY. tk.MustExec(`drop table if exists t;`) tk.MustExec(`create table t(a varchar(2) binary primary key, b varchar(2));`) tk.MustExec(`insert into t values(" ", " ");`) tk.MustExec(`insert into t values("a ", "b ");`) - // Test trailing spaces without sql mode `PAD_CHAR_TO_FULL_LENGTH`. - // `PAD_CHAR_TO_FULL_LENGTH` should not affect the result. tk.MustExec(`set @@sql_mode="";`) - tk.MustPointGet(`select * from t where a = "a";`).Check(testkit.Rows(`a b `)) + tk.MustPointGet(`select * from t where a = "a";`).Check(testkit.Rows()) tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows(`a b `)) - tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows(`a b `)) - tk.MustPointGet(`select * from t where a = " ";`).Check(testkit.Rows(` `)) + tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows()) + tk.MustPointGet(`select * from t where a = " ";`).Check(testkit.Rows()) tk.MustPointGet(`select * from t where a = " ";`).Check(testkit.Rows(` `)) - tk.MustPointGet(`select * from t where a = " ";`).Check(testkit.Rows(` `)) + tk.MustPointGet(`select * from t where a = " ";`).Check(testkit.Rows()) - // Test trailing spaces with sql mode `PAD_CHAR_TO_FULL_LENGTH`. - // `PAD_CHAR_TO_FULL_LENGTH` should not affect the result. - tk.MustExec(`set @@sql_mode="PAD_CHAR_TO_FULL_LENGTH";`) - tk.MustPointGet(`select * from t where a = "a";`).Check(testkit.Rows(`a b `)) - tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows(`a b `)) - tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows(`a b `)) - tk.MustPointGet(`select * from t where a = " ";`).Check(testkit.Rows(` `)) - tk.MustPointGet(`select * from t where a = " ";`).Check(testkit.Rows(` `)) - tk.MustPointGet(`select * from t where a = " ";`).Check(testkit.Rows(` `)) } func (s *testPointGetSuite) TestPointGetBinaryPK(c *C) { @@ -399,19 +297,11 @@ func (s *testPointGetSuite) TestPointGetBinaryPK(c *C) { tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows()) tk.MustPointGet(`select * from t where a = "a\0";`).Check(testkit.Rows("a\x00 b\x00")) - // `PAD_CHAR_TO_FULL_LENGTH` should not affect the result. - tk.MustExec(`set @@sql_mode="PAD_CHAR_TO_FULL_LENGTH";`) - tk.MustPointGet(`select * from t where a = "a";`).Check(testkit.Rows()) - tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows()) - tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows()) - tk.MustPointGet(`select * from t where a = "a\0";`).Check(testkit.Rows("a\x00 b\x00")) - tk.MustExec(`insert into t values("a ", "b ");`) tk.MustPointGet(`select * from t where a = "a";`).Check(testkit.Rows()) tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows(`a b `)) tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows()) - // `PAD_CHAR_TO_FULL_LENGTH` should not affect the result. tk.MustPointGet(`select * from t where a = "a";`).Check(testkit.Rows()) tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows(`a b `)) tk.MustPointGet(`select * from t where a = "a ";`).Check(testkit.Rows()) @@ -430,19 +320,11 @@ func (s *testPointGetSuite) TestPointGetAliasTableBinaryPK(c *C) { tk.MustPointGet(`select * from t tmp where a = "a ";`).Check(testkit.Rows()) tk.MustPointGet(`select * from t tmp where a = "a\0";`).Check(testkit.Rows("a\x00 b\x00")) - // `PAD_CHAR_TO_FULL_LENGTH` should not affect the result. - tk.MustExec(`set @@sql_mode="PAD_CHAR_TO_FULL_LENGTH";`) - tk.MustPointGet(`select * from t tmp where a = "a";`).Check(testkit.Rows()) - tk.MustPointGet(`select * from t tmp where a = "a ";`).Check(testkit.Rows()) - tk.MustPointGet(`select * from t tmp where a = "a ";`).Check(testkit.Rows()) - tk.MustPointGet(`select * from t tmp where a = "a\0";`).Check(testkit.Rows("a\x00 b\x00")) - tk.MustExec(`insert into t values("a ", "b ");`) tk.MustPointGet(`select * from t tmp where a = "a";`).Check(testkit.Rows()) tk.MustPointGet(`select * from t tmp where a = "a ";`).Check(testkit.Rows(`a b `)) tk.MustPointGet(`select * from t tmp where a = "a ";`).Check(testkit.Rows()) - // `PAD_CHAR_TO_FULL_LENGTH` should not affect the result. tk.MustPointGet(`select * from t tmp where a = "a";`).Check(testkit.Rows()) tk.MustPointGet(`select * from t tmp where a = "a ";`).Check(testkit.Rows(`a b `)) tk.MustPointGet(`select * from t tmp where a = "a ";`).Check(testkit.Rows()) @@ -468,27 +350,15 @@ func (s *testPointGetSuite) TestIndexLookupBinary(c *C) { tk.MustIndexLookup(`select * from t tmp where a = "a ";`).Check(testkit.Rows()) tk.MustIndexLookup(`select * from t tmp where a = "a\0";`).Check(testkit.Rows("a\x00 b\x00")) - // `PAD_CHAR_TO_FULL_LENGTH` should not affect the result. - tk.MustExec(`set @@sql_mode="PAD_CHAR_TO_FULL_LENGTH";`) - tk.MustIndexLookup(`select * from t where a = "a";`).Check(testkit.Rows()) - tk.MustIndexLookup(`select * from t where a = "a ";`).Check(testkit.Rows()) - tk.MustIndexLookup(`select * from t where a = "a ";`).Check(testkit.Rows()) - tk.MustIndexLookup(`select * from t where a = "a\0";`).Check(testkit.Rows("a\x00 b\x00")) - tk.MustExec(`insert into t values("a ", "b ");`) tk.MustIndexLookup(`select * from t where a = "a";`).Check(testkit.Rows()) tk.MustIndexLookup(`select * from t where a = "a ";`).Check(testkit.Rows(`a b `)) tk.MustIndexLookup(`select * from t where a = "a ";`).Check(testkit.Rows()) - // `PAD_CHAR_TO_FULL_LENGTH` should not affect the result. tk.MustIndexLookup(`select * from t where a = "a";`).Check(testkit.Rows()) tk.MustIndexLookup(`select * from t where a = "a ";`).Check(testkit.Rows(`a b `)) tk.MustIndexLookup(`select * from t where a = "a ";`).Check(testkit.Rows()) - // Test query with table alias in `PAD_CHAR_TO_FULL_LENGTH` mode - tk.MustIndexLookup(`select * from t tmp where a = "a";`).Check(testkit.Rows()) - tk.MustIndexLookup(`select * from t tmp where a = "a ";`).Check(testkit.Rows(`a b `)) - tk.MustIndexLookup(`select * from t tmp where a = "a ";`).Check(testkit.Rows()) } func (s *testPointGetSuite) TestIssue10448(c *C) { diff --git a/expression/column.go b/expression/column.go index 493c51de01984..2961e83235ecf 100644 --- a/expression/column.go +++ b/expression/column.go @@ -15,7 +15,6 @@ package expression import ( "fmt" - "strings" "github.com/pingcap/errors" "github.com/pingcap/parser/model" @@ -71,10 +70,6 @@ func (col *CorrelatedColumn) EvalString(ctx sessionctx.Context, row chunk.Row) ( return "", true, nil } res, err := col.Data.ToString() - resLen := len([]rune(res)) - if resLen < col.RetType.Flen && ctx.GetSessionVars().StmtCtx.PadCharToFullLength { - res = res + strings.Repeat(" ", col.RetType.Flen-resLen) - } return res, err != nil, err } @@ -249,12 +244,6 @@ func (col *Column) EvalString(ctx sessionctx.Context, row chunk.Row) (string, bo } val := row.GetString(col.Index) - if ctx.GetSessionVars().StmtCtx.PadCharToFullLength && col.GetType().Tp == mysql.TypeString { - valLen := len([]rune(val)) - if valLen < col.RetType.Flen { - val = val + strings.Repeat(" ", col.RetType.Flen-valLen) - } - } return val, false, nil } diff --git a/go.sum b/go.sum index 5c5bd4976ef42..49d379375f752 100644 --- a/go.sum +++ b/go.sum @@ -181,6 +181,7 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d h1:GoAlyOgbOEIFd github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/remyoudompheng/bigfft v0.0.0-20190512091148-babf20351dd7 h1:FUL3b97ZY2EPqg2NbXKuMHs5pXJB9hjj1fDHnF2vl28= github.com/remyoudompheng/bigfft v0.0.0-20190512091148-babf20351dd7/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= +github.com/sergi/go-diff v1.0.1-0.20180205163309-da645544ed44 h1:tB9NOR21++IjLyVx3/PCPhWMwqGNCMQEH96A6dMZ/gc= github.com/sergi/go-diff v1.0.1-0.20180205163309-da645544ed44/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/shirou/gopsutil v2.18.10+incompatible h1:cy84jW6EVRPa5g9HAHrlbxMSIjBhDSX0OFYyMYminYs= github.com/shirou/gopsutil v2.18.10+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= diff --git a/sessionctx/stmtctx/stmtctx.go b/sessionctx/stmtctx/stmtctx.go index e2dd000c1f960..2139b81e1a6b7 100644 --- a/sessionctx/stmtctx/stmtctx.go +++ b/sessionctx/stmtctx/stmtctx.go @@ -65,7 +65,6 @@ type StatementContext struct { OverflowAsWarning bool InShowWarning bool UseCache bool - PadCharToFullLength bool BatchCheck bool InNullRejectCheck bool AllowInvalidDate bool diff --git a/store/mockstore/mocktikv/cop_handler_dag.go b/store/mockstore/mocktikv/cop_handler_dag.go index c8b7c6aaf112e..36eeacc7b36f2 100644 --- a/store/mockstore/mocktikv/cop_handler_dag.go +++ b/store/mockstore/mocktikv/cop_handler_dag.go @@ -417,7 +417,6 @@ func flagsToStatementContext(flags uint64) *stmtctx.StatementContext { sc := new(stmtctx.StatementContext) sc.IgnoreTruncate = (flags & model.FlagIgnoreTruncate) > 0 sc.TruncateAsWarning = (flags & model.FlagTruncateAsWarning) > 0 - sc.PadCharToFullLength = (flags & model.FlagPadCharToFullLength) > 0 return sc } diff --git a/types/const_test.go b/types/const_test.go index b9a2c64fb37c8..e5e46037e796a 100644 --- a/types/const_test.go +++ b/types/const_test.go @@ -255,38 +255,6 @@ func (s *testMySQLConstSuite) TestIgnoreSpaceMode(c *C) { } -func (s *testMySQLConstSuite) TestPadCharToFullLengthMode(c *C) { - tk := testkit.NewTestKit(c, s.store) - tk.MustExec("use test") - // test type `CHAR(n)` - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t1 (a char(10));") - tk.MustExec("insert into t1 values ('xy');") - tk.MustExec("set sql_mode='';") - r := tk.MustQuery(`SELECT a='xy ', char_length(a) FROM t1;`) - r.Check(testkit.Rows("0 2")) - r = tk.MustQuery(`SELECT count(*) FROM t1 WHERE a='xy ';`) - r.Check(testkit.Rows("0")) - tk.MustExec("set sql_mode='PAD_CHAR_TO_FULL_LENGTH';") - r = tk.MustQuery(`SELECT a='xy ', char_length(a) FROM t1;`) - r.Check(testkit.Rows("1 10")) - r = tk.MustQuery(`SELECT count(*) FROM t1 WHERE a='xy ';`) - r.Check(testkit.Rows("1")) - - // test type `VARCHAR(n)` - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t1 (a varchar(10));") - tk.MustExec("insert into t1 values ('xy');") - tk.MustExec("set sql_mode='';") - r = tk.MustQuery(`SELECT a='xy ', char_length(a) FROM t1;`) - r.Check(testkit.Rows("0 2")) - r = tk.MustQuery(`SELECT count(*) FROM t1 WHERE a='xy ';`) - r.Check(testkit.Rows("0")) - tk.MustExec("set sql_mode='PAD_CHAR_TO_FULL_LENGTH';") - r = tk.MustQuery(`SELECT a='xy ', char_length(a) FROM t1;`) - r.Check(testkit.Rows("0 2")) -} - func (s *testMySQLConstSuite) TestNoBackslashEscapesMode(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("set sql_mode=''") diff --git a/util/ranger/points.go b/util/ranger/points.go index efb2efcda40d2..c9ba811ee28c9 100644 --- a/util/ranger/points.go +++ b/util/ranger/points.go @@ -17,15 +17,12 @@ import ( "fmt" "math" "sort" - "strings" "github.com/pingcap/errors" "github.com/pingcap/parser/ast" - "github.com/pingcap/parser/charset" "github.com/pingcap/parser/mysql" "github.com/pingcap/parser/terror" "github.com/pingcap/tidb/expression" - "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/chunk" @@ -245,11 +242,6 @@ func (r *builder) buildFormBinOp(expr *expression.ScalarFunction) []point { return nil } - value, err = HandlePadCharToFullLength(r.sc, ft, value) - if err != nil { - return nil - } - value, op, isValidRange := handleUnsignedIntCol(ft, value, op) if !isValidRange { return nil @@ -286,64 +278,6 @@ func (r *builder) buildFormBinOp(expr *expression.ScalarFunction) []point { return nil } -// HandlePadCharToFullLength handles the "PAD_CHAR_TO_FULL_LENGTH" sql mode for -// CHAR[N] index columns. -// NOTE: kv.ErrNotExist is returned to indicate that this value can not match -// any (key, value) pair in tikv storage. This error should be handled by -// the caller. -func HandlePadCharToFullLength(sc *stmtctx.StatementContext, ft *types.FieldType, val types.Datum) (types.Datum, error) { - isChar := (ft.Tp == mysql.TypeString) - isBinary := (isChar && ft.Collate == charset.CollationBin) - isVarchar := (ft.Tp == mysql.TypeVarString || ft.Tp == mysql.TypeVarchar) - isVarBinary := (isVarchar && ft.Collate == charset.CollationBin) - - if !isChar && !isVarchar && !isBinary && !isVarBinary { - return val, nil - } - - hasBinaryFlag := mysql.HasBinaryFlag(ft.Flag) - targetStr, err := val.ToString() - if err != nil { - return val, err - } - - switch { - case isBinary || isVarBinary: - val.SetString(targetStr) - return val, nil - case isVarchar && hasBinaryFlag: - noTrailingSpace := strings.TrimRight(targetStr, " ") - if numSpacesToFill := ft.Flen - len(noTrailingSpace); numSpacesToFill > 0 { - noTrailingSpace += strings.Repeat(" ", numSpacesToFill) - } - val.SetString(noTrailingSpace) - return val, nil - case isVarchar && !hasBinaryFlag: - val.SetString(targetStr) - return val, nil - case isChar && hasBinaryFlag: - noTrailingSpace := strings.TrimRight(targetStr, " ") - val.SetString(noTrailingSpace) - return val, nil - case isChar && !hasBinaryFlag && !sc.PadCharToFullLength: - val.SetString(targetStr) - return val, nil - case isChar && !hasBinaryFlag && sc.PadCharToFullLength: - if len(targetStr) != ft.Flen { - // return kv.ErrNotExist to indicate that this value can not match any - // (key, value) pair in tikv storage. - return val, kv.ErrNotExist - } - // Trailing spaces of data typed "CHAR[N]" is trimed in the storage, we - // need to trim these trailing spaces as well. - noTrailingSpace := strings.TrimRight(targetStr, " ") - val.SetString(noTrailingSpace) - return val, nil - default: - return val, nil - } -} - // handleUnsignedIntCol handles the case when unsigned column meets negative integer value. // The three returned values are: fixed constant value, fixed operator, and a boolean // which indicates whether the range is valid or not.