From 09122fabbc10aff96a331aaf49c0709ae42c1abf Mon Sep 17 00:00:00 2001 From: wjHuang Date: Tue, 1 Dec 2020 14:08:41 +0800 Subject: [PATCH 1/4] cherry pick #21379 to release-4.0 Signed-off-by: ti-srebot --- expression/integration_test.go | 260 +++++++++++++++++++++++++++++++++ statistics/histogram.go | 12 +- 2 files changed, 262 insertions(+), 10 deletions(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index 2251c105a7a8f..5014f070fb865 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -7318,3 +7318,263 @@ func (s *testIntegrationSerialSuite) TestCollationIndexJoin(c *C) { tk.MustQuery("select /*+ inl_merge_join(t2) */ t1.b, t2.b from t1 join t2 where t1.b=t2.b").Check(testkit.Rows("a A")) tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1815 Optimizer Hint /*+ INL_MERGE_JOIN(t2) */ is inapplicable")) } +<<<<<<< HEAD +======= + +func (s *testIntegrationSuite) TestIssue19892(c *C) { + defer s.cleanEnv(c) + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("USE test") + tk.MustExec("CREATE TABLE dd(a date, b datetime, c timestamp)") + + // check NO_ZERO_DATE + { + tk.MustExec("SET sql_mode=''") + { + tk.MustExec("TRUNCATE TABLE dd") + tk.MustExec("INSERT INTO dd(a) values('0000-00-00')") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) + tk.MustQuery("SELECT a FROM dd").Check(testkit.Rows("0000-00-00")) + + tk.MustExec("TRUNCATE TABLE dd") + tk.MustExec("INSERT INTO dd(b) values('2000-10-01')") + tk.MustExec("UPDATE dd SET b = '0000-00-00'") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) + tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) + + tk.MustExec("TRUNCATE TABLE dd") + tk.MustExec("INSERT INTO dd(c) values('0000-00-00 20:00:00')") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect timestamp value: '0000-00-00 20:00:00'")) + tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) + + tk.MustExec("TRUNCATE TABLE dd") + tk.MustExec("INSERT INTO dd(c) values('2000-10-01 20:00:00')") + tk.MustExec("UPDATE dd SET c = '0000-00-00 20:00:00'") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect timestamp value: '0000-00-00 20:00:00'")) + tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) + } + + tk.MustExec("SET sql_mode='NO_ZERO_DATE'") + { + tk.MustExec("TRUNCATE TABLE dd") + tk.MustExec("INSERT INTO dd(b) values('0000-0-00')") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect datetime value: '0000-0-00'")) + tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) + + tk.MustExec("TRUNCATE TABLE dd") + tk.MustExec("INSERT INTO dd(a) values('2000-10-01')") + tk.MustExec("UPDATE dd SET a = '0000-00-00'") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect date value: '0000-00-00'")) + tk.MustQuery("SELECT a FROM dd").Check(testkit.Rows("0000-00-00")) + + tk.MustExec("TRUNCATE TABLE dd") + tk.MustExec("INSERT INTO dd(c) values('2000-10-01 10:00:00')") + tk.MustExec("UPDATE dd SET c = '0000-00-00 10:00:00'") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect timestamp value: '0000-00-00 10:00:00'")) + tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) + } + + tk.MustExec("SET sql_mode='NO_ZERO_DATE,STRICT_TRANS_TABLES'") + { + tk.MustExec("TRUNCATE TABLE dd") + tk.MustGetErrMsg("INSERT INTO dd(c) VALUES ('0000-00-00 20:00:00')", "[table:1292]Incorrect timestamp value: '0000-00-00 20:00:00' for column 'c' at row 1") + tk.MustExec("INSERT IGNORE INTO dd(c) VALUES ('0000-00-00 20:00:00')") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect timestamp value: '0000-00-00 20:00:00'")) + tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) + + tk.MustExec("TRUNCATE TABLE dd") + tk.MustExec("INSERT INTO dd(b) values('2000-10-01')") + tk.MustGetErrMsg("UPDATE dd SET b = '0000-00-00'", "[types:1292]Incorrect datetime value: '0000-00-00'") + tk.MustExec("UPDATE IGNORE dd SET b = '0000-00-00'") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect datetime value: '0000-00-00'")) + tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) + + tk.MustExec("TRUNCATE TABLE dd") + tk.MustExec("INSERT INTO dd(c) values('2000-10-01 10:00:00')") + tk.MustGetErrMsg("UPDATE dd SET c = '0000-00-00 00:00:00'", "[types:1292]Incorrect timestamp value: '0000-00-00 00:00:00'") + tk.MustExec("UPDATE IGNORE dd SET c = '0000-00-00 00:00:00'") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect timestamp value: '0000-00-00 00:00:00'")) + tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) + } + } + + // check NO_ZERO_IN_DATE + { + tk.MustExec("SET sql_mode=''") + { + tk.MustExec("TRUNCATE TABLE dd") + tk.MustExec("INSERT INTO dd(a) values('2000-01-00')") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) + tk.MustQuery("SELECT a FROM dd").Check(testkit.Rows("2000-01-00")) + tk.MustExec("INSERT INTO dd(a) values('2000-00-01')") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) + tk.MustQuery("SELECT a FROM dd").Check(testkit.Rows("2000-01-00", "2000-00-01")) + tk.MustExec("INSERT INTO dd(a) values('0-01-02')") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) + tk.MustQuery("SELECT a FROM dd").Check(testkit.Rows("2000-01-00", "2000-00-01", "0000-01-02")) + + tk.MustExec("TRUNCATE TABLE dd") + tk.MustExec("INSERT INTO dd(b) values('2000-01-02')") + tk.MustExec("UPDATE dd SET b = '2000-00-02'") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) + tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("2000-00-02 00:00:00")) + + tk.MustExec("TRUNCATE TABLE dd") + tk.MustExec("INSERT INTO dd(c) values('2000-01-02 20:00:00')") + tk.MustExec("UPDATE dd SET c = '0000-01-02 20:00:00'") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect timestamp value: '0000-01-02 20:00:00'")) + tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) + } + + tk.MustExec("SET sql_mode='NO_ZERO_IN_DATE'") + { + tk.MustExec("TRUNCATE TABLE dd") + tk.MustExec("INSERT INTO dd(a) values('2000-01-00')") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect date value: '2000-01-00'")) + tk.MustQuery("SELECT a FROM dd").Check(testkit.Rows("0000-00-00")) + + tk.MustExec("TRUNCATE TABLE dd") + tk.MustExec("INSERT INTO dd(a) values('2000-01-02')") + tk.MustExec("UPDATE dd SET a = '2000-00-02'") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect date value: '2000-00-02'")) + tk.MustQuery("SELECT a FROM dd").Check(testkit.Rows("0000-00-00")) + tk.MustExec("UPDATE dd SET b = '2000-01-0'") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect datetime value: '2000-01-0'")) + tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) + // consistent with Mysql8 + tk.MustExec("UPDATE dd SET b = '0-01-02'") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) + tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-01-02 00:00:00")) + + tk.MustExec("TRUNCATE TABLE dd") + tk.MustExec("INSERT INTO dd(c) values('2000-01-02 20:00:00')") + tk.MustExec("UPDATE dd SET c = '2000-00-02 20:00:00'") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect timestamp value: '2000-00-02 20:00:00'")) + tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) + } + + tk.MustExec("SET sql_mode='NO_ZERO_IN_DATE,STRICT_TRANS_TABLES'") + { + tk.MustExec("TRUNCATE TABLE dd") + tk.MustGetErrMsg("INSERT INTO dd(b) VALUES ('2000-01-00')", "[table:1292]Incorrect datetime value: '2000-01-00' for column 'b' at row 1") + tk.MustExec("INSERT IGNORE INTO dd(b) VALUES ('2000-00-01')") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect datetime value: '2000-00-01'")) + tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) + + tk.MustExec("TRUNCATE TABLE dd") + tk.MustExec("INSERT INTO dd(b) VALUES ('2000-01-02')") + tk.MustGetErrMsg("UPDATE dd SET b = '2000-01-00'", "[types:1292]Incorrect datetime value: '2000-01-00'") + tk.MustExec("UPDATE IGNORE dd SET b = '2000-01-0'") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect datetime value: '2000-01-0'")) + tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) + tk.MustExec("UPDATE dd SET b = '0000-1-2'") + tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-01-02 00:00:00")) + tk.MustGetErrMsg("UPDATE dd SET c = '0000-01-05'", "[types:1292]Incorrect timestamp value: '0000-01-05'") + tk.MustExec("UPDATE IGNORE dd SET c = '0000-01-5'") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect timestamp value: '0000-01-5'")) + tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) + + tk.MustExec("TRUNCATE TABLE dd") + tk.MustGetErrMsg("INSERT INTO dd(c) VALUES ('2000-01-00 20:00:00')", "[table:1292]Incorrect timestamp value: '2000-01-00 20:00:00' for column 'c' at row 1") + tk.MustExec("INSERT INTO dd(c) VALUES ('2000-01-02')") + tk.MustGetErrMsg("UPDATE dd SET c = '2000-01-00 20:00:00'", "[types:1292]Incorrect timestamp value: '2000-01-00 20:00:00'") + tk.MustExec("UPDATE IGNORE dd SET b = '2000-01-00'") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect datetime value: '2000-01-00'")) + tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) + } + } + + // check !NO_ZERO_DATE + tk.MustExec("SET sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'") + { + tk.MustExec("TRUNCATE TABLE dd") + tk.MustExec("INSERT INTO dd(a) values('0000-00-00')") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) + tk.MustQuery("SELECT a FROM dd").Check(testkit.Rows("0000-00-00")) + + tk.MustExec("TRUNCATE TABLE dd") + tk.MustExec("INSERT INTO dd(b) values('2000-10-01')") + tk.MustExec("UPDATE dd SET b = '0000-00-00'") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) + tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) + + tk.MustExec("TRUNCATE TABLE dd") + tk.MustExec("INSERT INTO dd(c) values('0000-00-00 00:00:00')") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) + + tk.MustExec("TRUNCATE TABLE dd") + tk.MustExec("INSERT INTO dd(c) values('2000-10-01 10:00:00')") + tk.MustExec("UPDATE dd SET c = '0000-00-00 00:00:00'") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) + tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) + + tk.MustExec("TRUNCATE TABLE dd") + tk.MustGetErrMsg("INSERT INTO dd(b) VALUES ('2000-01-00')", "[table:1292]Incorrect datetime value: '2000-01-00' for column 'b' at row 1") + tk.MustExec("INSERT IGNORE INTO dd(b) VALUES ('2000-00-01')") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect datetime value: '2000-00-01'")) + tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) + + tk.MustExec("TRUNCATE TABLE dd") + tk.MustExec("INSERT INTO dd(b) VALUES ('2000-01-02')") + tk.MustGetErrMsg("UPDATE dd SET b = '2000-01-00'", "[types:1292]Incorrect datetime value: '2000-01-00'") + tk.MustExec("UPDATE IGNORE dd SET b = '2000-01-0'") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect datetime value: '2000-01-0'")) + tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) + tk.MustExec("UPDATE dd SET b = '0000-1-2'") + tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-01-02 00:00:00")) + tk.MustGetErrMsg("UPDATE dd SET c = '0000-01-05'", "[types:1292]Incorrect timestamp value: '0000-01-05'") + tk.MustExec("UPDATE IGNORE dd SET c = '0000-01-5'") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect timestamp value: '0000-01-5'")) + tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) + + tk.MustExec("TRUNCATE TABLE dd") + tk.MustGetErrMsg("INSERT INTO dd(c) VALUES ('2000-01-00 20:00:00')", "[table:1292]Incorrect timestamp value: '2000-01-00 20:00:00' for column 'c' at row 1") + tk.MustExec("INSERT INTO dd(c) VALUES ('2000-01-02')") + tk.MustGetErrMsg("UPDATE dd SET c = '2000-01-00 20:00:00'", "[types:1292]Incorrect timestamp value: '2000-01-00 20:00:00'") + tk.MustExec("UPDATE IGNORE dd SET b = '2000-01-00'") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect datetime value: '2000-01-00'")) + tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) + } + + // check !NO_ZERO_IN_DATE + tk.MustExec("SET sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'") + { + tk.MustExec("TRUNCATE TABLE dd") + tk.MustExec("INSERT INTO dd(a) values('2000-00-10')") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) + tk.MustQuery("SELECT a FROM dd").Check(testkit.Rows("2000-00-10")) + + tk.MustExec("TRUNCATE TABLE dd") + tk.MustExec("INSERT INTO dd(b) values('2000-10-01')") + tk.MustExec("UPDATE dd SET b = '2000-00-10'") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) + tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("2000-00-10 00:00:00")) + + tk.MustExec("TRUNCATE TABLE dd") + tk.MustExec("INSERT INTO dd(c) values('2000-10-01 10:00:00')") + tk.MustGetErrMsg("UPDATE dd SET c = '2000-00-10 00:00:00'", "[types:1292]Incorrect timestamp value: '2000-00-10 00:00:00'") + tk.MustExec("UPDATE IGNORE dd SET c = '2000-01-00 00:00:00'") + tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect timestamp value: '2000-01-00 00:00:00'")) + tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) + } +} + +func (s *testIntegrationSerialSuite) TestIssue20876(c *C) { + collate.SetNewCollationEnabledForTest(true) + defer collate.SetNewCollationEnabledForTest(false) + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("set @@tidb_enable_clustered_index=1;") + tk.MustExec("use test") + tk.MustExec("drop table if exists t;") + tk.MustExec("CREATE TABLE `t` (" + + " `a` char(10) COLLATE utf8mb4_unicode_ci NOT NULL," + + " `b` char(20) COLLATE utf8mb4_general_ci NOT NULL," + + " `c` int(11) NOT NULL," + + " PRIMARY KEY (`a`,`b`,`c`)," + + " KEY `idx` (`a`)" + + ")") + tk.MustExec("insert into t values ('#', 'C', 10), ('$', 'c', 20), ('$', 'c', 30), ('a', 'a', 10), ('A', 'A', 30)") + tk.MustExec("analyze table t") + tk.MustQuery("select * from t where a='#';").Check(testkit.Rows("# C 10")) +} +>>>>>>> 5131514eb... statistics: fix a bug which causes panic when using the clustered index and the new collation (#21379) diff --git a/statistics/histogram.go b/statistics/histogram.go index 66e8f9f3f3677..c786c89b7045f 100644 --- a/statistics/histogram.go +++ b/statistics/histogram.go @@ -785,18 +785,10 @@ func (c *Column) GetColumnRowCount(sc *stmtctx.StatementContext, ranges []*range highVal := *rg.HighVal[0].Clone() lowVal := *rg.LowVal[0].Clone() if highVal.Kind() == types.KindString { - highVal.SetBytesAsString(collate.GetCollator( - highVal.Collation()).Key(highVal.GetString()), - highVal.Collation(), - uint32(highVal.Length()), - ) + highVal.SetBytes(collate.GetCollator(highVal.Collation()).Key(highVal.GetString())) } if lowVal.Kind() == types.KindString { - lowVal.SetBytesAsString(collate.GetCollator( - lowVal.Collation()).Key(lowVal.GetString()), - lowVal.Collation(), - uint32(lowVal.Length()), - ) + lowVal.SetBytes(collate.GetCollator(lowVal.Collation()).Key(lowVal.GetString())) } cmp, err := lowVal.CompareDatum(sc, &highVal) if err != nil { From dc31cf6fe736dae71982c5add0e33ca1204c0391 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Thu, 28 Jan 2021 15:07:59 +0800 Subject: [PATCH 2/4] fix CI --- expression/integration_test.go | 238 --------------------------------- 1 file changed, 238 deletions(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index 32a60833b6beb..de0534da1b3f7 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -7591,244 +7591,6 @@ func (s *testIntegrationSerialSuite) TestCollationIndexJoin(c *C) { tk.MustQuery("show warnings").Check(testkit.Rows("Warning 1815 Optimizer Hint /*+ INL_MERGE_JOIN(t2) */ is inapplicable")) } -func (s *testIntegrationSuite) TestIssue19892(c *C) { - defer s.cleanEnv(c) - tk := testkit.NewTestKit(c, s.store) - tk.MustExec("USE test") - tk.MustExec("CREATE TABLE dd(a date, b datetime, c timestamp)") - - // check NO_ZERO_DATE - { - tk.MustExec("SET sql_mode=''") - { - tk.MustExec("TRUNCATE TABLE dd") - tk.MustExec("INSERT INTO dd(a) values('0000-00-00')") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) - tk.MustQuery("SELECT a FROM dd").Check(testkit.Rows("0000-00-00")) - - tk.MustExec("TRUNCATE TABLE dd") - tk.MustExec("INSERT INTO dd(b) values('2000-10-01')") - tk.MustExec("UPDATE dd SET b = '0000-00-00'") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) - tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) - - tk.MustExec("TRUNCATE TABLE dd") - tk.MustExec("INSERT INTO dd(c) values('0000-00-00 20:00:00')") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect timestamp value: '0000-00-00 20:00:00'")) - tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) - - tk.MustExec("TRUNCATE TABLE dd") - tk.MustExec("INSERT INTO dd(c) values('2000-10-01 20:00:00')") - tk.MustExec("UPDATE dd SET c = '0000-00-00 20:00:00'") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect timestamp value: '0000-00-00 20:00:00'")) - tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) - } - - tk.MustExec("SET sql_mode='NO_ZERO_DATE'") - { - tk.MustExec("TRUNCATE TABLE dd") - tk.MustExec("INSERT INTO dd(b) values('0000-0-00')") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect datetime value: '0000-0-00'")) - tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) - - tk.MustExec("TRUNCATE TABLE dd") - tk.MustExec("INSERT INTO dd(a) values('2000-10-01')") - tk.MustExec("UPDATE dd SET a = '0000-00-00'") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect date value: '0000-00-00'")) - tk.MustQuery("SELECT a FROM dd").Check(testkit.Rows("0000-00-00")) - - tk.MustExec("TRUNCATE TABLE dd") - tk.MustExec("INSERT INTO dd(c) values('2000-10-01 10:00:00')") - tk.MustExec("UPDATE dd SET c = '0000-00-00 10:00:00'") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect timestamp value: '0000-00-00 10:00:00'")) - tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) - } - - tk.MustExec("SET sql_mode='NO_ZERO_DATE,STRICT_TRANS_TABLES'") - { - tk.MustExec("TRUNCATE TABLE dd") - tk.MustGetErrMsg("INSERT INTO dd(c) VALUES ('0000-00-00 20:00:00')", "[table:1292]Incorrect timestamp value: '0000-00-00 20:00:00' for column 'c' at row 1") - tk.MustExec("INSERT IGNORE INTO dd(c) VALUES ('0000-00-00 20:00:00')") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect timestamp value: '0000-00-00 20:00:00'")) - tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) - - tk.MustExec("TRUNCATE TABLE dd") - tk.MustExec("INSERT INTO dd(b) values('2000-10-01')") - tk.MustGetErrMsg("UPDATE dd SET b = '0000-00-00'", "[types:1292]Incorrect datetime value: '0000-00-00'") - tk.MustExec("UPDATE IGNORE dd SET b = '0000-00-00'") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect datetime value: '0000-00-00'")) - tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) - - tk.MustExec("TRUNCATE TABLE dd") - tk.MustExec("INSERT INTO dd(c) values('2000-10-01 10:00:00')") - tk.MustGetErrMsg("UPDATE dd SET c = '0000-00-00 00:00:00'", "[types:1292]Incorrect timestamp value: '0000-00-00 00:00:00'") - tk.MustExec("UPDATE IGNORE dd SET c = '0000-00-00 00:00:00'") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect timestamp value: '0000-00-00 00:00:00'")) - tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) - } - } - - // check NO_ZERO_IN_DATE - { - tk.MustExec("SET sql_mode=''") - { - tk.MustExec("TRUNCATE TABLE dd") - tk.MustExec("INSERT INTO dd(a) values('2000-01-00')") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) - tk.MustQuery("SELECT a FROM dd").Check(testkit.Rows("2000-01-00")) - tk.MustExec("INSERT INTO dd(a) values('2000-00-01')") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) - tk.MustQuery("SELECT a FROM dd").Check(testkit.Rows("2000-01-00", "2000-00-01")) - tk.MustExec("INSERT INTO dd(a) values('0-01-02')") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) - tk.MustQuery("SELECT a FROM dd").Check(testkit.Rows("2000-01-00", "2000-00-01", "0000-01-02")) - - tk.MustExec("TRUNCATE TABLE dd") - tk.MustExec("INSERT INTO dd(b) values('2000-01-02')") - tk.MustExec("UPDATE dd SET b = '2000-00-02'") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) - tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("2000-00-02 00:00:00")) - - tk.MustExec("TRUNCATE TABLE dd") - tk.MustExec("INSERT INTO dd(c) values('2000-01-02 20:00:00')") - tk.MustExec("UPDATE dd SET c = '0000-01-02 20:00:00'") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect timestamp value: '0000-01-02 20:00:00'")) - tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) - } - - tk.MustExec("SET sql_mode='NO_ZERO_IN_DATE'") - { - tk.MustExec("TRUNCATE TABLE dd") - tk.MustExec("INSERT INTO dd(a) values('2000-01-00')") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect date value: '2000-01-00'")) - tk.MustQuery("SELECT a FROM dd").Check(testkit.Rows("0000-00-00")) - - tk.MustExec("TRUNCATE TABLE dd") - tk.MustExec("INSERT INTO dd(a) values('2000-01-02')") - tk.MustExec("UPDATE dd SET a = '2000-00-02'") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect date value: '2000-00-02'")) - tk.MustQuery("SELECT a FROM dd").Check(testkit.Rows("0000-00-00")) - tk.MustExec("UPDATE dd SET b = '2000-01-0'") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect datetime value: '2000-01-0'")) - tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) - // consistent with Mysql8 - tk.MustExec("UPDATE dd SET b = '0-01-02'") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) - tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-01-02 00:00:00")) - - tk.MustExec("TRUNCATE TABLE dd") - tk.MustExec("INSERT INTO dd(c) values('2000-01-02 20:00:00')") - tk.MustExec("UPDATE dd SET c = '2000-00-02 20:00:00'") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect timestamp value: '2000-00-02 20:00:00'")) - tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) - } - - tk.MustExec("SET sql_mode='NO_ZERO_IN_DATE,STRICT_TRANS_TABLES'") - { - tk.MustExec("TRUNCATE TABLE dd") - tk.MustGetErrMsg("INSERT INTO dd(b) VALUES ('2000-01-00')", "[table:1292]Incorrect datetime value: '2000-01-00' for column 'b' at row 1") - tk.MustExec("INSERT IGNORE INTO dd(b) VALUES ('2000-00-01')") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect datetime value: '2000-00-01'")) - tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) - - tk.MustExec("TRUNCATE TABLE dd") - tk.MustExec("INSERT INTO dd(b) VALUES ('2000-01-02')") - tk.MustGetErrMsg("UPDATE dd SET b = '2000-01-00'", "[types:1292]Incorrect datetime value: '2000-01-00'") - tk.MustExec("UPDATE IGNORE dd SET b = '2000-01-0'") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect datetime value: '2000-01-0'")) - tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) - tk.MustExec("UPDATE dd SET b = '0000-1-2'") - tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-01-02 00:00:00")) - tk.MustGetErrMsg("UPDATE dd SET c = '0000-01-05'", "[types:1292]Incorrect timestamp value: '0000-01-05'") - tk.MustExec("UPDATE IGNORE dd SET c = '0000-01-5'") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect timestamp value: '0000-01-5'")) - tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) - - tk.MustExec("TRUNCATE TABLE dd") - tk.MustGetErrMsg("INSERT INTO dd(c) VALUES ('2000-01-00 20:00:00')", "[table:1292]Incorrect timestamp value: '2000-01-00 20:00:00' for column 'c' at row 1") - tk.MustExec("INSERT INTO dd(c) VALUES ('2000-01-02')") - tk.MustGetErrMsg("UPDATE dd SET c = '2000-01-00 20:00:00'", "[types:1292]Incorrect timestamp value: '2000-01-00 20:00:00'") - tk.MustExec("UPDATE IGNORE dd SET b = '2000-01-00'") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect datetime value: '2000-01-00'")) - tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) - } - } - - // check !NO_ZERO_DATE - tk.MustExec("SET sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'") - { - tk.MustExec("TRUNCATE TABLE dd") - tk.MustExec("INSERT INTO dd(a) values('0000-00-00')") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) - tk.MustQuery("SELECT a FROM dd").Check(testkit.Rows("0000-00-00")) - - tk.MustExec("TRUNCATE TABLE dd") - tk.MustExec("INSERT INTO dd(b) values('2000-10-01')") - tk.MustExec("UPDATE dd SET b = '0000-00-00'") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) - tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) - - tk.MustExec("TRUNCATE TABLE dd") - tk.MustExec("INSERT INTO dd(c) values('0000-00-00 00:00:00')") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) - - tk.MustExec("TRUNCATE TABLE dd") - tk.MustExec("INSERT INTO dd(c) values('2000-10-01 10:00:00')") - tk.MustExec("UPDATE dd SET c = '0000-00-00 00:00:00'") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) - tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) - - tk.MustExec("TRUNCATE TABLE dd") - tk.MustGetErrMsg("INSERT INTO dd(b) VALUES ('2000-01-00')", "[table:1292]Incorrect datetime value: '2000-01-00' for column 'b' at row 1") - tk.MustExec("INSERT IGNORE INTO dd(b) VALUES ('2000-00-01')") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect datetime value: '2000-00-01'")) - tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) - - tk.MustExec("TRUNCATE TABLE dd") - tk.MustExec("INSERT INTO dd(b) VALUES ('2000-01-02')") - tk.MustGetErrMsg("UPDATE dd SET b = '2000-01-00'", "[types:1292]Incorrect datetime value: '2000-01-00'") - tk.MustExec("UPDATE IGNORE dd SET b = '2000-01-0'") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect datetime value: '2000-01-0'")) - tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) - tk.MustExec("UPDATE dd SET b = '0000-1-2'") - tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-01-02 00:00:00")) - tk.MustGetErrMsg("UPDATE dd SET c = '0000-01-05'", "[types:1292]Incorrect timestamp value: '0000-01-05'") - tk.MustExec("UPDATE IGNORE dd SET c = '0000-01-5'") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect timestamp value: '0000-01-5'")) - tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) - - tk.MustExec("TRUNCATE TABLE dd") - tk.MustGetErrMsg("INSERT INTO dd(c) VALUES ('2000-01-00 20:00:00')", "[table:1292]Incorrect timestamp value: '2000-01-00 20:00:00' for column 'c' at row 1") - tk.MustExec("INSERT INTO dd(c) VALUES ('2000-01-02')") - tk.MustGetErrMsg("UPDATE dd SET c = '2000-01-00 20:00:00'", "[types:1292]Incorrect timestamp value: '2000-01-00 20:00:00'") - tk.MustExec("UPDATE IGNORE dd SET b = '2000-01-00'") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect datetime value: '2000-01-00'")) - tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) - } - - // check !NO_ZERO_IN_DATE - tk.MustExec("SET sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'") - { - tk.MustExec("TRUNCATE TABLE dd") - tk.MustExec("INSERT INTO dd(a) values('2000-00-10')") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) - tk.MustQuery("SELECT a FROM dd").Check(testkit.Rows("2000-00-10")) - - tk.MustExec("TRUNCATE TABLE dd") - tk.MustExec("INSERT INTO dd(b) values('2000-10-01')") - tk.MustExec("UPDATE dd SET b = '2000-00-10'") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows()) - tk.MustQuery("SELECT b FROM dd").Check(testkit.Rows("2000-00-10 00:00:00")) - - tk.MustExec("TRUNCATE TABLE dd") - tk.MustExec("INSERT INTO dd(c) values('2000-10-01 10:00:00')") - tk.MustGetErrMsg("UPDATE dd SET c = '2000-00-10 00:00:00'", "[types:1292]Incorrect timestamp value: '2000-00-10 00:00:00'") - tk.MustExec("UPDATE IGNORE dd SET c = '2000-01-00 00:00:00'") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect timestamp value: '2000-01-00 00:00:00'")) - tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) - } -} - func (s *testIntegrationSerialSuite) TestIssue20876(c *C) { collate.SetNewCollationEnabledForTest(true) defer collate.SetNewCollationEnabledForTest(false) From f3ceda03c8b4581d9c3c2a5c9a508d2806e22199 Mon Sep 17 00:00:00 2001 From: wjHuang Date: Fri, 16 Apr 2021 14:16:50 +0800 Subject: [PATCH 3/4] Update integration_test.go --- expression/integration_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/expression/integration_test.go b/expression/integration_test.go index 692821120185f..d387160e336bb 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -8002,6 +8002,7 @@ func (s *testIntegrationSuite) TestIssue19892(c *C) { tk.MustExec("UPDATE IGNORE dd SET c = '2000-01-00 00:00:00'") tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Incorrect timestamp value: '2000-01-00 00:00:00'")) tk.MustQuery("SELECT c FROM dd").Check(testkit.Rows("0000-00-00 00:00:00")) + } } func (s *testIntegrationSuite2) TestCastCoer(c *C) { From c3106440c9aa1bb5446bb8c950459a8770eec18f Mon Sep 17 00:00:00 2001 From: wjHuang Date: Fri, 16 Apr 2021 14:48:49 +0800 Subject: [PATCH 4/4] Update integration_test.go --- expression/integration_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/expression/integration_test.go b/expression/integration_test.go index d387160e336bb..166ff656d8d74 100755 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -7752,7 +7752,6 @@ func (s *testIntegrationSerialSuite) TestIssue20876(c *C) { collate.SetNewCollationEnabledForTest(true) defer collate.SetNewCollationEnabledForTest(false) tk := testkit.NewTestKit(c, s.store) - tk.MustExec("set @@tidb_enable_clustered_index=1;") tk.MustExec("use test") tk.MustExec("drop table if exists t;") tk.MustExec("CREATE TABLE `t` (" +