From 448857402f62e237a90fc0b1841767526d7e8f5d Mon Sep 17 00:00:00 2001 From: xiongjiwei Date: Fri, 4 Dec 2020 18:59:48 +0800 Subject: [PATCH 1/4] cherry pick #19820 to release-3.0 Signed-off-by: ti-srebot --- expression/builtin_compare.go | 2 +- expression/integration_test.go | 187 ++++++++++++++++++++++++++++ planner/core/expression_rewriter.go | 42 +++++-- 3 files changed, 223 insertions(+), 8 deletions(-) diff --git a/expression/builtin_compare.go b/expression/builtin_compare.go index 76f55d5edda16..702e16f191c59 100644 --- a/expression/builtin_compare.go +++ b/expression/builtin_compare.go @@ -379,7 +379,7 @@ func temporalWithDateAsNumEvalType(argTp *types.FieldType) (argEvalType types.Ev return } -// GetCmpTp4MinMax gets compare type for GREATEST and LEAST and BETWEEN (mainly for datetime). +// GetCmpTp4MinMax gets compare type for GREATEST and LEAST and BETWEEN func GetCmpTp4MinMax(args []Expression) (argTp types.EvalType) { datetimeFound, isAllStr := false, true cmpEvalType, isStr, isTemporalWithDate := temporalWithDateAsNumEvalType(args[0].GetType()) diff --git a/expression/integration_test.go b/expression/integration_test.go index 1ee1623e5d52a..7fed904bb88f7 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -5206,7 +5206,194 @@ func (s *testIntegrationSuite) TestIssue18850(c *C) { tk.MustQuery("select /*+ HASH_JOIN(t, t1) */ * from t join t1 on t.b = t1.b1;").Check(testkit.Rows("1 A 1 A")) } +<<<<<<< HEAD func (s *testIntegrationSuite) TestIssue19804(c *C) { +======= +func (s *testIntegrationSerialSuite) TestNullValueRange(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 int, b int, index(a))") + tk.MustExec("insert into t values (null, 0), (null, 1), (10, 11), (10, 12)") + tk.MustQuery("select * from t use index(a) where a is null order by b").Check(testkit.Rows(" 0", " 1")) + tk.MustQuery("select * from t use index(a) where a<=>null order by b").Check(testkit.Rows(" 0", " 1")) + tk.MustQuery("select * from t use index(a) where a<=>10 order by b").Check(testkit.Rows("10 11", "10 12")) + + tk.MustExec("drop table if exists t1") + tk.MustExec("create table t1(a int, b int, c int, unique key(a, b, c))") + tk.MustExec("insert into t1 values (1, null, 1), (1, null, 2), (1, null, 3), (1, null, 4)") + tk.MustExec("insert into t1 values (1, 1, 1), (1, 2, 2), (1, 3, 33), (1, 4, 44)") + tk.MustQuery("select c from t1 where a=1 and b<=>null and c>2 order by c").Check(testkit.Rows("3", "4")) + tk.MustQuery("select c from t1 where a=1 and b is null and c>2 order by c").Check(testkit.Rows("3", "4")) + tk.MustQuery("select c from t1 where a=1 and b is not null and c>2 order by c").Check(testkit.Rows("33", "44")) +} + +func (s *testIntegrationSerialSuite) TestIssue18652(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("DROP TABLE IF EXISTS t1") + tk.MustExec("CREATE TABLE t1 ( `pk` int not null primary key auto_increment, `col_smallint_key_signed` smallint , key (`col_smallint_key_signed`))") + tk.MustExec("INSERT INTO `t1` VALUES (1,0),(2,NULL),(3,NULL),(4,0),(5,0),(6,NULL),(7,NULL),(8,0),(9,0),(10,0)") + tk.MustQuery("SELECT * FROM t1 WHERE ( LOG( `col_smallint_key_signed`, -8297584758403770424 ) ) DIV 1").Check(testkit.Rows()) +} + +func (s *testIntegrationSerialSuite) TestIssue18662(c *C) { + collate.SetNewCollationEnabledForTest(true) + defer collate.SetNewCollationEnabledForTest(false) + + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(a varchar(10) collate utf8mb4_bin, b varchar(10) collate utf8mb4_general_ci);") + tk.MustExec("insert into t (a, b) values ('a', 'A');") + tk.MustQuery("select * from t where field('A', a collate utf8mb4_general_ci, b) > 1;").Check(testkit.Rows()) + tk.MustQuery("select * from t where field('A', a, b collate utf8mb4_general_ci) > 1;").Check(testkit.Rows()) + tk.MustQuery("select * from t where field('A' collate utf8mb4_general_ci, a, b) > 1;").Check(testkit.Rows()) + tk.MustQuery("select * from t where field('A', a, b) > 1;").Check(testkit.Rows("a A")) +} + +func (s *testIntegrationSerialSuite) TestIssue19045(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t, t1, t2") + tk.MustExec(`CREATE TABLE t ( + id int(11) NOT NULL AUTO_INCREMENT, + a char(10) DEFAULT NULL, + PRIMARY KEY (id) +);`) + tk.MustExec(`CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + a char(10) DEFAULT NULL, + b char(10) DEFAULT NULL, + c char(10) DEFAULT NULL, + PRIMARY KEY (id) +);`) + tk.MustExec(`CREATE TABLE t2 ( + id int(11) NOT NULL AUTO_INCREMENT, + a char(10) DEFAULT NULL, + b char(10) DEFAULT NULL, + PRIMARY KEY (id), + UNIQUE KEY b (b) +);`) + tk.MustExec(`insert into t1(a,b,c) values('hs4_0004', "04", "101"), ('a01', "01", "101"),('a011', "02", "101");`) + tk.MustExec(`insert into t2(a,b) values("02","03");`) + tk.MustExec(`insert into t(a) values('101'),('101');`) + tk.MustQuery(`select ( SELECT t1.a FROM t1, t2 WHERE t1.b = t2.a AND t2.b = '03' AND t1.c = a.a) invode from t a ;`).Check(testkit.Rows("a011", "a011")) +} + +func (s *testIntegrationSerialSuite) TestIssue19116(c *C) { + collate.SetNewCollationEnabledForTest(true) + defer collate.SetNewCollationEnabledForTest(false) + + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("set names utf8mb4 collate utf8mb4_general_ci;") + tk.MustQuery("select collation(concat(1 collate `binary`));").Check(testkit.Rows("binary")) + tk.MustQuery("select coercibility(concat(1 collate `binary`));").Check(testkit.Rows("0")) + tk.MustQuery("select collation(concat(NULL,NULL));").Check(testkit.Rows("binary")) + tk.MustQuery("select coercibility(concat(NULL,NULL));").Check(testkit.Rows("6")) + tk.MustQuery("select collation(concat(1,1));").Check(testkit.Rows("utf8mb4_general_ci")) + tk.MustQuery("select coercibility(concat(1,1));").Check(testkit.Rows("4")) + tk.MustQuery("select collation(1);").Check(testkit.Rows("binary")) + tk.MustQuery("select coercibility(1);").Check(testkit.Rows("5")) + tk.MustQuery("select coercibility(1=1);").Check(testkit.Rows("5")) +} + +func (s *testIntegrationSerialSuite) TestIssue14448and19383(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("DROP TABLE IF EXISTS t1") + tk.MustExec("CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY)") + tk.MustExec("INSERT INTO t1 VALUES (1),(2),(3)") + _, err := tk.Exec("SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1") + message := `function SQL_CALC_FOUND_ROWS has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions` + c.Assert(strings.Contains(err.Error(), message), IsTrue) + _, err = tk.Exec("SELECT * FROM t1 LOCK IN SHARE MODE") + message = `function LOCK IN SHARE MODE has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions` + c.Assert(strings.Contains(err.Error(), message), IsTrue) + tk.MustExec("SET tidb_enable_noop_functions=1") + tk.MustExec("SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1") + tk.MustExec("SELECT * FROM t1 LOCK IN SHARE MODE") +} + +func (s *testIntegrationSerialSuite) TestIssue19315(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("drop table if exists t1") + tk.MustExec("CREATE TABLE `t` (`a` bit(10) DEFAULT NULL,`b` int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin") + tk.MustExec("INSERT INTO `t` VALUES (_binary '\\0',1),(_binary '\\0',2),(_binary '\\0',5),(_binary '\\0',4),(_binary '\\0',2),(_binary '\\0 ',4)") + tk.MustExec("CREATE TABLE `t1` (`a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin") + tk.MustExec("INSERT INTO `t1` VALUES (1,1),(1,5),(2,3),(2,4),(3,3)") + err := tk.QueryToErr("select * from t where t.b > (select min(t1.b) from t1 where t1.a > t.a)") + c.Assert(err, IsNil) +} + +func (s *testIntegrationSerialSuite) TestIssue18674(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustQuery("select -1.0 % -1.0").Check(testkit.Rows("0.0")) + tk.MustExec("use test") + tk.MustExec("drop table if exists t1") + tk.MustExec("create table t1(`pk` int primary key,`col_float_key_signed` float ,key (`col_float_key_signed`))") + tk.MustExec("insert into t1 values (0, null), (1, 0), (2, -0), (3, 1), (-1,-1)") + tk.MustQuery("select * from t1 where ( `col_float_key_signed` % `col_float_key_signed`) IS FALSE").Sort().Check(testkit.Rows("-1 -1", "3 1")) + tk.MustQuery("select `col_float_key_signed` , `col_float_key_signed` % `col_float_key_signed` from t1").Sort().Check(testkit.Rows( + "-1 -0", "0 ", "0 ", "1 0", " ")) + tk.MustQuery("select `col_float_key_signed` , (`col_float_key_signed` % `col_float_key_signed`) IS FALSE from t1").Sort().Check(testkit.Rows( + "-1 1", "0 0", "0 0", "1 1", " 0")) +} + +func (s *testIntegrationSerialSuite) TestIssue17063(c *C) { + collate.SetNewCollationEnabledForTest(true) + defer collate.SetNewCollationEnabledForTest(false) + + tk := testkit.NewTestKit(c, s.store) + tk.MustExec(`use test;`) + tk.MustExec(`drop table if exists t;`) + tk.MustExec("create table t(a char, b char) collate utf8mb4_general_ci;") + tk.MustExec(`insert into t values('a', 'b');`) + tk.MustExec(`insert into t values('a', 'B');`) + tk.MustQuery(`select * from t where if(a='x', a, b) = 'b';`).Check(testkit.Rows("a b", "a B")) + tk.MustQuery(`select collation(if(a='x', a, b)) from t;`).Check(testkit.Rows("utf8mb4_general_ci", "utf8mb4_general_ci")) + tk.MustQuery(`select coercibility(if(a='x', a, b)) from t;`).Check(testkit.Rows("2", "2")) + tk.MustQuery(`select collation(lag(b, 1, 'B') over w) from t window w as (order by b);`).Check(testkit.Rows("utf8mb4_general_ci", "utf8mb4_general_ci")) + tk.MustQuery(`select coercibility(lag(b, 1, 'B') over w) from t window w as (order by b);`).Check(testkit.Rows("2", "2")) +} + +func (s *testIntegrationSerialSuite) TestIssue11177(c *C) { + collate.SetNewCollationEnabledForTest(true) + defer collate.SetNewCollationEnabledForTest(false) + + tk := testkit.NewTestKit(c, s.store) + tk.MustQuery("SELECT 'lvuleck' BETWEEN '2008-09-16 22:23:50' AND 0;").Check(testkit.Rows("0")) + tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1292 Truncated incorrect FLOAT value: 'lvuleck'", "Warning 1292 Truncated incorrect FLOAT value: '2008-09-16 22:23:50'")) + tk.MustQuery("SELECT 'aa' BETWEEN 'bb' AND 0;").Check(testkit.Rows("1")) + tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1292 Truncated incorrect FLOAT value: 'aa'", "Warning 1292 Truncated incorrect FLOAT value: 'bb'")) + tk.MustQuery("select 1 between 0 and b'110';").Check(testkit.Rows("1")) + tk.MustQuery("show warnings;").Check(testkit.Rows()) + tk.MustQuery("select 'b' between 'a' and b'110';").Check(testkit.Rows("0")) + tk.MustQuery("show warnings;").Check(testkit.Rows()) +} + +func (s *testIntegrationSuite) TestIssue19504(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t1;") + tk.MustExec("create table t1 (c_int int, primary key (c_int));") + tk.MustExec("insert into t1 values (1), (2), (3);") + tk.MustExec("drop table if exists t2;") + tk.MustExec("create table t2 (c_int int, primary key (c_int));") + tk.MustExec("insert into t2 values (1);") + tk.MustQuery("select (select count(c_int) from t2 where c_int = t1.c_int) c1, (select count(1) from t2 where c_int = t1.c_int) c2 from t1;"). + Check(testkit.Rows("1 1", "0 0", "0 0")) + tk.MustQuery("select (select count(c_int*c_int) from t2 where c_int = t1.c_int) c1, (select count(1) from t2 where c_int = t1.c_int) c2 from t1;"). + Check(testkit.Rows("1 1", "0 0", "0 0")) +} + +func (s *testIntegrationSerialSuite) TestIssue19804(c *C) { + collate.SetNewCollationEnabledForTest(true) + defer collate.SetNewCollationEnabledForTest(false) + +>>>>>>> 1df810744... planner: fix invalid convert type in between...and... (#19820) tk := testkit.NewTestKit(c, s.store) tk.MustExec(`use test;`) tk.MustExec(`drop table if exists t;`) diff --git a/planner/core/expression_rewriter.go b/planner/core/expression_rewriter.go index b906c4f74d00d..db70f677aadf7 100644 --- a/planner/core/expression_rewriter.go +++ b/planner/core/expression_rewriter.go @@ -1304,6 +1304,40 @@ func (er *expressionRewriter) rowToScalarFunc(v *ast.RowExpr) { er.ctxStack = append(er.ctxStack, function) } +func (er *expressionRewriter) wrapExpWithCast() (expr, lexp, rexp expression.Expression) { + stkLen := len(er.ctxStack) + expr, lexp, rexp = er.ctxStack[stkLen-3], er.ctxStack[stkLen-2], er.ctxStack[stkLen-1] + var castFunc func(sessionctx.Context, expression.Expression) expression.Expression + switch expression.GetCmpTp4MinMax([]expression.Expression{expr, lexp, rexp}) { + case types.ETInt: + castFunc = expression.WrapWithCastAsInt + case types.ETReal: + castFunc = expression.WrapWithCastAsReal + case types.ETDecimal: + castFunc = expression.WrapWithCastAsDecimal + case types.ETString: + castFunc = func(ctx sessionctx.Context, e expression.Expression) expression.Expression { + // string kind expression do not need cast + if e.GetType().EvalType().IsStringKind() { + return e + } + return expression.WrapWithCastAsString(ctx, e) + } + case types.ETDatetime: + expr = expression.WrapWithCastAsTime(er.sctx, expr, types.NewFieldType(mysql.TypeDatetime)) + lexp = expression.WrapWithCastAsTime(er.sctx, lexp, types.NewFieldType(mysql.TypeDatetime)) + rexp = expression.WrapWithCastAsTime(er.sctx, rexp, types.NewFieldType(mysql.TypeDatetime)) + return + default: + return + } + + expr = castFunc(er.sctx, expr) + lexp = castFunc(er.sctx, lexp) + rexp = castFunc(er.sctx, rexp) + return +} + func (er *expressionRewriter) betweenToExpression(v *ast.BetweenExpr) { stkLen := len(er.ctxStack) er.err = expression.CheckArgsNotMultiColumnRow(er.ctxStack[stkLen-3:]...) @@ -1311,13 +1345,7 @@ func (er *expressionRewriter) betweenToExpression(v *ast.BetweenExpr) { return } - expr, lexp, rexp := er.ctxStack[stkLen-3], er.ctxStack[stkLen-2], er.ctxStack[stkLen-1] - - if expression.GetCmpTp4MinMax([]expression.Expression{expr, lexp, rexp}) == types.ETDatetime { - expr = expression.WrapWithCastAsTime(er.sctx, expr, types.NewFieldType(mysql.TypeDatetime)) - lexp = expression.WrapWithCastAsTime(er.sctx, lexp, types.NewFieldType(mysql.TypeDatetime)) - rexp = expression.WrapWithCastAsTime(er.sctx, rexp, types.NewFieldType(mysql.TypeDatetime)) - } + expr, lexp, rexp := er.wrapExpWithCast() var op string var l, r expression.Expression From a86857ea83a1a8072626c3fc10729071e55f2a27 Mon Sep 17 00:00:00 2001 From: xiongjiwei Date: Fri, 4 Dec 2020 19:12:59 +0800 Subject: [PATCH 2/4] Update integration_test.go --- expression/integration_test.go | 174 +-------------------------------- 1 file changed, 1 insertion(+), 173 deletions(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index 7fed904bb88f7..3490ca896da8a 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -5206,159 +5206,6 @@ func (s *testIntegrationSuite) TestIssue18850(c *C) { tk.MustQuery("select /*+ HASH_JOIN(t, t1) */ * from t join t1 on t.b = t1.b1;").Check(testkit.Rows("1 A 1 A")) } -<<<<<<< HEAD -func (s *testIntegrationSuite) TestIssue19804(c *C) { -======= -func (s *testIntegrationSerialSuite) TestNullValueRange(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 int, b int, index(a))") - tk.MustExec("insert into t values (null, 0), (null, 1), (10, 11), (10, 12)") - tk.MustQuery("select * from t use index(a) where a is null order by b").Check(testkit.Rows(" 0", " 1")) - tk.MustQuery("select * from t use index(a) where a<=>null order by b").Check(testkit.Rows(" 0", " 1")) - tk.MustQuery("select * from t use index(a) where a<=>10 order by b").Check(testkit.Rows("10 11", "10 12")) - - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t1(a int, b int, c int, unique key(a, b, c))") - tk.MustExec("insert into t1 values (1, null, 1), (1, null, 2), (1, null, 3), (1, null, 4)") - tk.MustExec("insert into t1 values (1, 1, 1), (1, 2, 2), (1, 3, 33), (1, 4, 44)") - tk.MustQuery("select c from t1 where a=1 and b<=>null and c>2 order by c").Check(testkit.Rows("3", "4")) - tk.MustQuery("select c from t1 where a=1 and b is null and c>2 order by c").Check(testkit.Rows("3", "4")) - tk.MustQuery("select c from t1 where a=1 and b is not null and c>2 order by c").Check(testkit.Rows("33", "44")) -} - -func (s *testIntegrationSerialSuite) TestIssue18652(c *C) { - tk := testkit.NewTestKit(c, s.store) - tk.MustExec("use test") - tk.MustExec("DROP TABLE IF EXISTS t1") - tk.MustExec("CREATE TABLE t1 ( `pk` int not null primary key auto_increment, `col_smallint_key_signed` smallint , key (`col_smallint_key_signed`))") - tk.MustExec("INSERT INTO `t1` VALUES (1,0),(2,NULL),(3,NULL),(4,0),(5,0),(6,NULL),(7,NULL),(8,0),(9,0),(10,0)") - tk.MustQuery("SELECT * FROM t1 WHERE ( LOG( `col_smallint_key_signed`, -8297584758403770424 ) ) DIV 1").Check(testkit.Rows()) -} - -func (s *testIntegrationSerialSuite) TestIssue18662(c *C) { - collate.SetNewCollationEnabledForTest(true) - defer collate.SetNewCollationEnabledForTest(false) - - tk := testkit.NewTestKit(c, s.store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a varchar(10) collate utf8mb4_bin, b varchar(10) collate utf8mb4_general_ci);") - tk.MustExec("insert into t (a, b) values ('a', 'A');") - tk.MustQuery("select * from t where field('A', a collate utf8mb4_general_ci, b) > 1;").Check(testkit.Rows()) - tk.MustQuery("select * from t where field('A', a, b collate utf8mb4_general_ci) > 1;").Check(testkit.Rows()) - tk.MustQuery("select * from t where field('A' collate utf8mb4_general_ci, a, b) > 1;").Check(testkit.Rows()) - tk.MustQuery("select * from t where field('A', a, b) > 1;").Check(testkit.Rows("a A")) -} - -func (s *testIntegrationSerialSuite) TestIssue19045(c *C) { - tk := testkit.NewTestKit(c, s.store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t, t1, t2") - tk.MustExec(`CREATE TABLE t ( - id int(11) NOT NULL AUTO_INCREMENT, - a char(10) DEFAULT NULL, - PRIMARY KEY (id) -);`) - tk.MustExec(`CREATE TABLE t1 ( - id int(11) NOT NULL AUTO_INCREMENT, - a char(10) DEFAULT NULL, - b char(10) DEFAULT NULL, - c char(10) DEFAULT NULL, - PRIMARY KEY (id) -);`) - tk.MustExec(`CREATE TABLE t2 ( - id int(11) NOT NULL AUTO_INCREMENT, - a char(10) DEFAULT NULL, - b char(10) DEFAULT NULL, - PRIMARY KEY (id), - UNIQUE KEY b (b) -);`) - tk.MustExec(`insert into t1(a,b,c) values('hs4_0004', "04", "101"), ('a01', "01", "101"),('a011', "02", "101");`) - tk.MustExec(`insert into t2(a,b) values("02","03");`) - tk.MustExec(`insert into t(a) values('101'),('101');`) - tk.MustQuery(`select ( SELECT t1.a FROM t1, t2 WHERE t1.b = t2.a AND t2.b = '03' AND t1.c = a.a) invode from t a ;`).Check(testkit.Rows("a011", "a011")) -} - -func (s *testIntegrationSerialSuite) TestIssue19116(c *C) { - collate.SetNewCollationEnabledForTest(true) - defer collate.SetNewCollationEnabledForTest(false) - - tk := testkit.NewTestKit(c, s.store) - tk.MustExec("set names utf8mb4 collate utf8mb4_general_ci;") - tk.MustQuery("select collation(concat(1 collate `binary`));").Check(testkit.Rows("binary")) - tk.MustQuery("select coercibility(concat(1 collate `binary`));").Check(testkit.Rows("0")) - tk.MustQuery("select collation(concat(NULL,NULL));").Check(testkit.Rows("binary")) - tk.MustQuery("select coercibility(concat(NULL,NULL));").Check(testkit.Rows("6")) - tk.MustQuery("select collation(concat(1,1));").Check(testkit.Rows("utf8mb4_general_ci")) - tk.MustQuery("select coercibility(concat(1,1));").Check(testkit.Rows("4")) - tk.MustQuery("select collation(1);").Check(testkit.Rows("binary")) - tk.MustQuery("select coercibility(1);").Check(testkit.Rows("5")) - tk.MustQuery("select coercibility(1=1);").Check(testkit.Rows("5")) -} - -func (s *testIntegrationSerialSuite) TestIssue14448and19383(c *C) { - tk := testkit.NewTestKit(c, s.store) - tk.MustExec("use test") - tk.MustExec("DROP TABLE IF EXISTS t1") - tk.MustExec("CREATE TABLE t1 (a INT NOT NULL PRIMARY KEY)") - tk.MustExec("INSERT INTO t1 VALUES (1),(2),(3)") - _, err := tk.Exec("SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1") - message := `function SQL_CALC_FOUND_ROWS has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions` - c.Assert(strings.Contains(err.Error(), message), IsTrue) - _, err = tk.Exec("SELECT * FROM t1 LOCK IN SHARE MODE") - message = `function LOCK IN SHARE MODE has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions` - c.Assert(strings.Contains(err.Error(), message), IsTrue) - tk.MustExec("SET tidb_enable_noop_functions=1") - tk.MustExec("SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1") - tk.MustExec("SELECT * FROM t1 LOCK IN SHARE MODE") -} - -func (s *testIntegrationSerialSuite) TestIssue19315(c *C) { - tk := testkit.NewTestKit(c, s.store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("drop table if exists t1") - tk.MustExec("CREATE TABLE `t` (`a` bit(10) DEFAULT NULL,`b` int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin") - tk.MustExec("INSERT INTO `t` VALUES (_binary '\\0',1),(_binary '\\0',2),(_binary '\\0',5),(_binary '\\0',4),(_binary '\\0',2),(_binary '\\0 ',4)") - tk.MustExec("CREATE TABLE `t1` (`a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin") - tk.MustExec("INSERT INTO `t1` VALUES (1,1),(1,5),(2,3),(2,4),(3,3)") - err := tk.QueryToErr("select * from t where t.b > (select min(t1.b) from t1 where t1.a > t.a)") - c.Assert(err, IsNil) -} - -func (s *testIntegrationSerialSuite) TestIssue18674(c *C) { - tk := testkit.NewTestKit(c, s.store) - tk.MustQuery("select -1.0 % -1.0").Check(testkit.Rows("0.0")) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t1(`pk` int primary key,`col_float_key_signed` float ,key (`col_float_key_signed`))") - tk.MustExec("insert into t1 values (0, null), (1, 0), (2, -0), (3, 1), (-1,-1)") - tk.MustQuery("select * from t1 where ( `col_float_key_signed` % `col_float_key_signed`) IS FALSE").Sort().Check(testkit.Rows("-1 -1", "3 1")) - tk.MustQuery("select `col_float_key_signed` , `col_float_key_signed` % `col_float_key_signed` from t1").Sort().Check(testkit.Rows( - "-1 -0", "0 ", "0 ", "1 0", " ")) - tk.MustQuery("select `col_float_key_signed` , (`col_float_key_signed` % `col_float_key_signed`) IS FALSE from t1").Sort().Check(testkit.Rows( - "-1 1", "0 0", "0 0", "1 1", " 0")) -} - -func (s *testIntegrationSerialSuite) TestIssue17063(c *C) { - collate.SetNewCollationEnabledForTest(true) - defer collate.SetNewCollationEnabledForTest(false) - - tk := testkit.NewTestKit(c, s.store) - tk.MustExec(`use test;`) - tk.MustExec(`drop table if exists t;`) - tk.MustExec("create table t(a char, b char) collate utf8mb4_general_ci;") - tk.MustExec(`insert into t values('a', 'b');`) - tk.MustExec(`insert into t values('a', 'B');`) - tk.MustQuery(`select * from t where if(a='x', a, b) = 'b';`).Check(testkit.Rows("a b", "a B")) - tk.MustQuery(`select collation(if(a='x', a, b)) from t;`).Check(testkit.Rows("utf8mb4_general_ci", "utf8mb4_general_ci")) - tk.MustQuery(`select coercibility(if(a='x', a, b)) from t;`).Check(testkit.Rows("2", "2")) - tk.MustQuery(`select collation(lag(b, 1, 'B') over w) from t window w as (order by b);`).Check(testkit.Rows("utf8mb4_general_ci", "utf8mb4_general_ci")) - tk.MustQuery(`select coercibility(lag(b, 1, 'B') over w) from t window w as (order by b);`).Check(testkit.Rows("2", "2")) -} - func (s *testIntegrationSerialSuite) TestIssue11177(c *C) { collate.SetNewCollationEnabledForTest(true) defer collate.SetNewCollationEnabledForTest(false) @@ -5374,26 +5221,7 @@ func (s *testIntegrationSerialSuite) TestIssue11177(c *C) { tk.MustQuery("show warnings;").Check(testkit.Rows()) } -func (s *testIntegrationSuite) TestIssue19504(c *C) { - tk := testkit.NewTestKit(c, s.store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1;") - tk.MustExec("create table t1 (c_int int, primary key (c_int));") - tk.MustExec("insert into t1 values (1), (2), (3);") - tk.MustExec("drop table if exists t2;") - tk.MustExec("create table t2 (c_int int, primary key (c_int));") - tk.MustExec("insert into t2 values (1);") - tk.MustQuery("select (select count(c_int) from t2 where c_int = t1.c_int) c1, (select count(1) from t2 where c_int = t1.c_int) c2 from t1;"). - Check(testkit.Rows("1 1", "0 0", "0 0")) - tk.MustQuery("select (select count(c_int*c_int) from t2 where c_int = t1.c_int) c1, (select count(1) from t2 where c_int = t1.c_int) c2 from t1;"). - Check(testkit.Rows("1 1", "0 0", "0 0")) -} - -func (s *testIntegrationSerialSuite) TestIssue19804(c *C) { - collate.SetNewCollationEnabledForTest(true) - defer collate.SetNewCollationEnabledForTest(false) - ->>>>>>> 1df810744... planner: fix invalid convert type in between...and... (#19820) +func (s *testIntegrationSuite) TestIssue19804(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec(`use test;`) tk.MustExec(`drop table if exists t;`) From 52b904ed5c3091a54742a98ab56b7a1190fc6dd5 Mon Sep 17 00:00:00 2001 From: xiongjiwei Date: Thu, 10 Dec 2020 15:54:47 +0800 Subject: [PATCH 3/4] Update integration_test.go --- expression/integration_test.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index 3490ca896da8a..bc8c70b6be6b8 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -5206,10 +5206,7 @@ func (s *testIntegrationSuite) TestIssue18850(c *C) { tk.MustQuery("select /*+ HASH_JOIN(t, t1) */ * from t join t1 on t.b = t1.b1;").Check(testkit.Rows("1 A 1 A")) } -func (s *testIntegrationSerialSuite) TestIssue11177(c *C) { - collate.SetNewCollationEnabledForTest(true) - defer collate.SetNewCollationEnabledForTest(false) - +func (s *testIntegrationSuite) TestIssue11177(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustQuery("SELECT 'lvuleck' BETWEEN '2008-09-16 22:23:50' AND 0;").Check(testkit.Rows("0")) tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1292 Truncated incorrect FLOAT value: 'lvuleck'", "Warning 1292 Truncated incorrect FLOAT value: '2008-09-16 22:23:50'")) From db05d01e3beb581a113f66df5ccf8ce8d8427d8a Mon Sep 17 00:00:00 2001 From: xiongjiwei Date: Thu, 10 Dec 2020 16:23:41 +0800 Subject: [PATCH 4/4] Update integration_test.go --- expression/integration_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index bc8c70b6be6b8..e3546be98418c 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -5209,9 +5209,9 @@ func (s *testIntegrationSuite) TestIssue18850(c *C) { func (s *testIntegrationSuite) TestIssue11177(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustQuery("SELECT 'lvuleck' BETWEEN '2008-09-16 22:23:50' AND 0;").Check(testkit.Rows("0")) - tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1292 Truncated incorrect FLOAT value: 'lvuleck'", "Warning 1292 Truncated incorrect FLOAT value: '2008-09-16 22:23:50'")) + tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1265 Data Truncated", "Warning 1265 Data Truncated")) tk.MustQuery("SELECT 'aa' BETWEEN 'bb' AND 0;").Check(testkit.Rows("1")) - tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1292 Truncated incorrect FLOAT value: 'aa'", "Warning 1292 Truncated incorrect FLOAT value: 'bb'")) + tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1265 Data Truncated", "Warning 1265 Data Truncated")) tk.MustQuery("select 1 between 0 and b'110';").Check(testkit.Rows("1")) tk.MustQuery("show warnings;").Check(testkit.Rows()) tk.MustQuery("select 'b' between 'a' and b'110';").Check(testkit.Rows("0"))