diff --git a/expression/integration_serial_test/BUILD.bazel b/expression/integration_serial_test/BUILD.bazel deleted file mode 100644 index 0ba73c9a2fbf7..0000000000000 --- a/expression/integration_serial_test/BUILD.bazel +++ /dev/null @@ -1,31 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_test") - -go_test( - name = "integration_serial_test_test", - timeout = "short", - srcs = [ - "integration_serial_test.go", - "main_test.go", - ], - flaky = True, - shard_count = 12, - deps = [ - "//config", - "//expression", - "//parser/terror", - "//planner/core", - "//session", - "//sessionctx/variable", - "//testkit", - "//testkit/testmain", - "//testkit/testsetup", - "//types", - "//util/timeutil", - "@com_github_pingcap_errors//:errors", - "@com_github_pingcap_failpoint//:failpoint", - "@com_github_stretchr_testify//require", - "@com_github_tikv_client_go_v2//oracle", - "@com_github_tikv_client_go_v2//tikv", - "@org_uber_go_goleak//:goleak", - ], -) diff --git a/expression/integration_serial_test/README.md b/expression/integration_serial_test/README.md deleted file mode 100644 index 78311d5ff7292..0000000000000 --- a/expression/integration_serial_test/README.md +++ /dev/null @@ -1,3 +0,0 @@ -Too many test case in this package. - -Please not add new test cases in this package. diff --git a/expression/integration_serial_test/integration_serial_test.go b/expression/integration_serial_test/integration_serial_test.go deleted file mode 100644 index b834e5a30ecd8..0000000000000 --- a/expression/integration_serial_test/integration_serial_test.go +++ /dev/null @@ -1,1714 +0,0 @@ -// Copyright 2022 PingCAP, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package integration_serial_test - -import ( - "context" - "encoding/binary" - "fmt" - "hash/crc32" - "math" - "strings" - "testing" - "time" - - "github.com/pingcap/errors" - "github.com/pingcap/failpoint" - "github.com/pingcap/tidb/expression" - "github.com/pingcap/tidb/parser/terror" - plannercore "github.com/pingcap/tidb/planner/core" - "github.com/pingcap/tidb/session" - "github.com/pingcap/tidb/sessionctx/variable" - "github.com/pingcap/tidb/testkit" - "github.com/pingcap/tidb/types" - "github.com/stretchr/testify/require" - "github.com/tikv/client-go/v2/oracle" -) - -func TestTimeBuiltin(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - originSQLMode := tk.Session().GetSessionVars().StrictSQLMode - tk.Session().GetSessionVars().StrictSQLMode = true - defer func() { - tk.Session().GetSessionVars().StrictSQLMode = originSQLMode - }() - tk.MustExec("use test") - - // for makeDate - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int, b double, c datetime, d time, e char(20), f bit(10))") - tk.MustExec(`insert into t values(1, 1.1, "2017-01-01 12:01:01", "12:01:01", "abcdef", 0b10101)`) - result := tk.MustQuery("select makedate(a,a), makedate(b,b), makedate(c,c), makedate(d,d), makedate(e,e), makedate(f,f), makedate(null,null), makedate(a,b) from t") - result.Check(testkit.Rows("2001-01-01 2001-01-01 2021-01-21 2001-01-01")) - - // for date - result = tk.MustQuery(`select date("2019-09-12"), date("2019-09-12 12:12:09"), date("2019-09-12 12:12:09.121212");`) - result.Check(testkit.Rows("2019-09-12 2019-09-12 2019-09-12")) - result = tk.MustQuery(`select date("0000-00-00"), date("0000-00-00 12:12:09"), date("0000-00-00 00:00:00.121212"), date("0000-00-00 00:00:00.000000");`) - result.Check(testkit.Rows(" 0000-00-00 0000-00-00 ")) - result = tk.MustQuery(`select date("aa"), date(12.1), date("");`) - result.Check(testkit.Rows(" ")) - - // for year - result = tk.MustQuery(`select year("2013-01-09"), year("2013-00-09"), year("000-01-09"), year("1-01-09"), year("20131-01-09"), year(null);`) - result.Check(testkit.Rows("2013 2013 0 2001 ")) - result = tk.MustQuery(`select year("2013-00-00"), year("2013-00-00 00:00:00"), year("0000-00-00 12:12:12"), year("2017-00-00 12:12:12");`) - result.Check(testkit.Rows("2013 2013 0 2017")) - result = tk.MustQuery(`select year("aa"), year(2013), year(2012.09), year("1-01"), year("-09");`) - result.Check(testkit.Rows(" ")) - tk.MustExec(`drop table if exists t`) - tk.MustExec(`create table t(a bigint)`) - _, err := tk.Exec(`insert into t select year("aa")`) - require.Error(t, err) - require.True(t, terror.ErrorEqual(err, types.ErrWrongValue), "err %v", err) - tk.MustExec(`set sql_mode='STRICT_TRANS_TABLES'`) // without zero date - tk.MustExec(`insert into t select year("0000-00-00 00:00:00")`) - tk.MustExec(`set sql_mode="NO_ZERO_DATE";`) // with zero date - tk.MustExec(`insert into t select year("0000-00-00 00:00:00")`) - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1292|Incorrect datetime value: '0000-00-00 00:00:00.000000'")) - tk.MustExec(`set sql_mode="NO_ZERO_DATE,STRICT_TRANS_TABLES";`) - _, err = tk.Exec(`insert into t select year("0000-00-00 00:00:00");`) - require.Error(t, err) - require.True(t, types.ErrWrongValue.Equal(err), "err %v", err) - - tk.MustExec(`insert into t select 1`) - tk.MustExec(`set sql_mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION";`) - _, err = tk.Exec(`update t set a = year("aa")`) - require.True(t, terror.ErrorEqual(err, types.ErrWrongValue), "err %v", err) - _, err = tk.Exec(`delete from t where a = year("aa")`) - // Only `code` can be used to compare because the error `class` information - // will be lost after expression push-down - require.Equal(t, types.ErrWrongValue.Code(), errors.Cause(err).(*terror.Error).Code(), "err %v", err) - - // for month - result = tk.MustQuery(`select month("2013-01-09"), month("2013-00-09"), month("000-01-09"), month("1-01-09"), month("20131-01-09"), month(null);`) - result.Check(testkit.Rows("1 0 1 1 ")) - result = tk.MustQuery(`select month("2013-00-00"), month("2013-00-00 00:00:00"), month("0000-00-00 12:12:12"), month("2017-00-00 12:12:12");`) - result.Check(testkit.Rows("0 0 0 0")) - result = tk.MustQuery(`select month("aa"), month(2013), month(2012.09), month("1-01"), month("-09");`) - result.Check(testkit.Rows(" ")) - result = tk.MustQuery(`select month("2013-012-09"), month("2013-0000000012-09"), month("2013-30-09"), month("000-41-09");`) - result.Check(testkit.Rows("12 12 ")) - tk.MustExec(`drop table if exists t`) - tk.MustExec(`create table t(a bigint)`) - _, err = tk.Exec(`insert into t select month("aa")`) - require.Error(t, err) - require.True(t, terror.ErrorEqual(err, types.ErrWrongValue), "err: %v", err) - tk.MustExec(`insert into t select month("0000-00-00 00:00:00")`) - tk.MustExec(`set sql_mode="NO_ZERO_DATE";`) - tk.MustExec(`insert into t select month("0000-00-00 00:00:00")`) - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1292|Incorrect datetime value: '0000-00-00 00:00:00.000000'")) - tk.MustExec(`set sql_mode="NO_ZERO_DATE,STRICT_TRANS_TABLES";`) - _, err = tk.Exec(`insert into t select month("0000-00-00 00:00:00");`) - require.Error(t, err) - require.True(t, types.ErrWrongValue.Equal(err), "err: %v", err) - tk.MustExec(`insert into t select 1`) - tk.MustExec(`set sql_mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION";`) - tk.MustExec(`insert into t select 1`) - _, err = tk.Exec(`update t set a = month("aa")`) - require.True(t, terror.ErrorEqual(err, types.ErrWrongValue)) - _, err = tk.Exec(`delete from t where a = month("aa")`) - require.Equal(t, types.ErrWrongValue.Code(), errors.Cause(err).(*terror.Error).Code(), "err %v", err) - - // for week - result = tk.MustQuery(`select week("2012-12-22"), week("2012-12-22", -2), week("2012-12-22", 0), week("2012-12-22", 1), week("2012-12-22", 2), week("2012-12-22", 200);`) - result.Check(testkit.Rows("51 51 51 51 51 51")) - result = tk.MustQuery(`select week("2008-02-20"), week("2008-02-20", 0), week("2008-02-20", 1), week("2009-02-20", 2), week("2008-02-20", 3), week("2008-02-20", 4);`) - result.Check(testkit.Rows("7 7 8 7 8 8")) - result = tk.MustQuery(`select week("2008-02-20", 5), week("2008-02-20", 6), week("2009-02-20", 7), week("2008-02-20", 8), week("2008-02-20", 9);`) - result.Check(testkit.Rows("7 8 7 7 8")) - result = tk.MustQuery(`select week("aa", 1), week(null, 2), week(11, 2), week(12.99, 2);`) - result.Check(testkit.Rows(" ")) - result = tk.MustQuery(`select week("aa"), week(null), week(11), week(12.99);`) - result.Check(testkit.Rows(" ")) - tk.MustExec(`drop table if exists t`) - tk.MustExec(`create table t(a datetime)`) - _, err = tk.Exec(`insert into t select week("aa", 1)`) - require.Error(t, err) - require.True(t, terror.ErrorEqual(err, types.ErrWrongValue)) - tk.MustExec(`insert into t select now()`) - _, err = tk.Exec(`update t set a = week("aa", 1)`) - require.True(t, terror.ErrorEqual(err, types.ErrWrongValue)) - _, err = tk.Exec(`delete from t where a = week("aa", 1)`) - require.Equal(t, types.ErrWrongValue.Code(), errors.Cause(err).(*terror.Error).Code(), "err %v", err) - - // for weekofyear - result = tk.MustQuery(`select weekofyear("2012-12-22"), weekofyear("2008-02-20"), weekofyear("aa"), weekofyear(null), weekofyear(11), weekofyear(12.99);`) - result.Check(testkit.Rows("51 8 ")) - tk.MustExec(`drop table if exists t`) - tk.MustExec(`create table t(a bigint)`) - _, err = tk.Exec(`insert into t select weekofyear("aa")`) - require.Error(t, err) - require.True(t, terror.ErrorEqual(err, types.ErrWrongValue)) - - tk.MustExec(`insert into t select 1`) - _, err = tk.Exec(`update t set a = weekofyear("aa")`) - require.True(t, terror.ErrorEqual(err, types.ErrWrongValue)) - _, err = tk.Exec(`delete from t where a = weekofyear("aa")`) - require.Equal(t, types.ErrWrongValue.Code(), errors.Cause(err).(*terror.Error).Code(), "err %v", err) - - // for weekday - result = tk.MustQuery(`select weekday("2012-12-20"), weekday("2012-12-21"), weekday("2012-12-22"), weekday("2012-12-23"), weekday("2012-12-24"), weekday("2012-12-25"), weekday("2012-12-26"), weekday("2012-12-27");`) - result.Check(testkit.Rows("3 4 5 6 0 1 2 3")) - result = tk.MustQuery(`select weekday("2012-12-90"), weekday("0000-00-00"), weekday("aa"), weekday(null), weekday(11), weekday(12.99);`) - result.Check(testkit.Rows(" ")) - - // for quarter - result = tk.MustQuery(`select quarter("2012-00-20"), quarter("2012-01-21"), quarter("2012-03-22"), quarter("2012-05-23"), quarter("2012-08-24"), quarter("2012-09-25"), quarter("2012-11-26"), quarter("2012-12-27");`) - result.Check(testkit.Rows("0 1 1 2 3 3 4 4")) - result = tk.MustQuery(`select quarter("2012-14-20"), quarter("aa"), quarter(null), quarter(11), quarter(12.99);`) - result.Check(testkit.Rows(" ")) - result = tk.MustQuery(`select quarter("0000-00-00"), quarter("0000-00-00 00:00:00");`) - result.Check(testkit.Rows("0 0")) - tk.MustQuery("show warnings").Check(testkit.Rows()) - result = tk.MustQuery(`select quarter(0), quarter(0.0), quarter(0e1), quarter(0.00);`) - result.Check(testkit.Rows("0 0 0 0")) - tk.MustQuery("show warnings").Check(testkit.Rows()) - - // for from_days - result = tk.MustQuery(`select from_days(0), from_days(-199), from_days(1111), from_days(120), from_days(1), from_days(1111111), from_days(9999999), from_days(22222);`) - result.Check(testkit.Rows("0000-00-00 0000-00-00 0003-01-16 0000-00-00 0000-00-00 3042-02-13 0000-00-00 0060-11-03")) - result = tk.MustQuery(`select from_days("2012-14-20"), from_days("111a"), from_days("aa"), from_days(null), from_days("123asf"), from_days(12.99);`) - result.Check(testkit.Rows("0005-07-05 0000-00-00 0000-00-00 0000-00-00 0000-00-00")) - - // Fix issue #3923 - result = tk.MustQuery("select timediff(cast('2004-12-30 12:00:00' as time), '12:00:00');") - result.Check(testkit.Rows("00:00:00")) - result = tk.MustQuery("select timediff('12:00:00', cast('2004-12-30 12:00:00' as time));") - result.Check(testkit.Rows("00:00:00")) - result = tk.MustQuery("select timediff(cast('2004-12-30 12:00:00' as time), '2004-12-30 12:00:00');") - result.Check(testkit.Rows("")) - result = tk.MustQuery("select timediff('2004-12-30 12:00:00', cast('2004-12-30 12:00:00' as time));") - result.Check(testkit.Rows("")) - result = tk.MustQuery("select timediff(cast('2004-12-30 12:00:01' as datetime), '2004-12-30 12:00:00');") - result.Check(testkit.Rows("00:00:01")) - result = tk.MustQuery("select timediff('2004-12-30 12:00:00', cast('2004-12-30 12:00:01' as datetime));") - result.Check(testkit.Rows("-00:00:01")) - result = tk.MustQuery("select timediff(cast('2004-12-30 12:00:01' as time), '-34 00:00:00');") - result.Check(testkit.Rows("828:00:01")) - result = tk.MustQuery("select timediff('-34 00:00:00', cast('2004-12-30 12:00:01' as time));") - result.Check(testkit.Rows("-828:00:01")) - result = tk.MustQuery("select timediff(cast('2004-12-30 12:00:01' as datetime), cast('2004-12-30 11:00:01' as datetime));") - result.Check(testkit.Rows("01:00:00")) - result = tk.MustQuery("select timediff(cast('2004-12-30 12:00:01' as datetime), '2004-12-30 12:00:00.1');") - result.Check(testkit.Rows("00:00:00.9")) - result = tk.MustQuery("select timediff('2004-12-30 12:00:00.1', cast('2004-12-30 12:00:01' as datetime));") - result.Check(testkit.Rows("-00:00:00.9")) - result = tk.MustQuery("select timediff(cast('2004-12-30 12:00:01' as datetime), '-34 124:00:00');") - result.Check(testkit.Rows("")) - result = tk.MustQuery("select timediff('-34 124:00:00', cast('2004-12-30 12:00:01' as datetime));") - result.Check(testkit.Rows("")) - result = tk.MustQuery("select timediff(cast('2004-12-30 12:00:01' as time), '-34 124:00:00');") - result.Check(testkit.Rows("838:59:59")) - result = tk.MustQuery("select timediff('-34 124:00:00', cast('2004-12-30 12:00:01' as time));") - result.Check(testkit.Rows("-838:59:59")) - result = tk.MustQuery("select timediff(cast('2004-12-30' as datetime), '12:00:00');") - result.Check(testkit.Rows("")) - result = tk.MustQuery("select timediff('12:00:00', cast('2004-12-30' as datetime));") - result.Check(testkit.Rows("")) - result = tk.MustQuery("select timediff('12:00:00', '-34 12:00:00');") - result.Check(testkit.Rows("838:59:59")) - result = tk.MustQuery("select timediff('12:00:00', '34 12:00:00');") - result.Check(testkit.Rows("-816:00:00")) - result = tk.MustQuery("select timediff('2014-1-2 12:00:00', '-34 12:00:00');") - result.Check(testkit.Rows("")) - result = tk.MustQuery("select timediff('-34 12:00:00', '2014-1-2 12:00:00');") - result.Check(testkit.Rows("")) - result = tk.MustQuery("select timediff('2014-1-2 12:00:00', '12:00:00');") - result.Check(testkit.Rows("")) - result = tk.MustQuery("select timediff('12:00:00', '2014-1-2 12:00:00');") - result.Check(testkit.Rows("")) - result = tk.MustQuery("select timediff('2014-1-2 12:00:00', '2014-1-1 12:00:00');") - result.Check(testkit.Rows("24:00:00")) - tk.MustQuery("select timediff(cast('10:10:10' as time), cast('10:10:11' as time))").Check(testkit.Rows("-00:00:01")) - - result = tk.MustQuery("select timestampadd(MINUTE, 1, '2003-01-02'), timestampadd(WEEK, 1, '2003-01-02 23:59:59')" + - ", timestampadd(MICROSECOND, 1, 950501);") - result.Check(testkit.Rows("2003-01-02 00:01:00 2003-01-09 23:59:59 1995-05-01 00:00:00.000001")) - result = tk.MustQuery("select timestampadd(day, 2, 950501), timestampadd(MINUTE, 37.5,'2003-01-02'), timestampadd(MINUTE, 37.49,'2003-01-02')," + - " timestampadd(YeAr, 1, '2003-01-02');") - result.Check(testkit.Rows("1995-05-03 00:00:00 2003-01-02 00:38:00 2003-01-02 00:37:00 2004-01-02 00:00:00")) - result = tk.MustQuery("select to_seconds(950501), to_seconds('2009-11-29'), to_seconds('2009-11-29 13:43:32'), to_seconds('09-11-29 13:43:32');") - result.Check(testkit.Rows("62966505600 63426672000 63426721412 63426721412")) - result = tk.MustQuery("select to_days(950501), to_days('2007-10-07'), to_days('2007-10-07 00:00:59'), to_days('0000-01-01')") - result.Check(testkit.Rows("728779 733321 733321 1")) - - result = tk.MustQuery("select last_day('2003-02-05'), last_day('2004-02-05'), last_day('2004-01-01 01:01:01'), last_day(950501);") - result.Check(testkit.Rows("2003-02-28 2004-02-29 2004-01-31 1995-05-31")) - - tk.MustExec("SET SQL_MODE='';") - result = tk.MustQuery("select last_day('0000-00-00');") - result.Check(testkit.Rows("")) - result = tk.MustQuery("select to_days('0000-00-00');") - result.Check(testkit.Rows("")) - result = tk.MustQuery("select to_seconds('0000-00-00');") - result.Check(testkit.Rows("")) - - result = tk.MustQuery("select timestamp('2003-12-31'), timestamp('2003-12-31 12:00:00','12:00:00');") - result.Check(testkit.Rows("2003-12-31 00:00:00 2004-01-01 00:00:00")) - result = tk.MustQuery("select timestamp(20170118123950.123), timestamp(20170118123950.999);") - result.Check(testkit.Rows("2017-01-18 12:39:50.123 2017-01-18 12:39:50.999")) - // Issue https://github.com/pingcap/tidb/issues/20003 - result = tk.MustQuery("select timestamp(0.0001, 0.00001);") - result.Check(testkit.Rows("")) - result = tk.MustQuery("select timestamp('2003-12-31', '01:01:01.01'), timestamp('2003-12-31 12:34', '01:01:01.01')," + - " timestamp('2008-12-31','00:00:00.0'), timestamp('2008-12-31 00:00:00.000');") - - tk.MustQuery(`select timestampadd(second, 1, cast("2001-01-01" as date))`).Check(testkit.Rows("2001-01-01 00:00:01")) - tk.MustQuery(`select timestampadd(hour, 1, cast("2001-01-01" as date))`).Check(testkit.Rows("2001-01-01 01:00:00")) - tk.MustQuery(`select timestampadd(day, 1, cast("2001-01-01" as date))`).Check(testkit.Rows("2001-01-02")) - tk.MustQuery(`select timestampadd(month, 1, cast("2001-01-01" as date))`).Check(testkit.Rows("2001-02-01")) - tk.MustQuery(`select timestampadd(year, 1, cast("2001-01-01" as date))`).Check(testkit.Rows("2002-01-01")) - tk.MustQuery(`select timestampadd(second, 1, cast("2001-01-01" as datetime))`).Check(testkit.Rows("2001-01-01 00:00:01")) - tk.MustQuery(`select timestampadd(hour, 1, cast("2001-01-01" as datetime))`).Check(testkit.Rows("2001-01-01 01:00:00")) - tk.MustQuery(`select timestampadd(day, 1, cast("2001-01-01" as datetime))`).Check(testkit.Rows("2001-01-02 00:00:00")) - tk.MustQuery(`select timestampadd(month, 1, cast("2001-01-01" as datetime))`).Check(testkit.Rows("2001-02-01 00:00:00")) - tk.MustQuery(`select timestampadd(year, 1, cast("2001-01-01" as datetime))`).Check(testkit.Rows("2002-01-01 00:00:00")) - - result.Check(testkit.Rows("2003-12-31 01:01:01.01 2003-12-31 13:35:01.01 2008-12-31 00:00:00.0 2008-12-31 00:00:00.000")) - result = tk.MustQuery("select timestamp('2003-12-31', 1), timestamp('2003-12-31', -1);") - result.Check(testkit.Rows("2003-12-31 00:00:01 2003-12-30 23:59:59")) - result = tk.MustQuery("select timestamp('2003-12-31', '2000-12-12 01:01:01.01'), timestamp('2003-14-31','01:01:01.01');") - result.Check(testkit.Rows(" ")) - - result = tk.MustQuery("select TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'), TIMESTAMPDIFF(yEaR,'2002-05-01', " + - "'2001-01-01'), TIMESTAMPDIFF(minute,binary('2003-02-01'),'2003-05-01 12:05:55'), TIMESTAMPDIFF(day," + - "'1995-05-02', 950501);") - result.Check(testkit.Rows("3 -1 128885 -1")) - - result = tk.MustQuery("select datediff('2007-12-31 23:59:59','2007-12-30'), datediff('2010-11-30 23:59:59', " + - "'2010-12-31'), datediff(950501,'2016-01-13'), datediff(950501.9,'2016-01-13'), datediff(binary(950501), '2016-01-13');") - result.Check(testkit.Rows("1 -31 -7562 -7562 -7562")) - result = tk.MustQuery("select datediff('0000-01-01','0001-01-01'), datediff('0001-00-01', '0001-00-01'), datediff('0001-01-00','0001-01-00'), datediff('2017-01-01','2017-01-01');") - result.Check(testkit.Rows("-365 0")) - - // for ADDTIME - result = tk.MustQuery("select addtime('01:01:11', '00:00:01.013'), addtime('01:01:11.00', '00:00:01'), addtime" + - "('2017-01-01 01:01:11.12', '00:00:01'), addtime('2017-01-01 01:01:11.12', '00:00:01.88');") - result.Check(testkit.Rows("01:01:12.013000 01:01:12 2017-01-01 01:01:12.120000 2017-01-01 01:01:13")) - result = tk.MustQuery("select addtime(cast('01:01:11' as time(4)), '00:00:01.013'), addtime(cast('01:01:11.00' " + - "as datetime(3)), '00:00:01')," + " addtime(cast('2017-01-01 01:01:11.12' as date), '00:00:01'), addtime(cast" + - "(cast('2017-01-01 01:01:11.12' as date) as datetime(2)), '00:00:01.88');") - result.Check(testkit.Rows("01:01:12.0130 2001-01-11 00:00:01.000 00:00:01 2017-01-01 00:00:01.88")) - result = tk.MustQuery("select addtime('2017-01-01 01:01:01', 5), addtime('2017-01-01 01:01:01', -5), addtime('2017-01-01 01:01:01', 0.0), addtime('2017-01-01 01:01:01', 1.34);") - result.Check(testkit.Rows("2017-01-01 01:01:06 2017-01-01 01:00:56 2017-01-01 01:01:01 2017-01-01 01:01:02.340000")) - result = tk.MustQuery("select addtime(cast('01:01:11.00' as datetime(3)), cast('00:00:01' as time)), addtime(cast('01:01:11.00' as datetime(3)), cast('00:00:01' as time(5)))") - result.Check(testkit.Rows("2001-01-11 00:00:01.000 2001-01-11 00:00:01.00000")) - result = tk.MustQuery("select addtime(cast('01:01:11.00' as date), cast('00:00:01' as time));") - result.Check(testkit.Rows("00:00:01")) - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a datetime, b timestamp, c time)") - tk.MustExec(`insert into t values("2017-01-01 12:30:31", "2017-01-01 12:30:31", "01:01:01")`) - result = tk.MustQuery("select addtime(a, b), addtime(cast(a as date), b), addtime(b,a), addtime(a,c), addtime(b," + - "c), addtime(c,a), addtime(c,b)" + - " from t;") - result.Check(testkit.Rows(" 2017-01-01 13:31:32 2017-01-01 13:31:32 ")) - result = tk.MustQuery("select addtime('01:01:11', cast('1' as time))") - result.Check(testkit.Rows("01:01:12")) - tk.MustQuery("select addtime(cast(null as char(20)), cast('1' as time))").Check(testkit.Rows("")) - require.NoError(t, tk.QueryToErr(`select addtime("01:01:11", cast('sdf' as time))`)) - tk.MustQuery(`select addtime("01:01:11", cast(null as char(20)))`).Check(testkit.Rows("")) - tk.MustQuery(`select addtime(cast(1 as time), cast(1 as time))`).Check(testkit.Rows("00:00:02")) - tk.MustQuery(`select addtime(cast(null as time), cast(1 as time))`).Check(testkit.Rows("")) - tk.MustQuery(`select addtime(cast(1 as time), cast(null as time))`).Check(testkit.Rows("")) - - // for SUBTIME - result = tk.MustQuery("select subtime('01:01:11', '00:00:01.013'), subtime('01:01:11.00', '00:00:01'), subtime" + - "('2017-01-01 01:01:11.12', '00:00:01'), subtime('2017-01-01 01:01:11.12', '00:00:01.88');") - result.Check(testkit.Rows("01:01:09.987000 01:01:10 2017-01-01 01:01:10.120000 2017-01-01 01:01:09.240000")) - result = tk.MustQuery("select subtime(cast('01:01:11' as time(4)), '00:00:01.013'), subtime(cast('01:01:11.00' " + - "as datetime(3)), '00:00:01')," + " subtime(cast('2017-01-01 01:01:11.12' as date), '00:00:01'), subtime(cast" + - "(cast('2017-01-01 01:01:11.12' as date) as datetime(2)), '00:00:01.88');") - result.Check(testkit.Rows("01:01:09.9870 2001-01-10 23:59:59.000 -00:00:01 2016-12-31 23:59:58.12")) - result = tk.MustQuery("select subtime('2017-01-01 01:01:01', 5), subtime('2017-01-01 01:01:01', -5), subtime('2017-01-01 01:01:01', 0.0), subtime('2017-01-01 01:01:01', 1.34);") - result.Check(testkit.Rows("2017-01-01 01:00:56 2017-01-01 01:01:06 2017-01-01 01:01:01 2017-01-01 01:00:59.660000")) - result = tk.MustQuery("select subtime('01:01:11', '0:0:1.013'), subtime('01:01:11.00', '0:0:1'), subtime('2017-01-01 01:01:11.12', '0:0:1'), subtime('2017-01-01 01:01:11.12', '0:0:1.120000');") - result.Check(testkit.Rows("01:01:09.987000 01:01:10 2017-01-01 01:01:10.120000 2017-01-01 01:01:10")) - result = tk.MustQuery("select subtime(cast('01:01:11.00' as datetime(3)), cast('00:00:01' as time)), subtime(cast('01:01:11.00' as datetime(3)), cast('00:00:01' as time(5)))") - result.Check(testkit.Rows("2001-01-10 23:59:59.000 2001-01-10 23:59:59.00000")) - result = tk.MustQuery("select subtime(cast('01:01:11.00' as date), cast('00:00:01' as time));") - result.Check(testkit.Rows("-00:00:01")) - result = tk.MustQuery("select subtime(a, b), subtime(cast(a as date), b), subtime(b,a), subtime(a,c), subtime(b," + - "c), subtime(c,a), subtime(c,b) from t;") - result.Check(testkit.Rows(" 2017-01-01 11:29:30 2017-01-01 11:29:30 ")) - tk.MustQuery("select subtime(cast('10:10:10' as time), cast('9:10:10' as time))").Check(testkit.Rows("01:00:00")) - tk.MustQuery("select subtime('10:10:10', cast('9:10:10' as time))").Check(testkit.Rows("01:00:00")) - - // SUBTIME issue #31868 - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a DATETIME(6))") - tk.MustExec(`insert into t values ("1000-01-01 01:00:00.000000"), ("1000-01-01 01:00:00.000001")`) - tk.MustQuery(`SELECT SUBTIME(a, '00:00:00.000001') FROM t ORDER BY a;`).Check(testkit.Rows("1000-01-01 00:59:59.999999", "1000-01-01 01:00:00.000000")) - tk.MustQuery(`SELECT SUBTIME(a, '10:00:00.000001') FROM t ORDER BY a;`).Check(testkit.Rows("0999-12-31 14:59:59.999999", "0999-12-31 15:00:00.000000")) - - // ADDTIME & SUBTIME issue #5966 - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a datetime, b timestamp, c time, d date, e bit(1))") - tk.MustExec(`insert into t values("2017-01-01 12:30:31", "2017-01-01 12:30:31", "01:01:01", "2017-01-01", 0b1)`) - - result = tk.MustQuery("select addtime(a, e), addtime(b, e), addtime(c, e), addtime(d, e) from t") - result.Check(testkit.Rows(" ")) - result = tk.MustQuery("select addtime('2017-01-01 01:01:01', 0b1), addtime('2017-01-01', b'1'), addtime('01:01:01', 0b1011)") - result.Check(testkit.Rows(" ")) - result = tk.MustQuery("select addtime('2017-01-01', 1), addtime('2017-01-01 01:01:01', 1), addtime(cast('2017-01-01' as date), 1)") - result.Check(testkit.Rows("2017-01-01 00:00:01 2017-01-01 01:01:02 00:00:01")) - result = tk.MustQuery("select subtime(a, e), subtime(b, e), subtime(c, e), subtime(d, e) from t") - result.Check(testkit.Rows(" ")) - result = tk.MustQuery("select subtime('2017-01-01 01:01:01', 0b1), subtime('2017-01-01', b'1'), subtime('01:01:01', 0b1011)") - result.Check(testkit.Rows(" ")) - result = tk.MustQuery("select subtime('2017-01-01', 1), subtime('2017-01-01 01:01:01', 1), subtime(cast('2017-01-01' as date), 1)") - result.Check(testkit.Rows("2016-12-31 23:59:59 2017-01-01 01:01:00 -00:00:01")) - - result = tk.MustQuery("select addtime(-32073, 0), addtime(0, -32073);") - result.Check(testkit.Rows(" ")) - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", - "Warning|1292|Truncated incorrect time value: '-32073'", - "Warning|1292|Truncated incorrect time value: '-32073'")) - result = tk.MustQuery("select addtime(-32073, c), addtime(c, -32073) from t;") - result.Check(testkit.Rows(" ")) - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", - "Warning|1292|Truncated incorrect time value: '-32073'", - "Warning|1292|Truncated incorrect time value: '-32073'")) - result = tk.MustQuery("select addtime(a, -32073), addtime(b, -32073), addtime(d, -32073) from t;") - result.Check(testkit.Rows(" ")) - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", - "Warning|1292|Truncated incorrect time value: '-32073'", - "Warning|1292|Truncated incorrect time value: '-32073'", - "Warning|1292|Truncated incorrect time value: '-32073'")) - - result = tk.MustQuery("select subtime(-32073, 0), subtime(0, -32073);") - result.Check(testkit.Rows(" ")) - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", - "Warning|1292|Truncated incorrect time value: '-32073'", - "Warning|1292|Truncated incorrect time value: '-32073'")) - result = tk.MustQuery("select subtime(-32073, c), subtime(c, -32073) from t;") - result.Check(testkit.Rows(" ")) - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", - "Warning|1292|Truncated incorrect time value: '-32073'", - "Warning|1292|Truncated incorrect time value: '-32073'")) - result = tk.MustQuery("select subtime(a, -32073), subtime(b, -32073), subtime(d, -32073) from t;") - result.Check(testkit.Rows(" ")) - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", - "Warning|1292|Truncated incorrect time value: '-32073'", - "Warning|1292|Truncated incorrect time value: '-32073'", - "Warning|1292|Truncated incorrect time value: '-32073'")) - - // fixed issue #3986 - tk.MustExec("SET SQL_MODE='NO_ENGINE_SUBSTITUTION';") - tk.MustExec("SET TIME_ZONE='+03:00';") - tk.MustExec("DROP TABLE IF EXISTS t;") - tk.MustExec("CREATE TABLE t (ix TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);") - tk.MustExec("INSERT INTO t VALUES (0), (20030101010160), (20030101016001), (20030101240101), (20030132010101), (20031301010101), (20031200000000), (20030000000000);") - result = tk.MustQuery("SELECT CAST(ix AS SIGNED) FROM t;") - result.Check(testkit.Rows("0", "0", "0", "0", "0", "0", "0", "0")) - - // test time - result = tk.MustQuery("select time('2003-12-31 01:02:03')") - result.Check(testkit.Rows("01:02:03")) - result = tk.MustQuery("select time('2003-12-31 01:02:03.000123')") - result.Check(testkit.Rows("01:02:03.000123")) - result = tk.MustQuery("select time('01:02:03.000123')") - result.Check(testkit.Rows("01:02:03.000123")) - result = tk.MustQuery("select time('01:02:03')") - result.Check(testkit.Rows("01:02:03")) - result = tk.MustQuery("select time('-838:59:59.000000')") - result.Check(testkit.Rows("-838:59:59.000000")) - result = tk.MustQuery("select time('-838:59:59.000001')") - result.Check(testkit.Rows("-838:59:59.000000")) - result = tk.MustQuery("select time('-839:59:59.000000')") - result.Check(testkit.Rows("-838:59:59.000000")) - result = tk.MustQuery("select time('840:59:59.000000')") - result.Check(testkit.Rows("838:59:59.000000")) - // FIXME: #issue 4193 - // result = tk.MustQuery("select time('840:59:60.000000')") - // result.Check(testkit.Rows("")) - // result = tk.MustQuery("select time('800:59:59.9999999')") - // result.Check(testkit.Rows("801:00:00.000000")) - // result = tk.MustQuery("select time('12003-12-10 01:02:03.000123')") - // result.Check(testkit.Rows("") - // result = tk.MustQuery("select time('')") - // result.Check(testkit.Rows("") - // result = tk.MustQuery("select time('2003-12-10-10 01:02:03.000123')") - // result.Check(testkit.Rows("00:20:03") - - // Issue 20995 - result = tk.MustQuery("select time('0.1234567')") - result.Check(testkit.Rows("00:00:00.123457")) - - // for hour - result = tk.MustQuery(`SELECT hour("12:13:14.123456"), hour("12:13:14.000010"), hour("272:59:55"), hour(020005), hour(null), hour("27aaaa2:59:55");`) - result.Check(testkit.Rows("12 12 272 2 ")) - - // for hour, issue #4340 - result = tk.MustQuery(`SELECT HOUR(20171222020005);`) - result.Check(testkit.Rows("2")) - result = tk.MustQuery(`SELECT HOUR(20171222020005.1);`) - result.Check(testkit.Rows("2")) - result = tk.MustQuery(`SELECT HOUR(20171222020005.1e0);`) - result.Check(testkit.Rows("2")) - result = tk.MustQuery(`SELECT HOUR("20171222020005");`) - result.Check(testkit.Rows("2")) - result = tk.MustQuery(`SELECT HOUR("20171222020005.1");`) - result.Check(testkit.Rows("2")) - result = tk.MustQuery(`select hour(20171222);`) - result.Check(testkit.Rows("")) - result = tk.MustQuery(`select hour(8381222);`) - result.Check(testkit.Rows("838")) - result = tk.MustQuery(`select hour(10000000000);`) - result.Check(testkit.Rows("")) - result = tk.MustQuery(`select hour(10100000000);`) - result.Check(testkit.Rows("")) - result = tk.MustQuery(`select hour(10001000000);`) - result.Check(testkit.Rows("")) - result = tk.MustQuery(`select hour(10101000000);`) - result.Check(testkit.Rows("0")) - - // for minute - result = tk.MustQuery(`SELECT minute("12:13:14.123456"), minute("12:13:14.000010"), minute("272:59:55"), minute(null), minute("27aaaa2:59:55");`) - result.Check(testkit.Rows("13 13 59 ")) - - // for second - result = tk.MustQuery(`SELECT second("12:13:14.123456"), second("12:13:14.000010"), second("272:59:55"), second(null), second("27aaaa2:59:55");`) - result.Check(testkit.Rows("14 14 55 ")) - - // for microsecond - result = tk.MustQuery(`SELECT microsecond("12:00:00.123456"), microsecond("12:00:00.000010"), microsecond(null), microsecond("27aaaa2:59:55");`) - result.Check(testkit.Rows("123456 10 ")) - - // for period_add - result = tk.MustQuery(`SELECT period_add(200807, 2), period_add(200807, -2);`) - result.Check(testkit.Rows("200809 200805")) - result = tk.MustQuery(`SELECT period_add(NULL, 2), period_add(-191, NULL), period_add(NULL, NULL), period_add(12.09, -2), period_add("200207aa", "1aa");`) - result.Check(testkit.Rows(" 200010 200208")) - for _, errPeriod := range []string{ - "period_add(0, 20)", "period_add(0, 0)", "period_add(-1, 1)", "period_add(200013, 1)", "period_add(-200012, 1)", "period_add('', '')", - } { - err := tk.QueryToErr(fmt.Sprintf("SELECT %v;", errPeriod)) - require.Error(t, err, "[expression:1210]Incorrect arguments to period_add") - } - - // for period_diff - result = tk.MustQuery(`SELECT period_diff(200807, 200705), period_diff(200807, 200908);`) - result.Check(testkit.Rows("14 -13")) - result = tk.MustQuery(`SELECT period_diff(NULL, 2), period_diff(-191, NULL), period_diff(NULL, NULL), period_diff(12.09, 2), period_diff("12aa", "11aa");`) - result.Check(testkit.Rows(" 10 1")) - for _, errPeriod := range []string{ - "period_diff(-00013,1)", "period_diff(00013,1)", "period_diff(0, 0)", "period_diff(200013, 1)", "period_diff(5612, 4513)", "period_diff('', '')", - } { - err := tk.QueryToErr(fmt.Sprintf("SELECT %v;", errPeriod)) - require.Error(t, err, "[expression:1210]Incorrect arguments to period_diff") - } - - // TODO: fix `CAST(xx as duration)` and release the test below: - // result = tk.MustQuery(`SELECT hour("aaa"), hour(123456), hour(1234567);`) - // result = tk.MustQuery(`SELECT minute("aaa"), minute(123456), minute(1234567);`) - // result = tk.MustQuery(`SELECT second("aaa"), second(123456), second(1234567);`) - // result = tk.MustQuery(`SELECT microsecond("aaa"), microsecond(123456), microsecond(1234567);`) - - // for time_format - result = tk.MustQuery("SELECT TIME_FORMAT('150:02:28', '%H:%i:%s %p');") - result.Check(testkit.Rows("150:02:28 AM")) - result = tk.MustQuery("SELECT TIME_FORMAT('bad string', '%H:%i:%s %p');") - result.Check(testkit.Rows("")) - result = tk.MustQuery("SELECT TIME_FORMAT(null, '%H:%i:%s %p');") - result.Check(testkit.Rows("")) - result = tk.MustQuery("SELECT TIME_FORMAT(123, '%H:%i:%s %p');") - result.Check(testkit.Rows("00:01:23 AM")) - result = tk.MustQuery("SELECT TIME_FORMAT('24:00:00', '%r');") - result.Check(testkit.Rows("12:00:00 AM")) - result = tk.MustQuery("SELECT TIME_FORMAT('25:00:00', '%r');") - result.Check(testkit.Rows("01:00:00 AM")) - result = tk.MustQuery("SELECT TIME_FORMAT('24:00:00', '%l %p');") - result.Check(testkit.Rows("12 AM")) - - // for date_format - result = tk.MustQuery(`SELECT DATE_FORMAT('2017-06-15', '%W %M %e %Y %r %y');`) - result.Check(testkit.Rows("Thursday June 15 2017 12:00:00 AM 17")) - result = tk.MustQuery(`SELECT DATE_FORMAT(151113102019.12, '%W %M %e %Y %r %y');`) - result.Check(testkit.Rows("Friday November 13 2015 10:20:19 AM 15")) - result = tk.MustQuery(`SELECT DATE_FORMAT('0000-00-00', '%W %M %e %Y %r %y');`) - result.Check(testkit.Rows("")) - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", - "Warning|1292|Incorrect datetime value: '0000-00-00 00:00:00.000000'")) - result = tk.MustQuery(`SELECT DATE_FORMAT('0', '%W %M %e %Y %r %y'), DATE_FORMAT('0.0', '%W %M %e %Y %r %y'), DATE_FORMAT(0, 0);`) - result.Check(testkit.Rows(" 0")) - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", - "Warning|1292|Incorrect time value: '0'", - "Warning|1292|Incorrect datetime value: '0.0'")) - result = tk.MustQuery(`SELECT DATE_FORMAT(0, '%W %M %e %Y %r %y'), DATE_FORMAT(0.0, '%W %M %e %Y %r %y');`) - result.Check(testkit.Rows(" ")) - tk.MustQuery("show warnings").Check(testkit.Rows()) - - // for yearweek - result = tk.MustQuery(`select yearweek("2014-12-27"), yearweek("2014-29-27"), yearweek("2014-00-27"), yearweek("2014-12-27 12:38:32"), yearweek("2014-12-27 12:38:32.1111111"), yearweek("2014-12-27 12:90:32"), yearweek("2014-12-27 89:38:32.1111111");`) - result.Check(testkit.Rows("201451 201451 201451 ")) - result = tk.MustQuery(`select yearweek(12121), yearweek(1.00009), yearweek("aaaaa"), yearweek(""), yearweek(NULL);`) - result.Check(testkit.Rows(" ")) - result = tk.MustQuery(`select yearweek("0000-00-00"), yearweek("2019-01-29", "aa"), yearweek("2011-01-01", null);`) - result.Check(testkit.Rows(" 201904 201052")) - - // for dayOfWeek, dayOfMonth, dayOfYear - result = tk.MustQuery(`select dayOfWeek(null), dayOfWeek("2017-08-12"), dayOfWeek("0000-00-00"), dayOfWeek("2017-00-00"), dayOfWeek("0000-00-00 12:12:12"), dayOfWeek("2017-00-00 12:12:12")`) - result.Check(testkit.Rows(" 7 ")) - result = tk.MustQuery(`select dayOfYear(null), dayOfYear("2017-08-12"), dayOfYear("0000-00-00"), dayOfYear("2017-00-00"), dayOfYear("0000-00-00 12:12:12"), dayOfYear("2017-00-00 12:12:12")`) - result.Check(testkit.Rows(" 224 ")) - result = tk.MustQuery(`select dayOfMonth(null), dayOfMonth("2017-08-12"), dayOfMonth("0000-00-00"), dayOfMonth("2017-00-00"), dayOfMonth("0000-00-00 12:12:12"), dayOfMonth("2017-00-00 12:12:12")`) - result.Check(testkit.Rows(" 12 0 0 0 0")) - - tk.MustExec("set sql_mode = 'NO_ZERO_DATE'") - result = tk.MustQuery(`select dayOfWeek(null), dayOfWeek("2017-08-12"), dayOfWeek("0000-00-00"), dayOfWeek("2017-00-00"), dayOfWeek("0000-00-00 12:12:12"), dayOfWeek("2017-00-00 12:12:12")`) - result.Check(testkit.Rows(" 7 ")) - result = tk.MustQuery(`select dayOfYear(null), dayOfYear("2017-08-12"), dayOfYear("0000-00-00"), dayOfYear("2017-00-00"), dayOfYear("0000-00-00 12:12:12"), dayOfYear("2017-00-00 12:12:12")`) - result.Check(testkit.Rows(" 224 ")) - result = tk.MustQuery(`select dayOfMonth(null), dayOfMonth("2017-08-12"), dayOfMonth("0000-00-00"), dayOfMonth("2017-00-00"), dayOfMonth("0000-00-00 12:12:12"), dayOfMonth("2017-00-00 12:12:12")`) - result.Check(testkit.Rows(" 12 0 0 0")) - - tk.MustExec(`drop table if exists t`) - tk.MustExec(`create table t(a bigint)`) - tk.MustExec(`insert into t value(1)`) - tk.MustExec("set sql_mode = 'STRICT_TRANS_TABLES'") - - _, err = tk.Exec("insert into t value(dayOfWeek('0000-00-00'))") - require.True(t, types.ErrWrongValue.Equal(err), "%v", err) - _, err = tk.Exec(`update t set a = dayOfWeek("0000-00-00")`) - require.True(t, types.ErrWrongValue.Equal(err)) - _, err = tk.Exec(`delete from t where a = dayOfWeek(123)`) - require.NoError(t, err) - - tk.MustExec("insert into t value(dayOfMonth('2017-00-00'))") - tk.MustExec("insert into t value(dayOfMonth('0000-00-00'))") - tk.MustExec(`update t set a = dayOfMonth("0000-00-00")`) - tk.MustExec("set sql_mode = 'NO_ZERO_DATE';") - tk.MustExec("insert into t value(dayOfMonth('0000-00-00'))") - tk.MustQuery("show warnings").CheckContain("Incorrect datetime value: '0000-00-00 00:00:00.000000'") - tk.MustExec(`update t set a = dayOfMonth("0000-00-00")`) - tk.MustExec("set sql_mode = 'NO_ZERO_DATE,STRICT_TRANS_TABLES';") - _, err = tk.Exec("insert into t value(dayOfMonth('0000-00-00'))") - require.True(t, types.ErrWrongValue.Equal(err)) - tk.MustExec("insert into t value(0)") - _, err = tk.Exec(`update t set a = dayOfMonth("0000-00-00")`) - require.True(t, types.ErrWrongValue.Equal(err)) - _, err = tk.Exec(`delete from t where a = dayOfMonth(123)`) - require.NoError(t, err) - - _, err = tk.Exec("insert into t value(dayOfYear('0000-00-00'))") - require.True(t, types.ErrWrongValue.Equal(err)) - _, err = tk.Exec(`update t set a = dayOfYear("0000-00-00")`) - require.True(t, types.ErrWrongValue.Equal(err)) - _, err = tk.Exec(`delete from t where a = dayOfYear(123)`) - require.NoError(t, err) - - tk.MustExec("set sql_mode = ''") - - // for unix_timestamp - tk.MustExec("SET time_zone = '+00:00';") - tk.MustQuery("SELECT UNIX_TIMESTAMP('1970-01-01 00:00:00.000001');").Check(testkit.Rows("0.000000")) - tk.MustQuery("SELECT UNIX_TIMESTAMP('1970-01-01 00:00:00.999999');").Check(testkit.Rows("0.000000")) - tk.MustQuery("SELECT UNIX_TIMESTAMP('1970-01-01 00:00:01.000000');").Check(testkit.Rows("1.000000")) - tk.MustQuery("SELECT UNIX_TIMESTAMP('2038-01-19 03:14:07.999999');").Check(testkit.Rows("2147483647.999999")) - tk.MustQuery("SELECT UNIX_TIMESTAMP('2038-01-19 03:14:08.000000');").Check(testkit.Rows("2147483648.000000")) - tk.MustQuery("SELECT UNIX_TIMESTAMP('3001-01-18 23:59:59.999999');").Check(testkit.Rows("32536771199.999999")) - tk.MustQuery("SELECT UNIX_TIMESTAMP('3001-01-19 00:00:00.000000');").Check(testkit.Rows("0.000000")) - - result = tk.MustQuery("SELECT UNIX_TIMESTAMP(151113);") - result.Check(testkit.Rows("1447372800")) - result = tk.MustQuery("SELECT UNIX_TIMESTAMP(20151113);") - result.Check(testkit.Rows("1447372800")) - result = tk.MustQuery("SELECT UNIX_TIMESTAMP(151113102019);") - result.Check(testkit.Rows("1447410019")) - result = tk.MustQuery("SELECT UNIX_TIMESTAMP(151113102019e0);") - result.Check(testkit.Rows("1447410019.000000")) - result = tk.MustQuery("SELECT UNIX_TIMESTAMP(15111310201912e-2);") - result.Check(testkit.Rows("1447410019.120000")) - result = tk.MustQuery("SELECT UNIX_TIMESTAMP(151113102019.12);") - result.Check(testkit.Rows("1447410019.12")) - result = tk.MustQuery("SELECT UNIX_TIMESTAMP(151113102019.1234567);") - result.Check(testkit.Rows("1447410019.123457")) - result = tk.MustQuery("SELECT UNIX_TIMESTAMP(20151113102019);") - result.Check(testkit.Rows("1447410019")) - result = tk.MustQuery("SELECT UNIX_TIMESTAMP('2015-11-13 10:20:19');") - result.Check(testkit.Rows("1447410019")) - result = tk.MustQuery("SELECT UNIX_TIMESTAMP('2015-11-13 10:20:19.012');") - result.Check(testkit.Rows("1447410019.012")) - result = tk.MustQuery("SELECT UNIX_TIMESTAMP('1970-01-01 00:00:00');") - result.Check(testkit.Rows("0")) - result = tk.MustQuery("SELECT UNIX_TIMESTAMP('1969-12-31 23:59:59');") - result.Check(testkit.Rows("0")) - result = tk.MustQuery("SELECT UNIX_TIMESTAMP('1970-13-01 00:00:00');") - // FIXME: MySQL returns 0 here. - result.Check(testkit.Rows("")) - result = tk.MustQuery("SELECT UNIX_TIMESTAMP('2038-01-19 03:14:07.999999');") - result.Check(testkit.Rows("2147483647.999999")) - result = tk.MustQuery("SELECT UNIX_TIMESTAMP('3001-01-18 23:59:59.999999');") - result.Check(testkit.Rows("32536771199.999999")) - result = tk.MustQuery("SELECT UNIX_TIMESTAMP('3001-01-19 00:00:00');") - result.Check(testkit.Rows("0")) - result = tk.MustQuery("SELECT UNIX_TIMESTAMP(0);") - result.Check(testkit.Rows("0")) - // result = tk.MustQuery("SELECT UNIX_TIMESTAMP(-1);") - // result.Check(testkit.Rows("0")) - // result = tk.MustQuery("SELECT UNIX_TIMESTAMP(12345);") - // result.Check(testkit.Rows("0")) - result = tk.MustQuery("SELECT UNIX_TIMESTAMP('2017-01-01')") - result.Check(testkit.Rows("1483228800")) - // Test different time zone. - tk.MustExec("SET time_zone = '+08:00';") - result = tk.MustQuery("SELECT UNIX_TIMESTAMP('1970-01-01 00:00:00');") - result.Check(testkit.Rows("0")) - result = tk.MustQuery("SELECT UNIX_TIMESTAMP('1970-01-01 08:00:00');") - result.Check(testkit.Rows("0")) - result = tk.MustQuery("SELECT UNIX_TIMESTAMP('2015-11-13 18:20:19.012'), UNIX_TIMESTAMP('2015-11-13 18:20:19.0123');") - result.Check(testkit.Rows("1447410019.012 1447410019.0123")) - result = tk.MustQuery("SELECT UNIX_TIMESTAMP('2038-01-19 11:14:07.999999');") - result.Check(testkit.Rows("2147483647.999999")) - - result = tk.MustQuery("SELECT TIME_FORMAT('bad string', '%H:%i:%s %p');") - result.Check(testkit.Rows("")) - result = tk.MustQuery("SELECT TIME_FORMAT(null, '%H:%i:%s %p');") - result.Check(testkit.Rows("")) - result = tk.MustQuery("SELECT TIME_FORMAT(123, '%H:%i:%s %p');") - result.Check(testkit.Rows("00:01:23 AM")) - - // for monthname - tk.MustExec(`drop table if exists t`) - tk.MustExec(`create table t(a varchar(10))`) - tk.MustExec(`insert into t value("abc")`) - tk.MustExec("set sql_mode = 'STRICT_TRANS_TABLES'") - - tk.MustExec("insert into t value(monthname('0000-00-00'))") - tk.MustExec(`update t set a = monthname("0000-00-00")`) - tk.MustExec("set sql_mode = 'NO_ZERO_DATE'") - tk.MustExec("insert into t value(monthname('0000-00-00'))") - tk.MustQuery("show warnings").CheckContain("Incorrect datetime value: '0000-00-00 00:00:00.000000'") - tk.MustExec(`update t set a = monthname("0000-00-00")`) - tk.MustExec("set sql_mode = ''") - tk.MustExec("insert into t value(monthname('0000-00-00'))") - tk.MustExec("set sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_DATE'") - _, err = tk.Exec(`update t set a = monthname("0000-00-00")`) - require.True(t, types.ErrWrongValue.Equal(err)) - _, err = tk.Exec(`delete from t where a = monthname(123)`) - require.NoError(t, err) - result = tk.MustQuery(`select monthname("2017-12-01"), monthname("0000-00-00"), monthname("0000-01-00"), monthname("0000-01-00 00:00:00")`) - result.Check(testkit.Rows("December January January")) - tk.MustQuery("show warnings").CheckContain("Incorrect datetime value: '0000-00-00 00:00:00.000000'") - - // for dayname - tk.MustExec(`drop table if exists t`) - tk.MustExec(`create table t(a varchar(10))`) - tk.MustExec(`insert into t value("abc")`) - tk.MustExec("set sql_mode = 'STRICT_TRANS_TABLES'") - - _, err = tk.Exec("insert into t value(dayname('0000-00-00'))") - require.True(t, types.ErrWrongValue.Equal(err)) - _, err = tk.Exec(`update t set a = dayname("0000-00-00")`) - require.True(t, types.ErrWrongValue.Equal(err)) - _, err = tk.Exec(`delete from t where a = dayname(123)`) - require.NoError(t, err) - result = tk.MustQuery(`select dayname("2017-12-01"), dayname("0000-00-00"), dayname("0000-01-00"), dayname("0000-01-00 00:00:00")`) - result.Check(testkit.Rows("Friday ")) - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", - "Warning|1292|Incorrect datetime value: '0000-00-00 00:00:00.000000'", - "Warning|1292|Incorrect datetime value: '0000-01-00 00:00:00.000000'", - "Warning|1292|Incorrect datetime value: '0000-01-00 00:00:00.000000'")) - // for dayname implicit cast to boolean and real - result = tk.MustQuery(`select 1 from dual where dayname('2016-03-07')`) - result.Check(testkit.Rows()) - result = tk.MustQuery(`select 1 from dual where dayname('2016-03-07') is true`) - result.Check(testkit.Rows()) - result = tk.MustQuery(`select 1 from dual where dayname('2016-03-07') is false`) - result.Check(testkit.Rows("1")) - result = tk.MustQuery(`select 1 from dual where dayname('2016-03-08')`) - result.Check(testkit.Rows("1")) - result = tk.MustQuery(`select 1 from dual where dayname('2016-03-08') is true`) - result.Check(testkit.Rows("1")) - result = tk.MustQuery(`select 1 from dual where dayname('2016-03-08') is false`) - result.Check(testkit.Rows()) - result = tk.MustQuery(`select cast(dayname("2016-03-07") as double), cast(dayname("2016-03-08") as double)`) - result.Check(testkit.Rows("0 1")) - - // for sec_to_time - result = tk.MustQuery("select sec_to_time(NULL)") - result.Check(testkit.Rows("")) - result = tk.MustQuery("select sec_to_time(2378), sec_to_time(3864000), sec_to_time(-3864000)") - result.Check(testkit.Rows("00:39:38 838:59:59 -838:59:59")) - result = tk.MustQuery("select sec_to_time(86401.4), sec_to_time(-86401.4), sec_to_time(864014e-1), sec_to_time(-864014e-1), sec_to_time('86401.4'), sec_to_time('-86401.4')") - result.Check(testkit.Rows("24:00:01.4 -24:00:01.4 24:00:01.400000 -24:00:01.400000 24:00:01.400000 -24:00:01.400000")) - result = tk.MustQuery("select sec_to_time(86401.54321), sec_to_time(86401.543212345)") - result.Check(testkit.Rows("24:00:01.54321 24:00:01.543212")) - result = tk.MustQuery("select sec_to_time('123.4'), sec_to_time('123.4567891'), sec_to_time('123')") - result.Check(testkit.Rows("00:02:03.400000 00:02:03.456789 00:02:03.000000")) - - // for time_to_sec - result = tk.MustQuery("select time_to_sec(NULL)") - result.Check(testkit.Rows("")) - result = tk.MustQuery("select time_to_sec('22:23:00'), time_to_sec('00:39:38'), time_to_sec('23:00'), time_to_sec('00:00'), time_to_sec('00:00:00'), time_to_sec('23:59:59')") - result.Check(testkit.Rows("80580 2378 82800 0 0 86399")) - result = tk.MustQuery("select time_to_sec('1:0'), time_to_sec('1:00'), time_to_sec('1:0:0'), time_to_sec('-02:00'), time_to_sec('-02:00:05'), time_to_sec('020005')") - result.Check(testkit.Rows("3600 3600 3600 -7200 -7205 7205")) - result = tk.MustQuery("select time_to_sec('20171222020005'), time_to_sec(020005), time_to_sec(20171222020005), time_to_sec(171222020005)") - result.Check(testkit.Rows("7205 7205 7205 7205")) - - // for str_to_date - result = tk.MustQuery("select str_to_date('01-01-2017', '%d-%m-%Y'), str_to_date('59:20:12 01-01-2017', '%s:%i:%H %d-%m-%Y'), str_to_date('59:20:12', '%s:%i:%H')") - result.Check(testkit.Rows("2017-01-01 2017-01-01 12:20:59 12:20:59")) - result = tk.MustQuery("select str_to_date('aaa01-01-2017', 'aaa%d-%m-%Y'), str_to_date('59:20:12 aaa01-01-2017', '%s:%i:%H aaa%d-%m-%Y'), str_to_date('59:20:12aaa', '%s:%i:%Haaa')") - result.Check(testkit.Rows("2017-01-01 2017-01-01 12:20:59 12:20:59")) - - result = tk.MustQuery("select str_to_date('01-01-2017', '%d'), str_to_date('59', '%d-%Y')") - // TODO: MySQL returns " ". - result.Check(testkit.Rows("0000-00-01 ")) - result = tk.MustQuery("show warnings") - result.Sort().Check(testkit.RowsWithSep("|", - "Warning|1292|Incorrect datetime value: '0000-00-00 00:00:00'", - "Warning|1292|Truncated incorrect datetime value: '01-01-2017'")) - - result = tk.MustQuery("select str_to_date('2018-6-1', '%Y-%m-%d'), str_to_date('2018-6-1', '%Y-%c-%d'), str_to_date('59:20:1', '%s:%i:%k'), str_to_date('59:20:1', '%s:%i:%l')") - result.Check(testkit.Rows("2018-06-01 2018-06-01 01:20:59 01:20:59")) - - result = tk.MustQuery("select str_to_date('2020-07-04 11:22:33 PM c', '%Y-%m-%d %r')") - result.Check(testkit.Rows("2020-07-04 23:22:33")) - result = tk.MustQuery("show warnings") - result.Check(testkit.RowsWithSep("|", "Warning|1292|Truncated incorrect datetime value: '2020-07-04 11:22:33 PM c'")) - - result = tk.MustQuery("select str_to_date('11:22:33 PM', ' %r')") - result.Check(testkit.Rows("23:22:33")) - result = tk.MustQuery("show warnings") - result.Check(testkit.Rows()) - - // for maketime - tk.MustExec(`drop table if exists t`) - tk.MustExec(`create table t(a double, b float, c decimal(10,4));`) - tk.MustExec(`insert into t value(1.23, 2.34, 3.1415)`) - result = tk.MustQuery("select maketime(1,1,a), maketime(2,2,b), maketime(3,3,c) from t;") - result.Check(testkit.Rows("01:01:01.230000 02:02:02.340000 03:03:03.1415")) - result = tk.MustQuery("select maketime(12, 13, 14), maketime('12', '15', 30.1), maketime(0, 1, 59.1), maketime(0, 1, '59.1'), maketime(0, 1, 59.5)") - result.Check(testkit.Rows("12:13:14 12:15:30.1 00:01:59.1 00:01:59.100000 00:01:59.5")) - result = tk.MustQuery("select maketime(12, 15, 60), maketime(12, 15, '60'), maketime(12, 60, 0), maketime(12, 15, null)") - result.Check(testkit.Rows(" ")) - result = tk.MustQuery("select maketime('', '', ''), maketime('h', 'm', 's');") - result.Check(testkit.Rows("00:00:00.000000 00:00:00.000000")) - - // for get_format - result = tk.MustQuery(`select GET_FORMAT(DATE,'USA'), GET_FORMAT(DATE,'JIS'), GET_FORMAT(DATE,'ISO'), GET_FORMAT(DATE,'EUR'), - GET_FORMAT(DATE,'INTERNAL'), GET_FORMAT(DATETIME,'USA') , GET_FORMAT(DATETIME,'JIS'), GET_FORMAT(DATETIME,'ISO'), - GET_FORMAT(DATETIME,'EUR') , GET_FORMAT(DATETIME,'INTERNAL'), GET_FORMAT(TIME,'USA') , GET_FORMAT(TIME,'JIS'), - GET_FORMAT(TIME,'ISO'), GET_FORMAT(TIME,'EUR'), GET_FORMAT(TIME,'INTERNAL')`) - result.Check(testkit.Rows("%m.%d.%Y %Y-%m-%d %Y-%m-%d %d.%m.%Y %Y%m%d %Y-%m-%d %H.%i.%s %Y-%m-%d %H:%i:%s %Y-%m-%d %H:%i:%s %Y-%m-%d %H.%i.%s %Y%m%d%H%i%s %h:%i:%s %p %H:%i:%s %H:%i:%s %H.%i.%s %H%i%s")) - - // for convert_tz - result = tk.MustQuery(`select convert_tz("2004-01-01 12:00:00", "+00:00", "+10:32"), convert_tz("2004-01-01 12:00:00.01", "+00:00", "+10:32"), convert_tz("2004-01-01 12:00:00.01234567", "+00:00", "+10:32");`) - result.Check(testkit.Rows("2004-01-01 22:32:00 2004-01-01 22:32:00.01 2004-01-01 22:32:00.012346")) - result = tk.MustQuery(`select convert_tz(20040101, "+00:00", "+10:32"), convert_tz(20040101.01, "+00:00", "+10:32"), convert_tz(20040101.01234567, "+00:00", "+10:32");`) - result.Check(testkit.Rows("2004-01-01 10:32:00 2004-01-01 10:32:00.00 2004-01-01 10:32:00.000000")) - result = tk.MustQuery(`select convert_tz(NULL, "+00:00", "+10:32"), convert_tz("2004-01-01 12:00:00", NULL, "+10:32"), convert_tz("2004-01-01 12:00:00", "+00:00", NULL);`) - result.Check(testkit.Rows(" ")) - result = tk.MustQuery(`select convert_tz("a", "+00:00", "+10:32"), convert_tz("2004-01-01 12:00:00", "a", "+10:32"), convert_tz("2004-01-01 12:00:00", "+00:00", "a");`) - result.Check(testkit.Rows(" ")) - result = tk.MustQuery(`select convert_tz("", "+00:00", "+10:32"), convert_tz("2004-01-01 12:00:00", "", "+10:32"), convert_tz("2004-01-01 12:00:00", "+00:00", "");`) - result.Check(testkit.Rows(" ")) - result = tk.MustQuery(`select convert_tz("0", "+00:00", "+10:32"), convert_tz("2004-01-01 12:00:00", "0", "+10:32"), convert_tz("2004-01-01 12:00:00", "+00:00", "0");`) - result.Check(testkit.Rows(" ")) - - // for from_unixtime - tk.MustExec(`set @@session.time_zone = "+08:00"`) - result = tk.MustQuery(`select from_unixtime(20170101), from_unixtime(20170101.9999999), from_unixtime(20170101.999), from_unixtime(20170101.999, "%Y %D %M %h:%i:%s %x"), from_unixtime(20170101.999, "%Y %D %M %h:%i:%s %x")`) - result.Check(testkit.Rows("1970-08-22 18:48:21 1970-08-22 18:48:22.000000 1970-08-22 18:48:21.999 1970 22nd August 06:48:21 1970 1970 22nd August 06:48:21 1970")) - tk.MustExec(`set @@session.time_zone = "+00:00"`) - result = tk.MustQuery(`select from_unixtime(20170101), from_unixtime(20170101.9999999), from_unixtime(20170101.999), from_unixtime(20170101.999, "%Y %D %M %h:%i:%s %x"), from_unixtime(20170101.999, "%Y %D %M %h:%i:%s %x")`) - result.Check(testkit.Rows("1970-08-22 10:48:21 1970-08-22 10:48:22.000000 1970-08-22 10:48:21.999 1970 22nd August 10:48:21 1970 1970 22nd August 10:48:21 1970")) - tk.MustExec(`set @@session.time_zone = @@global.time_zone`) - - // for extract - result = tk.MustQuery(`select extract(day from '800:12:12'), extract(hour from '800:12:12'), extract(month from 20170101), extract(day_second from '2017-01-01 12:12:12')`) - result.Check(testkit.Rows("12 800 1 1121212")) - result = tk.MustQuery("select extract(day_microsecond from '2017-01-01 12:12:12'), extract(day_microsecond from '01 12:12:12'), extract(day_microsecond from '12:12:12'), extract(day_microsecond from '01 00:00:00.89')") - result.Check(testkit.Rows("1121212000000 361212000000 121212000000 240000890000")) - result = tk.MustQuery("select extract(day_second from '2017-01-01 12:12:12'), extract(day_second from '01 12:12:12'), extract(day_second from '12:12:12'), extract(day_second from '01 00:00:00.89')") - result.Check(testkit.Rows("1121212 361212 121212 240000")) - result = tk.MustQuery("select extract(day_minute from '2017-01-01 12:12:12'), extract(day_minute from '01 12:12:12'), extract(day_minute from '12:12:12'), extract(day_minute from '01 00:00:00.89')") - result.Check(testkit.Rows("11212 3612 1212 2400")) - result = tk.MustQuery("select extract(day_hour from '2017-01-01 12:12:12'), extract(day_hour from '01 12:12:12'), extract(day_hour from '12:12:12'), extract(day_hour from '01 00:00:00.89')") - result.Check(testkit.Rows("112 36 12 24")) - result = tk.MustQuery("select extract(day_microsecond from cast('2017-01-01 12:12:12' as datetime)), extract(day_second from cast('2017-01-01 12:12:12' as datetime)), extract(day_minute from cast('2017-01-01 12:12:12' as datetime)), extract(day_hour from cast('2017-01-01 12:12:12' as datetime))") - result.Check(testkit.Rows("1121212000000 1121212 11212 112")) - result = tk.MustQuery("select extract(day_microsecond from cast(20010101020304.050607 as decimal(20,6))), extract(day_second from cast(20010101020304.050607 as decimal(20,6))), extract(day_minute from cast(20010101020304.050607 as decimal(20,6))), extract(day_hour from cast(20010101020304.050607 as decimal(20,6))), extract(day from cast(20010101020304.050607 as decimal(20,6)))") - result.Check(testkit.Rows("1020304050607 1020304 10203 102 1")) - result = tk.MustQuery("select extract(day_microsecond from cast(1020304.050607 as decimal(20,6))), extract(day_second from cast(1020304.050607 as decimal(20,6))), extract(day_minute from cast(1020304.050607 as decimal(20,6))), extract(day_hour from cast(1020304.050607 as decimal(20,6))), extract(day from cast(1020304.050607 as decimal(20,6)))") - result.Check(testkit.Rows("1020304050607 1020304 10203 102 4")) - - // for adddate, subdate - dateArithmeticalTests := []struct { - Date string - Interval string - Unit string - AddResult string - SubResult string - }{ - {"\"2011-11-11\"", "1", "DAY", "2011-11-12", "2011-11-10"}, - {"NULL", "1", "DAY", "", ""}, - {"\"2011-11-11\"", "NULL", "DAY", "", ""}, - {"\"2011-11-11 10:10:10\"", "1000", "MICROSECOND", "2011-11-11 10:10:10.001000", "2011-11-11 10:10:09.999000"}, - {"\"2011-11-11 10:10:10\"", "\"10\"", "SECOND", "2011-11-11 10:10:20", "2011-11-11 10:10:00"}, - {"\"2011-11-11 10:10:10\"", "\"10\"", "MINUTE", "2011-11-11 10:20:10", "2011-11-11 10:00:10"}, - {"\"2011-11-11 10:10:10\"", "\"10\"", "HOUR", "2011-11-11 20:10:10", "2011-11-11 00:10:10"}, - {"\"2011-11-11 10:10:10\"", "\"11\"", "DAY", "2011-11-22 10:10:10", "2011-10-31 10:10:10"}, - {"\"2011-11-11 10:10:10\"", "\"2\"", "WEEK", "2011-11-25 10:10:10", "2011-10-28 10:10:10"}, - {"\"2011-11-11 10:10:10\"", "\"2\"", "MONTH", "2012-01-11 10:10:10", "2011-09-11 10:10:10"}, - {"\"2011-11-11 10:10:10\"", "\"4\"", "QUARTER", "2012-11-11 10:10:10", "2010-11-11 10:10:10"}, - {"\"2011-11-11 10:10:10\"", "\"2\"", "YEAR", "2013-11-11 10:10:10", "2009-11-11 10:10:10"}, - {"\"2011-11-11 10:10:10\"", "\"10.00100000\"", "SECOND_MICROSECOND", "2011-11-11 10:10:20.100000", "2011-11-11 10:09:59.900000"}, - {"\"2011-11-11 10:10:10\"", "\"10.0010000000\"", "SECOND_MICROSECOND", "2011-11-11 10:10:30", "2011-11-11 10:09:50"}, - {"\"2011-11-11 10:10:10\"", "\"10.0010000010\"", "SECOND_MICROSECOND", "2011-11-11 10:10:30.000010", "2011-11-11 10:09:49.999990"}, - {"\"2011-11-11 10:10:10\"", "\"10:10.100\"", "MINUTE_MICROSECOND", "2011-11-11 10:20:20.100000", "2011-11-11 09:59:59.900000"}, - {"\"2011-11-11 10:10:10\"", "\"10:10\"", "MINUTE_SECOND", "2011-11-11 10:20:20", "2011-11-11 10:00:00"}, - {"\"2011-11-11 10:10:10\"", "\"10:10:10.100\"", "HOUR_MICROSECOND", "2011-11-11 20:20:20.100000", "2011-11-10 23:59:59.900000"}, - {"\"2011-11-11 10:10:10\"", "\"10:10:10\"", "HOUR_SECOND", "2011-11-11 20:20:20", "2011-11-11 00:00:00"}, - {"\"2011-11-11 10:10:10\"", "\"10:10\"", "HOUR_MINUTE", "2011-11-11 20:20:10", "2011-11-11 00:00:10"}, - {"\"2011-11-11 10:10:10\"", "\"11 10:10:10.100\"", "DAY_MICROSECOND", "2011-11-22 20:20:20.100000", "2011-10-30 23:59:59.900000"}, - {"\"2011-11-11 10:10:10\"", "\"11 10:10:10\"", "DAY_SECOND", "2011-11-22 20:20:20", "2011-10-31 00:00:00"}, - {"\"2011-11-11 10:10:10\"", "\"11 10:10\"", "DAY_MINUTE", "2011-11-22 20:20:10", "2011-10-31 00:00:10"}, - {"\"2011-11-11 10:10:10\"", "\"11 10\"", "DAY_HOUR", "2011-11-22 20:10:10", "2011-10-31 00:10:10"}, - {"\"2011-11-11 10:10:10\"", "\"11-1\"", "YEAR_MONTH", "2022-12-11 10:10:10", "2000-10-11 10:10:10"}, - {"\"2011-11-11 10:10:10\"", "\"11-11\"", "YEAR_MONTH", "2023-10-11 10:10:10", "1999-12-11 10:10:10"}, - {"\"2011-11-11 10:10:10\"", "\"20\"", "DAY", "2011-12-01 10:10:10", "2011-10-22 10:10:10"}, - {"\"2011-11-11 10:10:10\"", "19.88", "DAY", "2011-12-01 10:10:10", "2011-10-22 10:10:10"}, - {"\"2011-11-11 10:10:10\"", "\"19.88\"", "DAY", "2011-11-30 10:10:10", "2011-10-23 10:10:10"}, - {"\"2011-11-11 10:10:10\"", "\"prefix19suffix\"", "DAY", "2011-11-30 10:10:10", "2011-10-23 10:10:10"}, - {"\"2011-11-11 10:10:10\"", "\"20-11\"", "DAY", "2011-12-01 10:10:10", "2011-10-22 10:10:10"}, - {"\"2011-11-11 10:10:10\"", "\"20,11\"", "daY", "2011-12-01 10:10:10", "2011-10-22 10:10:10"}, - {"\"2011-11-11 10:10:10\"", "\"1000\"", "dAy", "2014-08-07 10:10:10", "2009-02-14 10:10:10"}, - {"\"2011-11-11 10:10:10\"", "\"true\"", "Day", "2011-11-12 10:10:10", "2011-11-10 10:10:10"}, - {"\"2011-11-11 10:10:10\"", "true", "Day", "2011-11-12 10:10:10", "2011-11-10 10:10:10"}, - {"\"2011-11-11\"", "1", "DAY", "2011-11-12", "2011-11-10"}, - {"\"2011-11-11\"", "10", "HOUR", "2011-11-11 10:00:00", "2011-11-10 14:00:00"}, - {"\"2011-11-11\"", "10", "MINUTE", "2011-11-11 00:10:00", "2011-11-10 23:50:00"}, - {"\"2011-11-11\"", "10", "SECOND", "2011-11-11 00:00:10", "2011-11-10 23:59:50"}, - {"\"2011-11-11\"", "\"10:10\"", "HOUR_MINUTE", "2011-11-11 10:10:00", "2011-11-10 13:50:00"}, - {"\"2011-11-11\"", "\"10:10:10\"", "HOUR_SECOND", "2011-11-11 10:10:10", "2011-11-10 13:49:50"}, - {"\"2011-11-11\"", "\"10:10:10.101010\"", "HOUR_MICROSECOND", "2011-11-11 10:10:10.101010", "2011-11-10 13:49:49.898990"}, - {"\"2011-11-11\"", "\"10:10\"", "MINUTE_SECOND", "2011-11-11 00:10:10", "2011-11-10 23:49:50"}, - {"\"2011-11-11\"", "\"10:10.101010\"", "MINUTE_MICROSECOND", "2011-11-11 00:10:10.101010", "2011-11-10 23:49:49.898990"}, - {"\"2011-11-11\"", "\"10.101010\"", "SECOND_MICROSECOND", "2011-11-11 00:00:10.101010", "2011-11-10 23:59:49.898990"}, - {"\"2011-11-11 00:00:00\"", "1", "DAY", "2011-11-12 00:00:00", "2011-11-10 00:00:00"}, - {"\"2011-11-11 00:00:00\"", "10", "HOUR", "2011-11-11 10:00:00", "2011-11-10 14:00:00"}, - {"\"2011-11-11 00:00:00\"", "10", "MINUTE", "2011-11-11 00:10:00", "2011-11-10 23:50:00"}, - {"\"2011-11-11 00:00:00\"", "10", "SECOND", "2011-11-11 00:00:10", "2011-11-10 23:59:50"}, - {"\"2011-11-11 00:00:00.500\"", "500000", "MICROSECOND", "2011-11-11 00:00:01", "2011-11-11 00:00:00"}, - - {"\"2011-11-11\"", "\"abc1000\"", "MICROSECOND", "2011-11-11 00:00:00", "2011-11-11 00:00:00"}, - {"\"20111111 10:10:10\"", "\"1\"", "DAY", "", ""}, - {"\"2011-11-11\"", "\"10\"", "SECOND_MICROSECOND", "2011-11-11 00:00:00.100000", "2011-11-10 23:59:59.900000"}, - {"\"2011-11-11\"", "\"10.0000\"", "MINUTE_MICROSECOND", "2011-11-11 00:00:10", "2011-11-10 23:59:50"}, - {"\"2011-11-11\"", "\"10:10:10\"", "MINUTE_MICROSECOND", "2011-11-11 00:10:10.100000", "2011-11-10 23:49:49.900000"}, - - {"cast(\"2011-11-11\" as datetime)", "\"10:10:10\"", "MINUTE_MICROSECOND", "2011-11-11 00:10:10.100000", "2011-11-10 23:49:49.900000"}, - {"cast(\"2011-11-11\" as datetime)", "\"1000000\"", "MICROSECOND", "2011-11-11 00:00:01.000000", "2011-11-10 23:59:59.000000"}, - {"cast(\"2011-11-11 00:00:00\" as datetime)", "1", "DAY", "2011-11-12 00:00:00", "2011-11-10 00:00:00"}, - {"cast(\"2011-11-11 00:00:00\" as datetime)", "10", "HOUR", "2011-11-11 10:00:00", "2011-11-10 14:00:00"}, - {"cast(\"2011-11-11 00:00:00\" as datetime)", "10", "MINUTE", "2011-11-11 00:10:00", "2011-11-10 23:50:00"}, - {"cast(\"2011-11-11 00:00:00\" as datetime)", "10", "SECOND", "2011-11-11 00:00:10", "2011-11-10 23:59:50"}, - - {"cast(\"2011-11-11 00:00:00\" as datetime)", "\"1\"", "DAY", "2011-11-12 00:00:00", "2011-11-10 00:00:00"}, - {"cast(\"2011-11-11 00:00:00\" as datetime)", "\"10\"", "HOUR", "2011-11-11 10:00:00", "2011-11-10 14:00:00"}, - {"cast(\"2011-11-11 00:00:00\" as datetime)", "\"10\"", "MINUTE", "2011-11-11 00:10:00", "2011-11-10 23:50:00"}, - {"cast(\"2011-11-11 00:00:00\" as datetime)", "\"10\"", "SECOND", "2011-11-11 00:00:10.000000", "2011-11-10 23:59:50.000000"}, - - {"cast(\"2011-11-11\" as date)", "\"10:10:10\"", "MINUTE_MICROSECOND", "2011-11-11 00:10:10.100000", "2011-11-10 23:49:49.900000"}, - {"cast(\"2011-11-11\" as date)", "\"1000000\"", "MINUTE_MICROSECOND", "2011-11-11 00:00:01.000000", "2011-11-10 23:59:59.000000"}, - {"cast(\"2011-11-11 00:00:00\" as date)", "1", "DAY", "2011-11-12", "2011-11-10"}, - {"cast(\"2011-11-11 00:00:00\" as date)", "10", "HOUR", "2011-11-11 10:00:00", "2011-11-10 14:00:00"}, - {"cast(\"2011-11-11 00:00:00\" as date)", "10", "MINUTE", "2011-11-11 00:10:00", "2011-11-10 23:50:00"}, - {"cast(\"2011-11-11 00:00:00\" as date)", "10", "SECOND", "2011-11-11 00:00:10", "2011-11-10 23:59:50"}, - - {"cast(\"2011-11-11 00:00:00\" as date)", "\"1\"", "DAY", "2011-11-12", "2011-11-10"}, - {"cast(\"2011-11-11 00:00:00\" as date)", "\"10\"", "HOUR", "2011-11-11 10:00:00", "2011-11-10 14:00:00"}, - {"cast(\"2011-11-11 00:00:00\" as date)", "\"10\"", "MINUTE", "2011-11-11 00:10:00", "2011-11-10 23:50:00"}, - {"cast(\"2011-11-11 00:00:00\" as date)", "\"10\"", "SECOND", "2011-11-11 00:00:10.000000", "2011-11-10 23:59:50.000000"}, - - // interval decimal support - {"\"2011-01-01 00:00:00\"", "10.10", "YEAR_MONTH", "2021-11-01 00:00:00", "2000-03-01 00:00:00"}, - {"\"2011-01-01 00:00:00\"", "10.10", "DAY_HOUR", "2011-01-11 10:00:00", "2010-12-21 14:00:00"}, - {"\"2011-01-01 00:00:00\"", "10.10", "HOUR_MINUTE", "2011-01-01 10:10:00", "2010-12-31 13:50:00"}, - {"\"2011-01-01 00:00:00\"", "10.10", "DAY_MINUTE", "2011-01-01 10:10:00", "2010-12-31 13:50:00"}, - {"\"2011-01-01 00:00:00\"", "10.10", "DAY_SECOND", "2011-01-01 00:10:10", "2010-12-31 23:49:50"}, - {"\"2011-01-01 00:00:00\"", "10.10", "HOUR_SECOND", "2011-01-01 00:10:10", "2010-12-31 23:49:50"}, - {"\"2011-01-01 00:00:00\"", "10.10", "MINUTE_SECOND", "2011-01-01 00:10:10", "2010-12-31 23:49:50"}, - {"\"2011-01-01 00:00:00\"", "10.10", "DAY_MICROSECOND", "2011-01-01 00:00:10.100000", "2010-12-31 23:59:49.900000"}, - {"\"2011-01-01 00:00:00\"", "10.10", "HOUR_MICROSECOND", "2011-01-01 00:00:10.100000", "2010-12-31 23:59:49.900000"}, - {"\"2011-01-01 00:00:00\"", "10.10", "MINUTE_MICROSECOND", "2011-01-01 00:00:10.100000", "2010-12-31 23:59:49.900000"}, - {"\"2011-01-01 00:00:00\"", "10.10", "SECOND_MICROSECOND", "2011-01-01 00:00:10.100000", "2010-12-31 23:59:49.900000"}, - {"\"2011-01-01 00:00:00\"", "10.10", "YEAR", "2021-01-01 00:00:00", "2001-01-01 00:00:00"}, - {"\"2011-01-01 00:00:00\"", "10.10", "QUARTER", "2013-07-01 00:00:00", "2008-07-01 00:00:00"}, - {"\"2011-01-01 00:00:00\"", "10.10", "MONTH", "2011-11-01 00:00:00", "2010-03-01 00:00:00"}, - {"\"2011-01-01 00:00:00\"", "10.10", "WEEK", "2011-03-12 00:00:00", "2010-10-23 00:00:00"}, - {"\"2011-01-01 00:00:00\"", "10.10", "DAY", "2011-01-11 00:00:00", "2010-12-22 00:00:00"}, - {"\"2011-01-01 00:00:00\"", "10.10", "HOUR", "2011-01-01 10:00:00", "2010-12-31 14:00:00"}, - {"\"2011-01-01 00:00:00\"", "10.10", "MINUTE", "2011-01-01 00:10:00", "2010-12-31 23:50:00"}, - {"\"2011-01-01 00:00:00\"", "10.10", "SECOND", "2011-01-01 00:00:10.100000", "2010-12-31 23:59:49.900000"}, - {"\"2011-01-01 00:00:00\"", "10.10", "MICROSECOND", "2011-01-01 00:00:00.000010", "2010-12-31 23:59:59.999990"}, - {"\"2011-01-01 00:00:00\"", "10.90", "MICROSECOND", "2011-01-01 00:00:00.000011", "2010-12-31 23:59:59.999989"}, - {"cast(\"2011-01-01\" as date)", "1.1", "SECOND", "2011-01-01 00:00:01.1", "2010-12-31 23:59:58.9"}, - {"cast(\"2011-01-01\" as datetime)", "1.1", "SECOND", "2011-01-01 00:00:01.1", "2010-12-31 23:59:58.9"}, - {"cast(\"2011-01-01\" as datetime(3))", "1.1", "SECOND", "2011-01-01 00:00:01.100", "2010-12-31 23:59:58.900"}, - - {"\"2009-01-01\"", "6/4", "HOUR_MINUTE", "2009-01-04 12:20:00", "2008-12-28 11:40:00"}, - {"\"2009-01-01\"", "6/0", "HOUR_MINUTE", "", ""}, - {"\"1970-01-01 12:00:00\"", "CAST(6/4 AS DECIMAL(3,1))", "HOUR_MINUTE", "1970-01-01 13:05:00", "1970-01-01 10:55:00"}, - // for issue #8077 - {"\"2012-01-02\"", "\"prefix8\"", "HOUR", "2012-01-02 08:00:00", "2012-01-01 16:00:00"}, - {"\"2012-01-02\"", "\"prefix8prefix\"", "HOUR", "2012-01-02 08:00:00", "2012-01-01 16:00:00"}, - {"\"2012-01-02\"", "\"8:00\"", "HOUR", "2012-01-02 08:00:00", "2012-01-01 16:00:00"}, - {"\"2012-01-02\"", "\"8:00:00\"", "HOUR", "2012-01-02 08:00:00", "2012-01-01 16:00:00"}, - } - for _, tc := range dateArithmeticalTests { - addDate := fmt.Sprintf("select adddate(%s, interval %s %s);", tc.Date, tc.Interval, tc.Unit) - subDate := fmt.Sprintf("select subdate(%s, interval %s %s);", tc.Date, tc.Interval, tc.Unit) - result = tk.MustQuery(addDate) - result.Check(testkit.Rows(tc.AddResult)) - result = tk.MustQuery(subDate) - result.Check(testkit.Rows(tc.SubResult)) - } - - // Customized check for the cases of adddate(time, ...) - it returns datetime with current date padded. - // 1. Check if the result contains space, that is, it must contain YMD part. - // 2. Check if the result's suffix matches expected, that is, the HMS part is an exact match. - checkHmsMatch := func(actual []string, expected []interface{}) bool { - return strings.Contains(actual[0], " ") && strings.HasSuffix(actual[0], expected[0].(string)) - } - - // for date_add/sub(duration, ...) - dateAddSubDurationAnyTests := []struct { - Date string - Interval string - Unit string - AddResult string - SubResult string - checkHmsOnly bool // Duration + day returns datetime with current date padded, only check HMS part for them. - }{ - {"cast('01:02:03' as time)", "'1000'", "MICROSECOND", "01:02:03.001000", "01:02:02.999000", false}, - {"cast('01:02:03' as time)", "1000", "MICROSECOND", "01:02:03.001000", "01:02:02.999000", false}, - {"cast('01:02:03' as time)", "'1'", "SECOND", "01:02:04.000000", "01:02:02.000000", false}, - {"cast('01:02:03' as time)", "1", "SECOND", "01:02:04", "01:02:02", false}, - {"cast('01:02:03' as time)", "'1.1'", "SECOND", "01:02:04.100000", "01:02:01.900000", false}, - {"cast('01:02:03' as time)", "1.1", "SECOND", "01:02:04.1", "01:02:01.9", false}, - {"cast('01:02:03' as time(3))", "1.1", "SECOND", "01:02:04.100", "01:02:01.900", false}, - {"cast('01:02:03' as time)", "cast(1.1 as decimal(10, 3))", "SECOND", "01:02:04.100", "01:02:01.900", false}, - {"cast('01:02:03' as time)", "cast('1.5' as double)", "SECOND", "01:02:04.500000", "01:02:01.500000", false}, - {"cast('01:02:03' as time)", "1", "DAY_MICROSECOND", "01:02:03.100000", "01:02:02.900000", false}, - {"cast('01:02:03' as time)", "1.1", "DAY_MICROSECOND", "01:02:04.100000", "01:02:01.900000", false}, - {"cast('01:02:03' as time)", "100", "DAY_MICROSECOND", "01:02:03.100000", "01:02:02.900000", false}, - {"cast('01:02:03' as time)", "1000000", "DAY_MICROSECOND", "01:02:04.000000", "01:02:02.000000", false}, - {"cast('01:02:03' as time)", "1", "DAY_SECOND", "01:02:04", "01:02:02", true}, - {"cast('01:02:03' as time)", "1.1", "DAY_SECOND", "01:03:04", "01:01:02", true}, - {"cast('01:02:03' as time)", "1", "DAY_MINUTE", "01:03:03", "01:01:03", true}, - {"cast('01:02:03' as time)", "1.1", "DAY_MINUTE", "02:03:03", "00:01:03", true}, - {"cast('01:02:03' as time)", "1", "DAY_HOUR", "02:02:03", "00:02:03", true}, - {"cast('01:02:03' as time)", "1.1", "DAY_HOUR", "02:02:03", "00:02:03", true}, - {"cast('01:02:03' as time)", "1", "DAY", "01:02:03", "01:02:03", true}, - {"cast('01:02:03' as time)", "1", "WEEK", "01:02:03", "01:02:03", true}, - {"cast('01:02:03' as time)", "1", "MONTH", "01:02:03", "01:02:03", true}, - {"cast('01:02:03' as time)", "1", "QUARTER", "01:02:03", "01:02:03", true}, - {"cast('01:02:03' as time)", "1", "YEAR", "01:02:03", "01:02:03", true}, - {"cast('01:02:03' as time)", "1", "YEAR_MONTH", "01:02:03", "01:02:03", true}, - } - for _, tc := range dateAddSubDurationAnyTests { - addDate := fmt.Sprintf("select date_add(%s, interval %s %s);", tc.Date, tc.Interval, tc.Unit) - subDate := fmt.Sprintf("select date_sub(%s, interval %s %s);", tc.Date, tc.Interval, tc.Unit) - if tc.checkHmsOnly { - result = tk.MustQuery(addDate) - result.CheckWithFunc(testkit.Rows(tc.AddResult), checkHmsMatch) - result = tk.MustQuery(subDate) - result.CheckWithFunc(testkit.Rows(tc.SubResult), checkHmsMatch) - } else { - result = tk.MustQuery(addDate) - result.Check(testkit.Rows(tc.AddResult)) - result = tk.MustQuery(subDate) - result.Check(testkit.Rows(tc.SubResult)) - } - } - - tk.MustQuery(`select subdate(cast("2000-02-01" as datetime), cast(1 as decimal))`).Check(testkit.Rows("2000-01-31 00:00:00")) - tk.MustQuery(`select subdate(cast("2000-02-01" as datetime), cast(null as decimal))`).Check(testkit.Rows("")) - tk.MustQuery(`select subdate(cast(null as datetime), cast(1 as decimal))`).Check(testkit.Rows("")) - tk.MustQuery(`select subdate(cast("2000-02-01" as datetime), cast("xxx" as decimal))`).Check(testkit.Rows("2000-02-01 00:00:00")) - tk.MustQuery(`select subdate(cast("xxx" as datetime), cast(1 as decimal))`).Check(testkit.Rows("")) - tk.MustQuery(`select subdate(cast(20000101 as SIGNED), cast("1" as decimal))`).Check(testkit.Rows("1999-12-31")) - tk.MustQuery(`select subdate(cast(20000101 as SIGNED), cast("xxx" as decimal))`).Check(testkit.Rows("2000-01-01")) - tk.MustQuery(`select subdate(cast("abc" as SIGNED), cast("1" as decimal))`).Check(testkit.Rows("")) - tk.MustQuery(`select subdate(cast(null as SIGNED), cast("1" as decimal))`).Check(testkit.Rows("")) - tk.MustQuery(`select subdate(cast(20000101 as SIGNED), cast(null as decimal))`).Check(testkit.Rows("")) - tk.MustQuery(`select adddate(cast("2000-02-01" as datetime), cast(1 as decimal))`).Check(testkit.Rows("2000-02-02 00:00:00")) - tk.MustQuery(`select adddate(cast("2000-02-01" as datetime), cast(null as decimal))`).Check(testkit.Rows("")) - tk.MustQuery(`select adddate(cast(null as datetime), cast(1 as decimal))`).Check(testkit.Rows("")) - tk.MustQuery(`select adddate(cast("2000-02-01" as datetime), cast("xxx" as decimal))`).Check(testkit.Rows("2000-02-01 00:00:00")) - tk.MustQuery(`select adddate(cast("xxx" as datetime), cast(1 as decimal))`).Check(testkit.Rows("")) - tk.MustQuery(`select adddate(cast("2000-02-01" as datetime), cast(1 as SIGNED))`).Check(testkit.Rows("2000-02-02 00:00:00")) - tk.MustQuery(`select adddate(cast("2000-02-01" as datetime), cast(null as SIGNED))`).Check(testkit.Rows("")) - tk.MustQuery(`select adddate(cast(null as datetime), cast(1 as SIGNED))`).Check(testkit.Rows("")) - tk.MustQuery(`select adddate(cast("2000-02-01" as datetime), cast("xxx" as SIGNED))`).Check(testkit.Rows("2000-02-01 00:00:00")) - tk.MustQuery(`select adddate(cast("xxx" as datetime), cast(1 as SIGNED))`).Check(testkit.Rows("")) - tk.MustQuery(`select adddate(20100101, cast(1 as decimal))`).Check(testkit.Rows("2010-01-02")) - tk.MustQuery(`select adddate(cast('10:10:10' as time), 1)`).CheckWithFunc(testkit.Rows("10:10:10"), checkHmsMatch) - tk.MustQuery(`select adddate(cast('10:10:10' as time), cast(1 as decimal))`).CheckWithFunc(testkit.Rows("10:10:10"), checkHmsMatch) - - // for localtime, localtimestamp - result = tk.MustQuery(`select localtime() = now(), localtime = now(), localtimestamp() = now(), localtimestamp = now()`) - result.Check(testkit.Rows("1 1 1 1")) - - // for current_timestamp, current_timestamp() - result = tk.MustQuery(`select current_timestamp() = now(), current_timestamp = now()`) - result.Check(testkit.Rows("1 1")) - - // for tidb_parse_tso - tk.MustExec("SET time_zone = '+00:00';") - result = tk.MustQuery(`select tidb_parse_tso(404411537129996288)`) - result.Check(testkit.Rows("2018-11-20 09:53:04.877000")) - result = tk.MustQuery(`select tidb_parse_tso("404411537129996288")`) - result.Check(testkit.Rows("2018-11-20 09:53:04.877000")) - result = tk.MustQuery(`select tidb_parse_tso(1)`) - result.Check(testkit.Rows("1970-01-01 00:00:00.000000")) - result = tk.MustQuery(`select tidb_parse_tso(0)`) - result.Check(testkit.Rows("")) - result = tk.MustQuery(`select tidb_parse_tso(-1)`) - result.Check(testkit.Rows("")) - - // for tidb_parse_tso_logical - result = tk.MustQuery(`SELECT TIDB_PARSE_TSO_LOGICAL(404411537129996288)`) - result.Check(testkit.Rows("0")) - result = tk.MustQuery(`SELECT TIDB_PARSE_TSO_LOGICAL(404411537129996289)`) - result.Check(testkit.Rows("1")) - result = tk.MustQuery(`SELECT TIDB_PARSE_TSO_LOGICAL(404411537129996290)`) - result.Check(testkit.Rows("2")) - result = tk.MustQuery(`SELECT TIDB_PARSE_TSO_LOGICAL(-1)`) - result.Check(testkit.Rows("")) - - // for tidb_bounded_staleness - tk.MustExec("SET time_zone = '+00:00';") - tt := time.Now().UTC() - ts := oracle.GoTimeToTS(tt) - tidbBoundedStalenessTests := []struct { - sql string - injectSafeTS uint64 - expect string - }{ - { - sql: `select tidb_bounded_staleness(DATE_SUB(NOW(), INTERVAL 600 SECOND), DATE_ADD(NOW(), INTERVAL 600 SECOND))`, - injectSafeTS: ts, - expect: tt.Format(types.TimeFSPFormat[:len(types.TimeFSPFormat)-3]), - }, - { - sql: `select tidb_bounded_staleness("2021-04-27 12:00:00.000", "2021-04-27 13:00:00.000")`, - injectSafeTS: func() uint64 { - tt, err := time.Parse("2006-01-02 15:04:05.000", "2021-04-27 13:30:04.877") - require.NoError(t, err) - return oracle.GoTimeToTS(tt) - }(), - expect: "2021-04-27 13:00:00.000", - }, - { - sql: `select tidb_bounded_staleness("2021-04-27 12:00:00.000", "2021-04-27 13:00:00.000")`, - injectSafeTS: func() uint64 { - tt, err := time.Parse("2006-01-02 15:04:05.000", "2021-04-27 11:30:04.877") - require.NoError(t, err) - return oracle.GoTimeToTS(tt) - }(), - expect: "2021-04-27 12:00:00.000", - }, - { - sql: `select tidb_bounded_staleness("2021-04-27 12:00:00.000", "2021-04-27 11:00:00.000")`, - injectSafeTS: 0, - expect: "", - }, - // Time is too small. - { - sql: `select tidb_bounded_staleness("0020-04-27 12:00:00.000", "2021-04-27 11:00:00.000")`, - injectSafeTS: 0, - expect: "1970-01-01 00:00:00.000", - }, - // Wrong value. - { - sql: `select tidb_bounded_staleness(1, 2)`, - injectSafeTS: 0, - expect: "", - }, - { - sql: `select tidb_bounded_staleness("invalid_time_1", "invalid_time_2")`, - injectSafeTS: 0, - expect: "", - }, - } - for _, test := range tidbBoundedStalenessTests { - require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/expression/injectSafeTS", - fmt.Sprintf("return(%v)", test.injectSafeTS))) - tk.MustQuery(test.sql).Check(testkit.Rows(test.expect)) - } - failpoint.Disable("github.com/pingcap/tidb/expression/injectSafeTS") - // test whether tidb_bounded_staleness is deterministic - result = tk.MustQuery(`select tidb_bounded_staleness(NOW(), DATE_ADD(NOW(), INTERVAL 600 SECOND)), tidb_bounded_staleness(NOW(), DATE_ADD(NOW(), INTERVAL 600 SECOND))`) - require.Len(t, result.Rows()[0], 2) - require.Equal(t, result.Rows()[0][0], result.Rows()[0][1]) - preResult := result.Rows()[0][0] - time.Sleep(time.Second) - result = tk.MustQuery(`select tidb_bounded_staleness(NOW(), DATE_ADD(NOW(), INTERVAL 600 SECOND)), tidb_bounded_staleness(NOW(), DATE_ADD(NOW(), INTERVAL 600 SECOND))`) - require.Len(t, result.Rows()[0], 2) - require.Equal(t, result.Rows()[0][0], result.Rows()[0][1]) - require.NotEqual(t, preResult, result.Rows()[0][0]) - - // fix issue 10308 - result = tk.MustQuery("select time(\"- -\");") - result.Check(testkit.Rows("00:00:00")) - tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1292 Truncated incorrect time value: '- -'")) - result = tk.MustQuery("select time(\"---1\");") - result.Check(testkit.Rows("00:00:00")) - tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1292 Truncated incorrect time value: '---1'")) - result = tk.MustQuery("select time(\"-- --1\");") - result.Check(testkit.Rows("00:00:00")) - tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1292 Truncated incorrect time value: '-- --1'")) - - // fix issue #15185 - result = tk.MustQuery(`select timestamp(11111.1111)`) - result.Check(testkit.Rows("2001-11-11 00:00:00.0000")) - result = tk.MustQuery(`select timestamp(cast(11111.1111 as decimal(60, 5)))`) - result.Check(testkit.Rows("2001-11-11 00:00:00.00000")) - result = tk.MustQuery(`select timestamp(1021121141105.4324)`) - result.Check(testkit.Rows("0102-11-21 14:11:05.4324")) - result = tk.MustQuery(`select timestamp(cast(1021121141105.4324 as decimal(60, 5)))`) - result.Check(testkit.Rows("0102-11-21 14:11:05.43240")) - result = tk.MustQuery(`select timestamp(21121141105.101)`) - result.Check(testkit.Rows("2002-11-21 14:11:05.101")) - result = tk.MustQuery(`select timestamp(cast(21121141105.101 as decimal(60, 5)))`) - result.Check(testkit.Rows("2002-11-21 14:11:05.10100")) - result = tk.MustQuery(`select timestamp(1121141105.799055)`) - result.Check(testkit.Rows("2000-11-21 14:11:05.799055")) - result = tk.MustQuery(`select timestamp(cast(1121141105.799055 as decimal(60, 5)))`) - result.Check(testkit.Rows("2000-11-21 14:11:05.79906")) - result = tk.MustQuery(`select timestamp(121141105.123)`) - result.Check(testkit.Rows("2000-01-21 14:11:05.123")) - result = tk.MustQuery(`select timestamp(cast(121141105.123 as decimal(60, 5)))`) - result.Check(testkit.Rows("2000-01-21 14:11:05.12300")) - result = tk.MustQuery(`select timestamp(1141105)`) - result.Check(testkit.Rows("0114-11-05 00:00:00")) - result = tk.MustQuery(`select timestamp(cast(1141105 as decimal(60, 5)))`) - result.Check(testkit.Rows("0114-11-05 00:00:00.00000")) - result = tk.MustQuery(`select timestamp(41105.11)`) - result.Check(testkit.Rows("2004-11-05 00:00:00.00")) - result = tk.MustQuery(`select timestamp(cast(41105.11 as decimal(60, 5)))`) - result.Check(testkit.Rows("2004-11-05 00:00:00.00000")) - result = tk.MustQuery(`select timestamp(1105.3)`) - result.Check(testkit.Rows("2000-11-05 00:00:00.0")) - result = tk.MustQuery(`select timestamp(cast(1105.3 as decimal(60, 5)))`) - result.Check(testkit.Rows("2000-11-05 00:00:00.00000")) - result = tk.MustQuery(`select timestamp(105)`) - result.Check(testkit.Rows("2000-01-05 00:00:00")) - result = tk.MustQuery(`select timestamp(cast(105 as decimal(60, 5)))`) - result.Check(testkit.Rows("2000-01-05 00:00:00.00000")) -} - -func TestSetVariables(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - _, err := tk.Exec("set sql_mode='adfasdfadsfdasd';") - require.Error(t, err) - _, err = tk.Exec("set @@sql_mode='adfasdfadsfdasd';") - require.Error(t, err) - _, err = tk.Exec("set @@global.sql_mode='adfasdfadsfdasd';") - require.Error(t, err) - _, err = tk.Exec("set @@session.sql_mode='adfasdfadsfdasd';") - require.Error(t, err) - - var r *testkit.Result - _, err = tk.Exec("set @@session.sql_mode=',NO_ZERO_DATE,ANSI,ANSI_QUOTES';") - require.NoError(t, err) - r = tk.MustQuery(`select @@session.sql_mode`) - r.Check(testkit.Rows("NO_ZERO_DATE,REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ONLY_FULL_GROUP_BY,ANSI")) - r = tk.MustQuery(`show variables like 'sql_mode'`) - r.Check(testkit.Rows("sql_mode NO_ZERO_DATE,REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ONLY_FULL_GROUP_BY,ANSI")) - - // for invalid SQL mode. - tk.MustExec("use test") - tk.MustExec("drop table if exists tab0") - tk.MustExec("CREATE TABLE tab0(col1 time)") - _, err = tk.Exec("set sql_mode='STRICT_TRANS_TABLES';") - require.NoError(t, err) - _, err = tk.Exec("INSERT INTO tab0 select cast('999:44:33' as time);") - require.Error(t, err) - require.Error(t, err, "[types:1292]Truncated incorrect time value: '999:44:33'") - _, err = tk.Exec("set sql_mode=' ,';") - require.Error(t, err) - _, err = tk.Exec("INSERT INTO tab0 select cast('999:44:33' as time);") - require.Error(t, err) - require.Error(t, err, "[types:1292]Truncated incorrect time value: '999:44:33'") - - // issue #5478 - _, err = tk.Exec("set session transaction read write;") - require.NoError(t, err) - _, err = tk.Exec("set global transaction read write;") - require.NoError(t, err) - r = tk.MustQuery(`select @@session.tx_read_only, @@global.tx_read_only, @@session.transaction_read_only, @@global.transaction_read_only;`) - r.Check(testkit.Rows("0 0 0 0")) - - _, err = tk.Exec("set session transaction read only;") - require.Error(t, err) - - _, err = tk.Exec("start transaction read only;") - require.Error(t, err) - - _, err = tk.Exec("set tidb_enable_noop_functions=1") - require.NoError(t, err) - - tk.MustExec("set session transaction read only;") - tk.MustExec("start transaction read only;") - - r = tk.MustQuery(`select @@session.tx_read_only, @@global.tx_read_only, @@session.transaction_read_only, @@global.transaction_read_only;`) - r.Check(testkit.Rows("1 0 1 0")) - _, err = tk.Exec("set global transaction read only;") - require.Error(t, err) - tk.MustExec("set global tidb_enable_noop_functions=1;") - tk.MustExec("set global transaction read only;") - r = tk.MustQuery(`select @@session.tx_read_only, @@global.tx_read_only, @@session.transaction_read_only, @@global.transaction_read_only;`) - r.Check(testkit.Rows("1 1 1 1")) - - _, err = tk.Exec("set session transaction read write;") - require.NoError(t, err) - _, err = tk.Exec("set global transaction read write;") - require.NoError(t, err) - r = tk.MustQuery(`select @@session.tx_read_only, @@global.tx_read_only, @@session.transaction_read_only, @@global.transaction_read_only;`) - r.Check(testkit.Rows("0 0 0 0")) - - // reset - tk.MustExec("set tidb_enable_noop_functions=0") - tk.MustExec("set global tidb_enable_noop_functions=1") - - _, err = tk.Exec("set @@global.max_user_connections='';") - require.Error(t, err) - require.Error(t, err, variable.ErrWrongTypeForVar.GenWithStackByArgs("max_user_connections").Error()) - _, err = tk.Exec("set @@global.max_prepared_stmt_count='';") - require.Error(t, err) - require.Error(t, err, variable.ErrWrongTypeForVar.GenWithStackByArgs("max_prepared_stmt_count").Error()) - - // Previously global values were cached. This is incorrect. - // See: https://github.com/pingcap/tidb/issues/24368 - tk.MustQuery("SHOW VARIABLES LIKE 'max_connections'").Check(testkit.Rows("max_connections 0")) - tk.MustExec("SET GLOBAL max_connections=1234") - tk.MustQuery("SHOW VARIABLES LIKE 'max_connections'").Check(testkit.Rows("max_connections 1234")) - // restore - tk.MustExec("SET GLOBAL max_connections=0") -} - -func TestPreparePlanCache(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("set tidb_enable_prepared_plan_cache=ON") - // Use the example from the docs https://docs.pingcap.com/tidb/stable/sql-prepare-plan-cache - tk.MustExec("use test") - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t(a int);") - tk.MustExec("prepare stmt from 'select * from t where a = ?';") - tk.MustExec("set @a = 1;") - tk.MustExec("execute stmt using @a;") - tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0")) - tk.MustExec("execute stmt using @a;") - tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("1")) -} - -func TestPreparePlanCacheOnCachedTable(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("set tidb_enable_prepared_plan_cache=ON") - tk.Session() - - var err error - se, err := session.CreateSession4TestWithOpt(store, &session.Opt{ - PreparedPlanCache: plannercore.NewLRUPlanCache(100, 0.1, math.MaxUint64, tk.Session(), false), - }) - require.NoError(t, err) - tk.SetSession(se) - - tk.MustExec("use test") - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t(a int);") - tk.MustExec("alter table t cache") - - var readFromTableCache bool - for i := 0; i < 50; i++ { - tk.MustQuery("select * from t where a = 1") - if tk.Session().GetSessionVars().StmtCtx.ReadFromTableCache { - readFromTableCache = true - break - } - time.Sleep(50 * time.Millisecond) - } - require.True(t, readFromTableCache) - // already read cache after reading first time - tk.MustExec("prepare stmt from 'select * from t where a = ?';") - tk.MustExec("set @a = 1;") - tk.MustExec("execute stmt using @a;") - tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0")) - tk.MustExec("execute stmt using @a;") - readFromTableCache = tk.Session().GetSessionVars().StmtCtx.ReadFromTableCache - require.True(t, readFromTableCache) - tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("1")) -} - -func TestIssue16205(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("set tidb_enable_prepared_plan_cache=ON") - tk.MustExec("use test") - tk.MustExec("prepare stmt from 'select random_bytes(3)'") - rows1 := tk.MustQuery("execute stmt").Rows() - require.Len(t, rows1, 1) - rows2 := tk.MustQuery("execute stmt").Rows() - require.Len(t, rows2, 1) - require.NotEqual(t, rows1[0][0].(string), rows2[0][0].(string)) -} - -func TestRowCountPlanCache(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("set tidb_enable_prepared_plan_cache=ON") - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int auto_increment primary key)") - tk.MustExec("prepare stmt from 'select row_count()';") - tk.MustExec("insert into t values()") - res := tk.MustQuery("execute stmt").Rows() - require.Len(t, res, 1) - require.Equal(t, "1", res[0][0]) - tk.MustExec("insert into t values(),(),()") - res = tk.MustQuery("execute stmt").Rows() - require.Len(t, res, 1) - require.Equal(t, "3", res[0][0]) -} - -func TestCacheRegexpr(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("set tidb_enable_prepared_plan_cache=ON") - tk.MustExec("use test") - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t1 (a varchar(40))") - tk.MustExec("insert into t1 values ('C1'),('R1')") - tk.MustExec("prepare stmt1 from 'select a from t1 where a rlike ?'") - tk.MustExec("set @a='^C.*'") - tk.MustQuery("execute stmt1 using @a").Check(testkit.Rows("C1")) - tk.MustExec("set @a='^R.*'") - tk.MustQuery("execute stmt1 using @a").Check(testkit.Rows("R1")) -} - -func TestCacheRefineArgs(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("set tidb_enable_prepared_plan_cache=ON") - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(col_int int)") - tk.MustExec("insert into t values(null)") - tk.MustExec("prepare stmt from 'SELECT ((col_int is true) = ?) AS res FROM t'") - tk.MustExec("set @p0='0.8'") - tk.MustQuery("execute stmt using @p0").Check(testkit.Rows("0")) - tk.MustExec("set @p0='0'") - tk.MustQuery("execute stmt using @p0").Check(testkit.Rows("1")) - - tk.MustExec("prepare stmt from 'SELECT UCASE(?) < col_int from t;';") - tk.MustExec("set @a1 = 'xayh7vrWVNqZtzlJmdJQUwAHnkI8Ec';") - tk.MustQuery("execute stmt using @a1;").Check(testkit.Rows("")) - - tk.MustExec("delete from t") - tk.MustExec("insert into t values(1)") - tk.MustExec("prepare stmt from 'SELECT col_int < ? FROM t'") - tk.MustExec("set @p0='-184467440737095516167.1'") - tk.MustQuery("execute stmt using @p0").Check(testkit.Rows("0")) -} - -func TestCacheConstEval(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("set tidb_enable_prepared_plan_cache=ON") - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(col_double double)") - tk.MustExec("insert into t values (1)") - tk.Session().GetSessionVars().EnableVectorizedExpression = false - tk.MustExec("insert into mysql.expr_pushdown_blacklist values('cast', 'tikv,tiflash,tidb', 'for test')") - tk.MustExec("admin reload expr_pushdown_blacklist") - tk.MustExec("prepare stmt from 'SELECT * FROM (SELECT col_double AS c0 FROM t) t WHERE (ABS((REPEAT(?, ?) OR 5617780767323292672)) < LN(EXP(c0)) + (? ^ ?))'") - tk.MustExec("set @a1 = 'JuvkBX7ykVux20zQlkwDK2DFelgn7'") - tk.MustExec("set @a2 = 1") - tk.MustExec("set @a3 = -112990.35179796701") - tk.MustExec("set @a4 = 87997.92704840179") - // Main purpose here is checking no error is reported. 1 is the result when plan cache is disabled, it is - // incompatible with MySQL actually, update the result after fixing it. - tk.MustQuery("execute stmt using @a1, @a2, @a3, @a4").Check(testkit.Rows("1")) - tk.Session().GetSessionVars().EnableVectorizedExpression = true - tk.MustExec("delete from mysql.expr_pushdown_blacklist where name = 'cast' and store_type = 'tikv,tiflash,tidb' and reason = 'for test'") - tk.MustExec("admin reload expr_pushdown_blacklist") -} - -// issues 14448, 19383, 17734 -func TestNoopFunctions(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec(`set tidb_enable_non_prepared_plan_cache=0`) // variable changes in the test will not affect the plan cache - 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)") - - message := `.* has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions` - stmts := []string{ - "SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1", - "SELECT * FROM t1 LOCK IN SHARE MODE", - "SELECT * FROM t1 GROUP BY a DESC", - "SELECT * FROM t1 GROUP BY a ASC", - } - - for _, stmt := range stmts { - // test on - tk.MustExec("SET tidb_enable_noop_functions='ON'") - tk.MustExec(stmt) - // test warning - tk.MustExec("SET tidb_enable_noop_functions='WARN'") - tk.MustExec(stmt) - warn := tk.Session().GetSessionVars().StmtCtx.GetWarnings() - require.Regexp(t, message, warn[0].Err.Error()) - // test off - tk.MustExec("SET tidb_enable_noop_functions='OFF'") - _, err := tk.Exec(stmt) - require.Regexp(t, message, err.Error()) - } - - // These statements return a different error message - // to the above. Test for error, not specifically the message. - // After they execute, we need to reset the values because - // otherwise tidb_enable_noop_functions can't be changed. - - stmts = []string{ - "START TRANSACTION READ ONLY", - "SET TRANSACTION READ ONLY", - "SET tx_read_only = 1", - "SET transaction_read_only = 1", - } - - for _, stmt := range stmts { - // test off - tk.MustExec("SET tidb_enable_noop_functions='OFF'") - _, err := tk.Exec(stmt) - require.Error(t, err) - // test warning - tk.MustExec("SET tidb_enable_noop_functions='WARN'") - tk.MustExec(stmt) - warn := tk.Session().GetSessionVars().StmtCtx.GetWarnings() - require.Len(t, warn, 1) - // test on - tk.MustExec("SET tidb_enable_noop_functions='ON'") - tk.MustExec(stmt) - - // Reset (required for future loop iterations and future tests) - tk.MustExec("SET tx_read_only = 0") - tk.MustExec("SET transaction_read_only = 0") - } -} - -func TestCrossDCQuery(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t1") - tk.MustExec("drop placement policy if exists p1") - tk.MustExec("drop placement policy if exists p2") - tk.MustExec("create placement policy p1 leader_constraints='[+zone=sh]'") - tk.MustExec("create placement policy p2 leader_constraints='[+zone=bj]'") - tk.MustExec(`create table t1 (c int primary key, d int,e int,index idx_d(d),index idx_e(e)) -PARTITION BY RANGE (c) ( - PARTITION p0 VALUES LESS THAN (6) placement policy p1, - PARTITION p1 VALUES LESS THAN (11) placement policy p2 -);`) - defer func() { - tk.MustExec("drop table if exists t1") - tk.MustExec("drop placement policy if exists p1") - tk.MustExec("drop placement policy if exists p2") - }() - - tk.MustExec(`insert into t1 (c,d,e) values (1,1,1);`) - tk.MustExec(`insert into t1 (c,d,e) values (2,3,5);`) - tk.MustExec(`insert into t1 (c,d,e) values (3,5,7);`) - - testcases := []struct { - name string - txnScope string - zone string - sql string - expectErr error - }{ - // FIXME: block by https://github.com/pingcap/tidb/issues/21872 - //{ - // name: "cross dc read to sh by holding bj, IndexReader", - // txnScope: "bj", - // sql: "select /*+ USE_INDEX(t1, idx_d) */ d from t1 where c < 5 and d < 1;", - // expectErr: fmt.Errorf(".*can not be read by.*"), - //}, - // FIXME: block by https://github.com/pingcap/tidb/issues/21847 - //{ - // name: "cross dc read to sh by holding bj, BatchPointGet", - // txnScope: "bj", - // sql: "select * from t1 where c in (1,2,3,4);", - // expectErr: fmt.Errorf(".*can not be read by.*"), - //}, - { - name: "cross dc read to sh by holding bj, PointGet", - txnScope: "local", - zone: "bj", - sql: "select * from t1 where c = 1", - expectErr: fmt.Errorf(".*can not be read by.*"), - }, - { - name: "cross dc read to sh by holding bj, IndexLookUp", - txnScope: "local", - zone: "bj", - sql: "select * from t1 use index (idx_d) where c < 5 and d < 5;", - expectErr: fmt.Errorf(".*can not be read by.*"), - }, - { - name: "cross dc read to sh by holding bj, IndexMerge", - txnScope: "local", - zone: "bj", - sql: "select /*+ USE_INDEX_MERGE(t1, idx_d, idx_e) */ * from t1 where c <5 and (d =5 or e=5);", - expectErr: fmt.Errorf(".*can not be read by.*"), - }, - { - name: "cross dc read to sh by holding bj, TableReader", - txnScope: "local", - zone: "bj", - sql: "select * from t1 where c < 6", - expectErr: fmt.Errorf(".*can not be read by.*"), - }, - { - name: "cross dc read to global by holding bj", - txnScope: "local", - zone: "bj", - sql: "select * from t1", - expectErr: fmt.Errorf(".*can not be read by.*"), - }, - { - name: "read sh dc by holding sh", - txnScope: "local", - zone: "sh", - sql: "select * from t1 where c < 6", - expectErr: nil, - }, - { - name: "read sh dc by holding global", - txnScope: "global", - zone: "", - sql: "select * from t1 where c < 6", - expectErr: nil, - }, - } - tk.MustExec("set global tidb_enable_local_txn = on;") - for _, testcase := range testcases { - t.Log(testcase.name) - require.NoError(t, failpoint.Enable("tikvclient/injectTxnScope", - fmt.Sprintf(`return("%v")`, testcase.zone))) - tk.MustExec(fmt.Sprintf("set @@txn_scope='%v'", testcase.txnScope)) - tk.Exec("begin") - res, err := tk.Exec(testcase.sql) - _, resErr := session.GetRows4Test(context.Background(), tk.Session(), res) - var checkErr error - if err != nil { - checkErr = err - } else { - checkErr = resErr - } - if testcase.expectErr != nil { - require.Error(t, checkErr) - require.Regexp(t, ".*can not be read by.*", checkErr.Error()) - } else { - require.NoError(t, checkErr) - } - if res != nil { - res.Close() - } - tk.Exec("commit") - } - require.NoError(t, failpoint.Disable("tikvclient/injectTxnScope")) - tk.MustExec("set global tidb_enable_local_txn = off;") -} - -func TestTiDBRowChecksumBuiltin(t *testing.T) { - store := testkit.CreateMockStore(t) - - checksum := func(cols ...interface{}) uint32 { - buf := make([]byte, 0, 64) - for _, col := range cols { - switch x := col.(type) { - case int: - buf = binary.LittleEndian.AppendUint64(buf, uint64(x)) - case string: - buf = binary.LittleEndian.AppendUint32(buf, uint32(len(x))) - buf = append(buf, []byte(x)...) - } - } - return crc32.ChecksumIEEE(buf) - } - - tk := testkit.NewTestKit(t, store) - tk.MustExec("set global tidb_enable_row_level_checksum = 1") - tk.MustExec("use test") - tk.MustExec("create table t (id int primary key, c int)") - - // row with 2 checksums - tk.MustExec("insert into t values (1, 10)") - tk.MustExec("alter table t change column c c varchar(10)") - checksum1 := fmt.Sprintf("%d,%d", checksum(1, 10), checksum(1, "10")) - // row with 1 checksum - tk.Session().GetSessionVars().EnableRowLevelChecksum = true - tk.MustExec("insert into t values (2, '20')") - checksum2 := fmt.Sprintf("%d", checksum(2, "20")) - // row without checksum - tk.Session().GetSessionVars().EnableRowLevelChecksum = false - tk.MustExec("insert into t values (3, '30')") - checksum3 := "" - - // fast point-get - tk.MustQuery("select tidb_row_checksum() from t where id = 1").Check(testkit.Rows(checksum1)) - tk.MustQuery("select tidb_row_checksum() from t where id = 2").Check(testkit.Rows(checksum2)) - tk.MustQuery("select tidb_row_checksum() from t where id = 3").Check(testkit.Rows(checksum3)) - // fast batch-point-get - tk.MustQuery("select tidb_row_checksum() from t where id in (1, 2, 3)").Check(testkit.Rows(checksum1, checksum2, checksum3)) - - // non-fast point-get - tk.MustGetDBError("select length(tidb_row_checksum()) from t where id = 1", expression.ErrNotSupportedYet) - tk.MustGetDBError("select c from t where id = 1 and tidb_row_checksum() is not null", expression.ErrNotSupportedYet) - // non-fast batch-point-get - tk.MustGetDBError("select length(tidb_row_checksum()) from t where id in (1, 2, 3)", expression.ErrNotSupportedYet) - tk.MustGetDBError("select c from t where id in (1, 2, 3) and tidb_row_checksum() is not null", expression.ErrNotSupportedYet) - - // other plans - tk.MustGetDBError("select tidb_row_checksum() from t", expression.ErrNotSupportedYet) - tk.MustGetDBError("select tidb_row_checksum() from t where id > 0", expression.ErrNotSupportedYet) -} diff --git a/expression/integration_serial_test/main_test.go b/expression/integration_serial_test/main_test.go deleted file mode 100644 index ec5032f96f721..0000000000000 --- a/expression/integration_serial_test/main_test.go +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2023 PingCAP, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package integration_serial_test - -import ( - "testing" - - "github.com/pingcap/tidb/config" - "github.com/pingcap/tidb/testkit/testmain" - "github.com/pingcap/tidb/testkit/testsetup" - "github.com/pingcap/tidb/util/timeutil" - "github.com/tikv/client-go/v2/tikv" - "go.uber.org/goleak" -) - -func TestMain(m *testing.M) { - testsetup.SetupForCommonTest() - testmain.ShortCircuitForBench(m) - - config.UpdateGlobal(func(conf *config.Config) { - conf.TiKVClient.AsyncCommit.SafeWindow = 0 - conf.TiKVClient.AsyncCommit.AllowedClockDrift = 0 - conf.Experimental.AllowsExpressionIndex = true - }) - tikv.EnableFailpoints() - - // Some test depends on the values of timeutil.SystemLocation() - // If we don't SetSystemTZ() here, the value would change unpredictable. - // Affected by the order whether a testsuite runs before or after integration test. - // Note, SetSystemTZ() is a sync.Once operation. - timeutil.SetSystemTZ("system") - - opts := []goleak.Option{ - goleak.IgnoreTopFunction("github.com/golang/glog.(*fileSink).flushDaemon"), - goleak.IgnoreTopFunction("github.com/lestrrat-go/httprc.runFetchWorker"), - goleak.IgnoreTopFunction("go.etcd.io/etcd/client/pkg/v3/logutil.(*MergeLogger).outputLoop"), - goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"), - } - - goleak.VerifyTestMain(m, opts...) -} diff --git a/expression/integration_test/BUILD.bazel b/expression/integration_test/BUILD.bazel index 7305f7f9d7a86..c966c65cda3c8 100644 --- a/expression/integration_test/BUILD.bazel +++ b/expression/integration_test/BUILD.bazel @@ -8,7 +8,7 @@ go_test( "main_test.go", ], flaky = True, - shard_count = 27, + shard_count = 28, deps = [ "//config", "//domain", @@ -34,8 +34,10 @@ go_test( "//util/timeutil", "//util/versioninfo", "@com_github_pingcap_errors//:errors", + "@com_github_pingcap_failpoint//:failpoint", "@com_github_stretchr_testify//assert", "@com_github_stretchr_testify//require", + "@com_github_tikv_client_go_v2//oracle", "@com_github_tikv_client_go_v2//tikv", "@org_uber_go_goleak//:goleak", ], diff --git a/expression/integration_test/integration_test.go b/expression/integration_test/integration_test.go index 5901c4c56b15f..682706d5e21a2 100644 --- a/expression/integration_test/integration_test.go +++ b/expression/integration_test/integration_test.go @@ -17,8 +17,11 @@ package integration_test import ( "bytes" "context" + "encoding/binary" "encoding/hex" "fmt" + "hash/crc32" + "math" "math/rand" "sort" "strconv" @@ -27,6 +30,7 @@ import ( "time" "github.com/pingcap/errors" + "github.com/pingcap/failpoint" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/errno" @@ -49,6 +53,7 @@ import ( "github.com/pingcap/tidb/util/versioninfo" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/tikv/client-go/v2/oracle" ) func TestGetLock(t *testing.T) { @@ -194,302 +199,6 @@ func TestGetLock(t *testing.T) { tk.MustQuery("SELECT release_all_locks()").Check(testkit.Rows("0")) } -func TestMiscellaneousBuiltin(t *testing.T) { - ctx := context.Background() - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - // for uuid - r := tk.MustQuery("select uuid(), uuid(), uuid(), uuid(), uuid(), uuid();") - for _, it := range r.Rows() { - for _, item := range it { - uuid, ok := item.(string) - require.True(t, ok) - list := strings.Split(uuid, "-") - require.Len(t, list, 5) - require.Len(t, list[0], 8) - require.Len(t, list[1], 4) - require.Len(t, list[2], 4) - require.Len(t, list[3], 4) - require.Len(t, list[4], 12) - } - } - tk.MustQuery("select sleep(1);").Check(testkit.Rows("0")) - tk.MustQuery("select sleep(0);").Check(testkit.Rows("0")) - tk.MustQuery("select sleep('a');").Check(testkit.Rows("0")) - tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1292 Truncated incorrect DOUBLE value: 'a'")) - rs, err := tk.Exec("select sleep(-1);") - require.NoError(t, err) - require.NotNil(t, rs) - _, err = session.GetRows4Test(ctx, tk.Session(), rs) - require.Error(t, err) - require.NoError(t, rs.Close()) - - tk.MustQuery("SELECT INET_ATON('10.0.5.9');").Check(testkit.Rows("167773449")) - tk.MustQuery("SELECT INET_NTOA(167773449);").Check(testkit.Rows("10.0.5.9")) - tk.MustQuery("SELECT HEX(INET6_ATON('fdfe::5a55:caff:fefa:9089'));").Check(testkit.Rows("FDFE0000000000005A55CAFFFEFA9089")) - tk.MustQuery("SELECT HEX(INET6_ATON('10.0.5.9'));").Check(testkit.Rows("0A000509")) - tk.MustQuery("SELECT INET6_NTOA(INET6_ATON('fdfe::5a55:caff:fefa:9089'));").Check(testkit.Rows("fdfe::5a55:caff:fefa:9089")) - tk.MustQuery("SELECT INET6_NTOA(INET6_ATON('10.0.5.9'));").Check(testkit.Rows("10.0.5.9")) - tk.MustQuery("SELECT INET6_NTOA(UNHEX('FDFE0000000000005A55CAFFFEFA9089'));").Check(testkit.Rows("fdfe::5a55:caff:fefa:9089")) - tk.MustQuery("SELECT INET6_NTOA(UNHEX('0A000509'));").Check(testkit.Rows("10.0.5.9")) - - tk.MustQuery(`SELECT IS_IPV4('10.0.5.9'), IS_IPV4('10.0.5.256');`).Check(testkit.Rows("1 0")) - tk.MustQuery(`SELECT IS_IPV4_COMPAT(INET6_ATON('::10.0.5.9'));`).Check(testkit.Rows("1")) - tk.MustQuery(`SELECT IS_IPV4_COMPAT(INET6_ATON('::ffff:10.0.5.9'));`).Check(testkit.Rows("0")) - tk.MustQuery(`SELECT - IS_IPV4_COMPAT(INET6_ATON('::192.168.0.1')), - IS_IPV4_COMPAT(INET6_ATON('::c0a8:0001')), - IS_IPV4_COMPAT(INET6_ATON('::c0a8:1'));`).Check(testkit.Rows("1 1 1")) - tk.MustQuery(`SELECT IS_IPV4_MAPPED(INET6_ATON('::10.0.5.9'));`).Check(testkit.Rows("0")) - tk.MustQuery(`SELECT IS_IPV4_MAPPED(INET6_ATON('::ffff:10.0.5.9'));`).Check(testkit.Rows("1")) - tk.MustQuery(`SELECT - IS_IPV4_MAPPED(INET6_ATON('::ffff:192.168.0.1')), - IS_IPV4_MAPPED(INET6_ATON('::ffff:c0a8:0001')), - IS_IPV4_MAPPED(INET6_ATON('::ffff:c0a8:1'));`).Check(testkit.Rows("1 1 1")) - tk.MustQuery(`SELECT IS_IPV6('10.0.5.9'), IS_IPV6('::1');`).Check(testkit.Rows("0 1")) - - tk.MustExec("drop table if exists t1;") - tk.MustExec(`create table t1( - a int, - b int not null, - c int not null default 0, - d int default 0, - unique key(b,c), - unique key(b,d) -);`) - tk.MustExec("insert into t1 (a,b) values(1,10),(1,20),(2,30),(2,40);") - tk.MustQuery("select any_value(a), sum(b) from t1;").Check(testkit.Rows("1 100")) - tk.MustQuery("select a,any_value(b),sum(c) from t1 group by a order by a;").Check(testkit.Rows("1 10 0", "2 30 0")) - - // for locks - result := tk.MustQuery(`SELECT GET_LOCK('test_lock1', 10);`) - result.Check(testkit.Rows("1")) - result = tk.MustQuery(`SELECT GET_LOCK('test_lock2', 10);`) - result.Check(testkit.Rows("1")) - - result = tk.MustQuery(`SELECT IS_USED_LOCK('test_lock1') = CONNECTION_ID();`) - result.Check(testkit.Rows("1")) - result = tk.MustQuery(`SELECT IS_USED_LOCK('foobar');`) - result.Check(testkit.Rows("")) - - result = tk.MustQuery(`SELECT IS_FREE_LOCK('test_lock1');`) - result.Check(testkit.Rows("0")) - result = tk.MustQuery(`SELECT IS_FREE_LOCK('foobar');`) - result.Check(testkit.Rows("1")) - - result = tk.MustQuery(`SELECT RELEASE_LOCK('test_lock2');`) - result.Check(testkit.Rows("1")) - result = tk.MustQuery(`SELECT RELEASE_LOCK('test_lock1');`) - result.Check(testkit.Rows("1")) - result = tk.MustQuery(`SELECT RELEASE_LOCK('test_lock3');`) // not acquired - result.Check(testkit.Rows("0")) - tk.MustQuery(`SELECT RELEASE_ALL_LOCKS()`).Check(testkit.Rows("0")) // none acquired -} - -func TestEncryptionBuiltin(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.Session().GetSessionVars().User = &auth.UserIdentity{Username: "root"} - ctx := context.Background() - - // for password - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a char(41), b char(41), c char(41))") - tk.MustExec(`insert into t values(NULL, '', 'abc')`) - result := tk.MustQuery("select password(a) from t") - result.Check(testkit.Rows("")) - result = tk.MustQuery("select password(b) from t") - result.Check(testkit.Rows("")) - result = tk.MustQuery("select password(c) from t") - result.Check(testkit.Rows("*0D3CED9BEC10A777AEC23CCC353A8C08A633045E")) - - // for md5 - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a char(10), b int, c double, d datetime, e time, f bit(4), g binary(20), h blob(10), i text(30))") - tk.MustExec(`insert into t values('2', 2, 2.3, "2017-01-01 12:01:01", "12:01:01", 0b1010, "512", "48", "tidb")`) - result = tk.MustQuery("select md5(a), md5(b), md5(c), md5(d), md5(e), md5(f), md5(g), md5(h), md5(i) from t") - result.Check(testkit.Rows("c81e728d9d4c2f636f067f89cc14862c c81e728d9d4c2f636f067f89cc14862c 1a18da63cbbfb49cb9616e6bfd35f662 bad2fa88e1f35919ec7584cc2623a310 991f84d41d7acff6471e536caa8d97db 68b329da9893e34099c7d8ad5cb9c940 5c9f0e9b3b36276731bfba852a73ccc6 642e92efb79421734881b53e1e1b18b6 c337e11bfca9f12ae9b1342901e04379")) - result = tk.MustQuery("select md5('123'), md5(123), md5(''), md5('你好'), md5(NULL), md5('👍')") - result.Check(testkit.Rows(`202cb962ac59075b964b07152d234b70 202cb962ac59075b964b07152d234b70 d41d8cd98f00b204e9800998ecf8427e 7eca689f0d3389d9dea66ae112e5cfd7 0215ac4dab1ecaf71d83f98af5726984`)) - - // for sha/sha1 - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a char(10), b int, c double, d datetime, e time, f bit(4), g binary(20), h blob(10), i text(30))") - tk.MustExec(`insert into t values('2', 2, 2.3, "2017-01-01 12:01:01", "12:01:01", 0b1010, "512", "48", "tidb")`) - result = tk.MustQuery("select sha1(a), sha1(b), sha1(c), sha1(d), sha1(e), sha1(f), sha1(g), sha1(h), sha1(i) from t") - result.Check(testkit.Rows("da4b9237bacccdf19c0760cab7aec4a8359010b0 da4b9237bacccdf19c0760cab7aec4a8359010b0 ce0d88c5002b6cf7664052f1fc7d652cbdadccec 6c6956de323692298e4e5ad3028ff491f7ad363c 1906f8aeb5a717ca0f84154724045839330b0ea9 adc83b19e793491b1c6ea0fd8b46cd9f32e592fc 9aadd14ceb737b28697b8026f205f4b3e31de147 64e095fe763fc62418378753f9402623bea9e227 4df56fc09a3e66b48fb896e90b0a6fc02c978e9e")) - result = tk.MustQuery("select sha1('123'), sha1(123), sha1(''), sha1('你好'), sha1(NULL)") - result.Check(testkit.Rows(`40bd001563085fc35165329ea1ff5c5ecbdbbeef 40bd001563085fc35165329ea1ff5c5ecbdbbeef da39a3ee5e6b4b0d3255bfef95601890afd80709 440ee0853ad1e99f962b63e459ef992d7c211722 `)) - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a char(10), b int, c double, d datetime, e time, f bit(4), g binary(20), h blob(10), i text(30))") - tk.MustExec(`insert into t values('2', 2, 2.3, "2017-01-01 12:01:01", "12:01:01", 0b1010, "512", "48", "tidb")`) - result = tk.MustQuery("select sha(a), sha(b), sha(c), sha(d), sha(e), sha(f), sha(g), sha(h), sha(i) from t") - result.Check(testkit.Rows("da4b9237bacccdf19c0760cab7aec4a8359010b0 da4b9237bacccdf19c0760cab7aec4a8359010b0 ce0d88c5002b6cf7664052f1fc7d652cbdadccec 6c6956de323692298e4e5ad3028ff491f7ad363c 1906f8aeb5a717ca0f84154724045839330b0ea9 adc83b19e793491b1c6ea0fd8b46cd9f32e592fc 9aadd14ceb737b28697b8026f205f4b3e31de147 64e095fe763fc62418378753f9402623bea9e227 4df56fc09a3e66b48fb896e90b0a6fc02c978e9e")) - result = tk.MustQuery("select sha('123'), sha(123), sha(''), sha('你好'), sha(NULL)") - result.Check(testkit.Rows(`40bd001563085fc35165329ea1ff5c5ecbdbbeef 40bd001563085fc35165329ea1ff5c5ecbdbbeef da39a3ee5e6b4b0d3255bfef95601890afd80709 440ee0853ad1e99f962b63e459ef992d7c211722 `)) - - // for sha2 - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a char(10), b int, c double, d datetime, e time, f bit(4), g binary(20), h blob(10), i text(30))") - tk.MustExec(`insert into t values('2', 2, 2.3, "2017-01-01 12:01:01", "12:01:01", 0b1010, "512", "48", "tidb")`) - result = tk.MustQuery("select sha2(a, 224), sha2(b, 0), sha2(c, 512), sha2(d, 256), sha2(e, 384), sha2(f, 0), sha2(g, 512), sha2(h, 256), sha2(i, 224) from t") - result.Check(testkit.Rows("58b2aaa0bfae7acc021b3260e941117b529b2e69de878fd7d45c61a9 d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35 42415572557b0ca47e14fa928e83f5746d33f90c74270172cc75c61a78db37fe1485159a4fd75f33ab571b154572a5a300938f7d25969bdd05d8ac9dd6c66123 8c2fa3f276952c92b0b40ed7d27454e44b8399a19769e6bceb40da236e45a20a b11d35f1a37e54d5800d210d8e6b80b42c9f6d20ea7ae548c762383ebaa12c5954c559223c6c7a428e37af96bb4f1e0d 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 9550da35ea1683abaf5bfa8de68fe02b9c6d756c64589d1ef8367544c254f5f09218a6466cadcee8d74214f0c0b7fb342d1a9f3bd4d406aacf7be59c327c9306 98010bd9270f9b100b6214a21754fd33bdc8d41b2bc9f9dd16ff54d3c34ffd71 a7cddb7346fbc66ab7f803e865b74cbd99aace8e7dabbd8884c148cb")) - result = tk.MustQuery("select sha2('123', 512), sha2(123, 512), sha2('', 512), sha2('你好', 224), sha2(NULL, 256), sha2('foo', 123)") - result.Check(testkit.Rows(`3c9909afec25354d551dae21590bb26e38d53f2173b8d3dc3eee4c047e7ab1c1eb8b85103e3be7ba613b31bb5c9c36214dc9f14a42fd7a2fdb84856bca5c44c2 3c9909afec25354d551dae21590bb26e38d53f2173b8d3dc3eee4c047e7ab1c1eb8b85103e3be7ba613b31bb5c9c36214dc9f14a42fd7a2fdb84856bca5c44c2 cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e e91f006ed4e0882de2f6a3c96ec228a6a5c715f356d00091bce842b5 `)) - - // for sm3 - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a char(10), b int, c double, d datetime, e time, f bit(4), g binary(20), h blob(10), i text(30))") - tk.MustExec(`insert into t values('2', 2, 2.3, "2017-01-01 12:01:01", "12:01:01", 0b1010, "512", "48", "tidb")`) - result = tk.MustQuery("select sm3(a), sm3(b), sm3(c), sm3(d), sm3(e), sm3(f), sm3(g), sm3(h), sm3(i) from t") - result.Check(testkit.Rows("a0dc2d74b9b0e3c87e076003dbfe472a424cb3032463cb339e351460765a822e a0dc2d74b9b0e3c87e076003dbfe472a424cb3032463cb339e351460765a822e b01f6234a2c1d98af2d8bfb79a8c95677c6e9f5750eb756890f29b33b712f804 8485b2ccde69acf41e333e8fba2f55a1b3556e1a42443095235db1d5c78b25d1 f71ab1aad211e14a47b549e8df55b627c36fa75c1aa75b9682cccae2de00babc f4051d239b766c4111e92979aa31af0b35def053646e347bc41e8b73cfd080bc d42cb1657149a8057cef0ba0ededef7f23c9a2f133bfd286ad0f4a6a8bdb5cb2 19dfccdab83e610f04c414a96edb45007b9a022af01473fccf2073b546ad092e 5e0fb8467c33dae5879fb296c9766c78b0a6fc966372f76ac000cc1fcafc2876")) - result = tk.MustQuery("select sm3('123'), sm3(123), sm3(''), sm3('你好'), sm3(NULL)") - result.Check(testkit.Rows(`6e0f9e14344c5406a0cf5a3b4dfb665f87f4a771a31f7edbb5c72874a32b2957 6e0f9e14344c5406a0cf5a3b4dfb665f87f4a771a31f7edbb5c72874a32b2957 1ab21d8355cfa17f8e61194831e81a8f22bec8c728fefb747ed035eb5082aa2b 78e5c78c5322ca174089e58dc7790acf8ce9d542bee6ae4a5a0797d5e356be61 `)) - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a char(10), b int, c double, d datetime, e time, f bit(4), g binary(20), h blob(10), i text(30))") - tk.MustExec(`insert into t values('2', 2, 2.3, "2017-01-01 12:01:01", "12:01:01", 0b1010, "512", "48", "tidb")`) - result = tk.MustQuery("select sm3(a), sm3(b), sm3(c), sm3(d), sm3(e), sm3(f), sm3(g), sm3(h), sm3(i) from t") - result.Check(testkit.Rows("a0dc2d74b9b0e3c87e076003dbfe472a424cb3032463cb339e351460765a822e a0dc2d74b9b0e3c87e076003dbfe472a424cb3032463cb339e351460765a822e b01f6234a2c1d98af2d8bfb79a8c95677c6e9f5750eb756890f29b33b712f804 8485b2ccde69acf41e333e8fba2f55a1b3556e1a42443095235db1d5c78b25d1 f71ab1aad211e14a47b549e8df55b627c36fa75c1aa75b9682cccae2de00babc f4051d239b766c4111e92979aa31af0b35def053646e347bc41e8b73cfd080bc d42cb1657149a8057cef0ba0ededef7f23c9a2f133bfd286ad0f4a6a8bdb5cb2 19dfccdab83e610f04c414a96edb45007b9a022af01473fccf2073b546ad092e 5e0fb8467c33dae5879fb296c9766c78b0a6fc966372f76ac000cc1fcafc2876")) - result = tk.MustQuery("select sm3('123'), sm3(123), sm3(''), sm3('你好'), sm3(NULL)") - result.Check(testkit.Rows(`6e0f9e14344c5406a0cf5a3b4dfb665f87f4a771a31f7edbb5c72874a32b2957 6e0f9e14344c5406a0cf5a3b4dfb665f87f4a771a31f7edbb5c72874a32b2957 1ab21d8355cfa17f8e61194831e81a8f22bec8c728fefb747ed035eb5082aa2b 78e5c78c5322ca174089e58dc7790acf8ce9d542bee6ae4a5a0797d5e356be61 `)) - - // for AES_ENCRYPT - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a char(10), b int, c double, d datetime, e time, f bit(4), g binary(20), h blob(10), i text(30))") - tk.MustExec(`insert into t values('2', 2, 2.3, "2017-01-01 12:01:01", "12:01:01", 0b1010, "512", "48", "tidb")`) - tk.MustExec("SET block_encryption_mode='aes-128-ecb';") - result = tk.MustQuery("select HEX(AES_ENCRYPT(a, 'key')), HEX(AES_ENCRYPT(b, 'key')), HEX(AES_ENCRYPT(c, 'key')), HEX(AES_ENCRYPT(d, 'key')), HEX(AES_ENCRYPT(e, 'key')), HEX(AES_ENCRYPT(f, 'key')), HEX(AES_ENCRYPT(g, 'key')), HEX(AES_ENCRYPT(h, 'key')), HEX(AES_ENCRYPT(i, 'key')) from t") - result.Check(testkit.Rows("B3800B3A3CB4ECE2051A3E80FE373EAC B3800B3A3CB4ECE2051A3E80FE373EAC 9E018F7F2838DBA23C57F0E4CCF93287 E764D3E9D4AF8F926CD0979DDB1D0AF40C208B20A6C39D5D028644885280973A C452FFEEB76D3F5E9B26B8D48F7A228C 181BD5C81CBD36779A3C9DD5FF486B35 CE15F14AC7FF4E56ECCF148DE60E4BEDBDB6900AD51383970A5F32C59B3AC6E3 E1B29995CCF423C75519790F54A08CD2 84525677E95AC97698D22E1125B67E92")) - result = tk.MustQuery("select HEX(AES_ENCRYPT('123', 'foobar')), HEX(AES_ENCRYPT(123, 'foobar')), HEX(AES_ENCRYPT('', 'foobar')), HEX(AES_ENCRYPT('你好', 'foobar')), AES_ENCRYPT(NULL, 'foobar')") - result.Check(testkit.Rows(`45ABDD5C4802EFA6771A94C43F805208 45ABDD5C4802EFA6771A94C43F805208 791F1AEB6A6B796E6352BF381895CA0E D0147E2EB856186F146D9F6DE33F9546 `)) - result = tk.MustQuery("select HEX(AES_ENCRYPT(a, 'key', 'iv')), HEX(AES_ENCRYPT(b, 'key', 'iv')) from t") - result.Check(testkit.Rows("B3800B3A3CB4ECE2051A3E80FE373EAC B3800B3A3CB4ECE2051A3E80FE373EAC")) - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1618| option ignored", "Warning|1618| option ignored")) - tk.MustExec("SET block_encryption_mode='aes-128-cbc';") - result = tk.MustQuery("select HEX(AES_ENCRYPT(a, 'key', '1234567890123456')), HEX(AES_ENCRYPT(b, 'key', '1234567890123456')), HEX(AES_ENCRYPT(c, 'key', '1234567890123456')), HEX(AES_ENCRYPT(d, 'key', '1234567890123456')), HEX(AES_ENCRYPT(e, 'key', '1234567890123456')), HEX(AES_ENCRYPT(f, 'key', '1234567890123456')), HEX(AES_ENCRYPT(g, 'key', '1234567890123456')), HEX(AES_ENCRYPT(h, 'key', '1234567890123456')), HEX(AES_ENCRYPT(i, 'key', '1234567890123456')) from t") - result.Check(testkit.Rows("341672829F84CB6B0BE690FEC4C4DAE9 341672829F84CB6B0BE690FEC4C4DAE9 D43734E147A12BB96C6897C4BBABA283 16F2C972411948DCEF3659B726D2CCB04AD1379A1A367FA64242058A50211B67 41E71D0C58967C1F50EEC074523946D1 1117D292E2D39C3EAA3B435371BE56FC 8ACB7ECC0883B672D7BD1CFAA9FA5FAF5B731ADE978244CD581F114D591C2E7E D2B13C30937E3251AEDA73859BA32E4B 2CF4A6051FF248A67598A17AA2C17267")) - result = tk.MustQuery("select HEX(AES_ENCRYPT('123', 'foobar', '1234567890123456')), HEX(AES_ENCRYPT(123, 'foobar', '1234567890123456')), HEX(AES_ENCRYPT('', 'foobar', '1234567890123456')), HEX(AES_ENCRYPT('你好', 'foobar', '1234567890123456')), AES_ENCRYPT(NULL, 'foobar', '1234567890123456')") - result.Check(testkit.Rows(`80D5646F07B4654B05A02D9085759770 80D5646F07B4654B05A02D9085759770 B3C14BA15030D2D7E99376DBE011E752 0CD2936EE4FEC7A8CDF6208438B2BC05 `)) - tk.MustExec("SET block_encryption_mode='aes-128-ofb';") - result = tk.MustQuery("select HEX(AES_ENCRYPT(a, 'key', '1234567890123456')), HEX(AES_ENCRYPT(b, 'key', '1234567890123456')), HEX(AES_ENCRYPT(c, 'key', '1234567890123456')), HEX(AES_ENCRYPT(d, 'key', '1234567890123456')), HEX(AES_ENCRYPT(e, 'key', '1234567890123456')), HEX(AES_ENCRYPT(f, 'key', '1234567890123456')), HEX(AES_ENCRYPT(g, 'key', '1234567890123456')), HEX(AES_ENCRYPT(h, 'key', '1234567890123456')), HEX(AES_ENCRYPT(i, 'key', '1234567890123456')) from t") - result.Check(testkit.Rows("40 40 40C35C 40DD5EBDFCAA397102386E27DDF97A39ECCEC5 43DF55BAE0A0386D 78 47DC5D8AD19A085C32094E16EFC34A08D6FEF459 46D5 06840BE8")) - result = tk.MustQuery("select HEX(AES_ENCRYPT('123', 'foobar', '1234567890123456')), HEX(AES_ENCRYPT(123, 'foobar', '1234567890123456')), HEX(AES_ENCRYPT('', 'foobar', '1234567890123456')), HEX(AES_ENCRYPT('你好', 'foobar', '1234567890123456')), AES_ENCRYPT(NULL, 'foobar', '1234567890123456')") - result.Check(testkit.Rows(`48E38A 48E38A 9D6C199101C3 `)) - tk.MustExec("SET block_encryption_mode='aes-192-ofb';") - result = tk.MustQuery("select HEX(AES_ENCRYPT(a, 'key', '1234567890123456')), HEX(AES_ENCRYPT(b, 'key', '1234567890123456')), HEX(AES_ENCRYPT(c, 'key', '1234567890123456')), HEX(AES_ENCRYPT(d, 'key', '1234567890123456')), HEX(AES_ENCRYPT(e, 'key', '1234567890123456')), HEX(AES_ENCRYPT(f, 'key', '1234567890123456')), HEX(AES_ENCRYPT(g, 'key', '1234567890123456')), HEX(AES_ENCRYPT(h, 'key', '1234567890123456')), HEX(AES_ENCRYPT(i, 'key', '1234567890123456')) from t") - result.Check(testkit.Rows("4B 4B 4B573F 4B493D42572E6477233A429BF3E0AD39DB816D 484B36454B24656B 73 4C483E757A1E555A130B62AAC1DA9D08E1B15C47 4D41 0D106817")) - result = tk.MustQuery("select HEX(AES_ENCRYPT('123', 'foobar', '1234567890123456')), HEX(AES_ENCRYPT(123, 'foobar', '1234567890123456')), HEX(AES_ENCRYPT('', 'foobar', '1234567890123456')), HEX(AES_ENCRYPT('你好', 'foobar', '1234567890123456')), AES_ENCRYPT(NULL, 'foobar', '1234567890123456')") - result.Check(testkit.Rows(`3A76B0 3A76B0 EFF92304268E `)) - tk.MustExec("SET block_encryption_mode='aes-256-ofb';") - result = tk.MustQuery("select HEX(AES_ENCRYPT(a, 'key', '1234567890123456')), HEX(AES_ENCRYPT(b, 'key', '1234567890123456')), HEX(AES_ENCRYPT(c, 'key', '1234567890123456')), HEX(AES_ENCRYPT(d, 'key', '1234567890123456')), HEX(AES_ENCRYPT(e, 'key', '1234567890123456')), HEX(AES_ENCRYPT(f, 'key', '1234567890123456')), HEX(AES_ENCRYPT(g, 'key', '1234567890123456')), HEX(AES_ENCRYPT(h, 'key', '1234567890123456')), HEX(AES_ENCRYPT(i, 'key', '1234567890123456')) from t") - result.Check(testkit.Rows("16 16 16D103 16CF01CBC95D33E2ED721CBD930262415A69AD 15CD0ACCD55732FE 2E 11CE02FCE46D02CFDD433C8CA138527060599C35 10C7 5096549E")) - result = tk.MustQuery("select HEX(AES_ENCRYPT('123', 'foobar', '1234567890123456')), HEX(AES_ENCRYPT(123, 'foobar', '1234567890123456')), HEX(AES_ENCRYPT('', 'foobar', '1234567890123456')), HEX(AES_ENCRYPT('你好', 'foobar', '1234567890123456')), AES_ENCRYPT(NULL, 'foobar', '1234567890123456')") - result.Check(testkit.Rows(`E842C5 E842C5 3DCD5646767D `)) - - // for AES_DECRYPT - tk.MustExec("SET block_encryption_mode='aes-128-ecb';") - result = tk.MustQuery("select AES_DECRYPT(AES_ENCRYPT('foo', 'bar'), 'bar')") - result.Check(testkit.Rows("foo")) - result = tk.MustQuery("select AES_DECRYPT(UNHEX('45ABDD5C4802EFA6771A94C43F805208'), 'foobar'), AES_DECRYPT(UNHEX('791F1AEB6A6B796E6352BF381895CA0E'), 'foobar'), AES_DECRYPT(UNHEX('D0147E2EB856186F146D9F6DE33F9546'), 'foobar'), AES_DECRYPT(NULL, 'foobar'), AES_DECRYPT('SOME_THING_STRANGE', 'foobar')") - result.Check(testkit.Rows(`123 你好 `)) - tk.MustExec("SET block_encryption_mode='aes-128-cbc';") - result = tk.MustQuery("select AES_DECRYPT(AES_ENCRYPT('foo', 'bar', '1234567890123456'), 'bar', '1234567890123456')") - result.Check(testkit.Rows("foo")) - result = tk.MustQuery("select AES_DECRYPT(UNHEX('80D5646F07B4654B05A02D9085759770'), 'foobar', '1234567890123456'), AES_DECRYPT(UNHEX('B3C14BA15030D2D7E99376DBE011E752'), 'foobar', '1234567890123456'), AES_DECRYPT(UNHEX('0CD2936EE4FEC7A8CDF6208438B2BC05'), 'foobar', '1234567890123456'), AES_DECRYPT(NULL, 'foobar', '1234567890123456'), AES_DECRYPT('SOME_THING_STRANGE', 'foobar', '1234567890123456')") - result.Check(testkit.Rows(`123 你好 `)) - tk.MustExec("SET block_encryption_mode='aes-128-ofb';") - result = tk.MustQuery("select AES_DECRYPT(AES_ENCRYPT('foo', 'bar', '1234567890123456'), 'bar', '1234567890123456')") - result.Check(testkit.Rows("foo")) - result = tk.MustQuery("select AES_DECRYPT(UNHEX('48E38A'), 'foobar', '1234567890123456'), AES_DECRYPT(UNHEX(''), 'foobar', '1234567890123456'), AES_DECRYPT(UNHEX('9D6C199101C3'), 'foobar', '1234567890123456'), AES_DECRYPT(NULL, 'foobar', '1234567890123456'), HEX(AES_DECRYPT('SOME_THING_STRANGE', 'foobar', '1234567890123456'))") - result.Check(testkit.Rows(`123 你好 2A9EF431FB2ACB022D7F2E7C71EEC48C7D2B`)) - tk.MustExec("SET block_encryption_mode='aes-192-ofb';") - result = tk.MustQuery("select AES_DECRYPT(AES_ENCRYPT('foo', 'bar', '1234567890123456'), 'bar', '1234567890123456')") - result.Check(testkit.Rows("foo")) - result = tk.MustQuery("select AES_DECRYPT(UNHEX('3A76B0'), 'foobar', '1234567890123456'), AES_DECRYPT(UNHEX(''), 'foobar', '1234567890123456'), AES_DECRYPT(UNHEX('EFF92304268E'), 'foobar', '1234567890123456'), AES_DECRYPT(NULL, 'foobar', '1234567890123456'), HEX(AES_DECRYPT('SOME_THING_STRANGE', 'foobar', '1234567890123456'))") - result.Check(testkit.Rows(`123 你好 580BCEA4DC67CF33FF2C7C570D36ECC89437`)) - tk.MustExec("SET block_encryption_mode='aes-256-ofb';") - result = tk.MustQuery("select AES_DECRYPT(AES_ENCRYPT('foo', 'bar', '1234567890123456'), 'bar', '1234567890123456')") - result.Check(testkit.Rows("foo")) - result = tk.MustQuery("select AES_DECRYPT(UNHEX('E842C5'), 'foobar', '1234567890123456'), AES_DECRYPT(UNHEX(''), 'foobar', '1234567890123456'), AES_DECRYPT(UNHEX('3DCD5646767D'), 'foobar', '1234567890123456'), AES_DECRYPT(NULL, 'foobar', '1234567890123456'), HEX(AES_DECRYPT('SOME_THING_STRANGE', 'foobar', '1234567890123456'))") - result.Check(testkit.Rows(`123 你好 8A3FBBE68C9465834584430E3AEEBB04B1F5`)) - - // for COMPRESS - tk.MustExec("DROP TABLE IF EXISTS t1;") - tk.MustExec("CREATE TABLE t1(a VARCHAR(1000));") - tk.MustExec("INSERT INTO t1 VALUES('12345'), ('23456');") - result = tk.MustQuery("SELECT HEX(COMPRESS(a)) FROM t1;") - result.Check(testkit.Rows("05000000789C323432363105040000FFFF02F80100", "05000000789C323236313503040000FFFF03070105")) - tk.MustExec("DROP TABLE IF EXISTS t2;") - tk.MustExec("CREATE TABLE t2(a VARCHAR(1000), b VARBINARY(1000));") - tk.MustExec("INSERT INTO t2 (a, b) SELECT a, COMPRESS(a) from t1;") - result = tk.MustQuery("SELECT a, HEX(b) FROM t2;") - result.Check(testkit.Rows("12345 05000000789C323432363105040000FFFF02F80100", "23456 05000000789C323236313503040000FFFF03070105")) - - // for UNCOMPRESS - result = tk.MustQuery("SELECT UNCOMPRESS(COMPRESS('123'))") - result.Check(testkit.Rows("123")) - result = tk.MustQuery("SELECT UNCOMPRESS(UNHEX('03000000789C3334320600012D0097'))") - result.Check(testkit.Rows("123")) - result = tk.MustQuery("SELECT UNCOMPRESS(UNHEX('03000000789C32343206040000FFFF012D0097'))") - result.Check(testkit.Rows("123")) - tk.MustExec("INSERT INTO t2 VALUES ('12345', UNHEX('05000000789C3334323631050002F80100'))") - result = tk.MustQuery("SELECT UNCOMPRESS(a), UNCOMPRESS(b) FROM t2;") - result.Check(testkit.Rows(" 12345", " 23456", " 12345")) - - // for UNCOMPRESSED_LENGTH - result = tk.MustQuery("SELECT UNCOMPRESSED_LENGTH(COMPRESS('123'))") - result.Check(testkit.Rows("3")) - result = tk.MustQuery("SELECT UNCOMPRESSED_LENGTH(UNHEX('03000000789C3334320600012D0097'))") - result.Check(testkit.Rows("3")) - result = tk.MustQuery("SELECT UNCOMPRESSED_LENGTH(UNHEX('03000000789C32343206040000FFFF012D0097'))") - result.Check(testkit.Rows("3")) - result = tk.MustQuery("SELECT UNCOMPRESSED_LENGTH('')") - result.Check(testkit.Rows("0")) - result = tk.MustQuery("SELECT UNCOMPRESSED_LENGTH(UNHEX('0100'))") - result.Check(testkit.Rows("0")) - result = tk.MustQuery("SELECT UNCOMPRESSED_LENGTH(a), UNCOMPRESSED_LENGTH(b) FROM t2;") - result.Check(testkit.Rows("875770417 5", "892613426 5", "875770417 5")) - - // for RANDOM_BYTES - lengths := []int{0, -5, 1025, 4000} - for _, length := range lengths { - rs, err := tk.Exec(fmt.Sprintf("SELECT RANDOM_BYTES(%d);", length)) - require.NoError(t, err, "%v", length) - _, err = session.GetRows4Test(ctx, tk.Session(), rs) - require.Error(t, err, "%v", length) - terr := errors.Cause(err).(*terror.Error) - require.Equal(t, errors.ErrCode(mysql.ErrDataOutOfRange), terr.Code(), "%v", length) - require.NoError(t, rs.Close()) - } - tk.MustQuery("SELECT RANDOM_BYTES('1');") - tk.MustQuery("SELECT RANDOM_BYTES(1024);") - result = tk.MustQuery("SELECT RANDOM_BYTES(NULL);") - result.Check(testkit.Rows("")) - - // for VALIDATE_PASSWORD_STRENGTH - tk.MustExec(fmt.Sprintf("SET GLOBAL validate_password.dictionary='%s'", "password")) - tk.MustExec("SET GLOBAL validate_password.enable = 1") - tk.MustQuery("SELECT validate_password_strength('root')").Check(testkit.Rows("0")) - tk.MustQuery("SELECT validate_password_strength('toor')").Check(testkit.Rows("0")) - tk.MustQuery("SELECT validate_password_strength('ROOT')").Check(testkit.Rows("25")) - tk.MustQuery("SELECT validate_password_strength('TOOR')").Check(testkit.Rows("25")) - tk.MustQuery("SELECT validate_password_strength('fooHoHo%1')").Check(testkit.Rows("100")) - tk.MustQuery("SELECT validate_password_strength('pass')").Check(testkit.Rows("25")) - tk.MustQuery("SELECT validate_password_strength('password')").Check(testkit.Rows("50")) - tk.MustQuery("SELECT validate_password_strength('password0000')").Check(testkit.Rows("50")) - tk.MustQuery("SELECT validate_password_strength('password1A#')").Check(testkit.Rows("75")) - tk.MustQuery("SELECT validate_password_strength('PA12wrd!#')").Check(testkit.Rows("100")) - tk.MustQuery("SELECT VALIDATE_PASSWORD_STRENGTH(REPEAT(\"aA1#\", 26))").Check(testkit.Rows("100")) - tk.MustQuery("SELECT validate_password_strength(null)").Check(testkit.Rows("")) - tk.MustQuery("SELECT validate_password_strength('null')").Check(testkit.Rows("25")) - tk.MustQuery("SELECT VALIDATE_PASSWORD_STRENGTH( 0x6E616E646F73617135234552 )").Check(testkit.Rows("100")) - tk.MustQuery("SELECT VALIDATE_PASSWORD_STRENGTH(CAST(0xd2 AS BINARY(10)))").Check(testkit.Rows("50")) -} - func TestInfoBuiltin(t *testing.T) { store := testkit.CreateMockStore(t) @@ -728,42 +437,6 @@ func TestFilterExtractFromDNF(t *testing.T) { } } -func TestTiDBDecodePlanFunc(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustQuery("select tidb_decode_plan('')").Check(testkit.Rows("")) - tk.MustQuery("select tidb_decode_plan('7APIMAk1XzEzCTAJMQlmdW5jczpjb3VudCgxKQoxCTE3XzE0CTAJMAlpbm5lciBqb2luLCBp" + - "AQyQOlRhYmxlUmVhZGVyXzIxLCBlcXVhbDpbZXEoQ29sdW1uIzEsIA0KCDkpIBkXADIVFywxMCldCjIJMzFfMTgFZXhkYXRhOlNlbGVjdGlvbl" + - "8xNwozCTFfMTcJMQkwCWx0HVlATlVMTCksIG5vdChpc251bGwVHAApUhcAUDIpKQo0CTEwXzE2CTEJMTAwMDAJdAHB2Dp0MSwgcmFuZ2U6Wy1p" + - "bmYsK2luZl0sIGtlZXAgb3JkZXI6ZmFsc2UsIHN0YXRzOnBzZXVkbwoFtgAyAZcEMAk6tgAEMjAFtgQyMDq2AAg5LCBmtgAAMFa3AAA5FbcAO" + - "T63AAAyzrcA')").Check(testkit.Rows("" + - "\tid \ttask\testRows\toperator info\n" + - "\tStreamAgg_13 \troot\t1 \tfuncs:count(1)\n" + - "\t└─HashJoin_14 \troot\t0 \tinner join, inner:TableReader_21, equal:[eq(Column#1, Column#9) eq(Column#2, Column#10)]\n" + - "\t ├─TableReader_18 \troot\t0 \tdata:Selection_17\n" + - "\t │ └─Selection_17 \tcop \t0 \tlt(Column#1, NULL), not(isnull(Column#1)), not(isnull(Column#2))\n" + - "\t │ └─TableScan_16\tcop \t10000 \ttable:t1, range:[-inf,+inf], keep order:false, stats:pseudo\n" + - "\t └─TableReader_21 \troot\t0 \tdata:Selection_20\n" + - "\t └─Selection_20 \tcop \t0 \tlt(Column#9, NULL), not(isnull(Column#10)), not(isnull(Column#9))\n" + - "\t └─TableScan_19\tcop \t10000 \ttable:t2, range:[-inf,+inf], keep order:false, stats:pseudo")) - tk.MustQuery("select tidb_decode_plan('rwPwcTAJNV8xNAkwCTEJZnVuY3M6bWF4KHRlc3QudC5hKS0+Q29sdW1uIzQJMQl0aW1lOj" + - "IyMy45MzXCtXMsIGxvb3BzOjIJMTI4IEJ5dGVzCU4vQQoxCTE2XzE4CTAJMQlvZmZzZXQ6MCwgY291bnQ6MQkxCQlHFDE4LjQyMjJHAAhOL0" + - "EBBCAKMgkzMl8yOAkBlEBpbmRleDpMaW1pdF8yNwkxCQ0+DDYuODUdPSwxLCBycGMgbnVtOiANDAUpGDE1MC44MjQFKjhwcm9jIGtleXM6MA" + - "kxOTgdsgAzAbIAMgFearIAFDU3LjM5NgVKAGwN+BGxIDQJMTNfMjYJMQGgHGFibGU6dCwgCbqwaWR4KGEpLCByYW5nZTooMCwraW5mXSwga2" + - "VlcCBvcmRlcjp0cnVlLCBkZXNjAT8kaW1lOjU2LjY2MR1rJDEJTi9BCU4vQQo=')").Check(testkit.Rows("" + - "\tid \ttask\testRows\toperator info \tactRows\texecution info \tmemory \tdisk\n" + - "\tStreamAgg_14 \troot\t1 \tfuncs:max(test.t.a)->Column#4 \t1 \ttime:223.935µs, loops:2 \t128 Bytes\tN/A\n" + - "\t└─Limit_18 \troot\t1 \toffset:0, count:1 \t1 \ttime:218.422µs, loops:2 \tN/A \tN/A\n" + - "\t └─IndexReader_28 \troot\t1 \tindex:Limit_27 \t1 \ttime:216.85µs, loops:1, rpc num: 1, rpc time:150.824µs, proc keys:0\t198 Bytes\tN/A\n" + - "\t └─Limit_27 \tcop \t1 \toffset:0, count:1 \t1 \ttime:57.396µs, loops:2 \tN/A \tN/A\n" + - "\t └─IndexScan_26\tcop \t1 \ttable:t, index:idx(a), range:(0,+inf], keep order:true, desc\t1 \ttime:56.661µs, loops:1 \tN/A \tN/A")) - - // Test issue16939 - tk.MustQuery("select tidb_decode_plan(query), time from information_schema.slow_query order by time desc limit 1;") - tk.MustQuery("select tidb_decode_plan('xxx')").Check(testkit.Rows("xxx")) -} - func TestTiDBDecodeKeyFunc(t *testing.T) { store := testkit.CreateMockStore(t) @@ -1041,18 +714,6 @@ func TestExprPushdownBlacklist(t *testing.T) { tk.MustExec("admin reload expr_pushdown_blacklist") } -func TestIssue10804(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustQuery(`SELECT @@information_schema_stats_expiry`).Check(testkit.Rows(`86400`)) - tk.MustExec("/*!80000 SET SESSION information_schema_stats_expiry=0 */") - tk.MustQuery(`SELECT @@information_schema_stats_expiry`).Check(testkit.Rows(`0`)) - tk.MustQuery(`SELECT @@GLOBAL.information_schema_stats_expiry`).Check(testkit.Rows(`86400`)) - tk.MustExec("/*!80000 SET GLOBAL information_schema_stats_expiry=0 */") - tk.MustQuery(`SELECT @@GLOBAL.information_schema_stats_expiry`).Check(testkit.Rows(`0`)) -} - func TestNotExistFunc(t *testing.T) { store := testkit.CreateMockStore(t) @@ -1409,17 +1070,6 @@ func TestIssue11333(t *testing.T) { tk.MustQuery(`select 0.000000000000000000000000000000000000000000000000000000000000000000000001;`).Check(testkit.Rows("0.000000000000000000000000000000000000000000000000000000000000000000000001")) } -func TestDatetimeUserVariable(t *testing.T) { - store := testkit.CreateMockStore(t) - - tk := testkit.NewTestKit(t, store) - tk.MustExec("set @p = now()") - tk.MustExec("set @@tidb_enable_vectorized_expression = false") - require.NotEqual(t, "", tk.MustQuery("select @p").Rows()[0][0]) - tk.MustExec("set @@tidb_enable_vectorized_expression = true") - require.NotEqual(t, "", tk.MustQuery("select @p").Rows()[0][0]) -} - func TestSecurityEnhancedMode(t *testing.T) { store := testkit.CreateMockStore(t) @@ -2049,13 +1699,1575 @@ func TestCompareBuiltin(t *testing.T) { result.Check(testkit.Rows("0")) } -func TestIssue41986(t *testing.T) { +func TestTimeBuiltin(t *testing.T) { store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + originSQLMode := tk.Session().GetSessionVars().StrictSQLMode + tk.Session().GetSessionVars().StrictSQLMode = true + defer func() { + tk.Session().GetSessionVars().StrictSQLMode = originSQLMode + }() + tk.MustExec("use test") + + // for makeDate + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(a int, b double, c datetime, d time, e char(20), f bit(10))") + tk.MustExec(`insert into t values(1, 1.1, "2017-01-01 12:01:01", "12:01:01", "abcdef", 0b10101)`) + result := tk.MustQuery("select makedate(a,a), makedate(b,b), makedate(c,c), makedate(d,d), makedate(e,e), makedate(f,f), makedate(null,null), makedate(a,b) from t") + result.Check(testkit.Rows("2001-01-01 2001-01-01 2021-01-21 2001-01-01")) + + // for date + result = tk.MustQuery(`select date("2019-09-12"), date("2019-09-12 12:12:09"), date("2019-09-12 12:12:09.121212");`) + result.Check(testkit.Rows("2019-09-12 2019-09-12 2019-09-12")) + result = tk.MustQuery(`select date("0000-00-00"), date("0000-00-00 12:12:09"), date("0000-00-00 00:00:00.121212"), date("0000-00-00 00:00:00.000000");`) + result.Check(testkit.Rows(" 0000-00-00 0000-00-00 ")) + result = tk.MustQuery(`select date("aa"), date(12.1), date("");`) + result.Check(testkit.Rows(" ")) + + // for year + result = tk.MustQuery(`select year("2013-01-09"), year("2013-00-09"), year("000-01-09"), year("1-01-09"), year("20131-01-09"), year(null);`) + result.Check(testkit.Rows("2013 2013 0 2001 ")) + result = tk.MustQuery(`select year("2013-00-00"), year("2013-00-00 00:00:00"), year("0000-00-00 12:12:12"), year("2017-00-00 12:12:12");`) + result.Check(testkit.Rows("2013 2013 0 2017")) + result = tk.MustQuery(`select year("aa"), year(2013), year(2012.09), year("1-01"), year("-09");`) + result.Check(testkit.Rows(" ")) + tk.MustExec(`drop table if exists t`) + tk.MustExec(`create table t(a bigint)`) + _, err := tk.Exec(`insert into t select year("aa")`) + require.Error(t, err) + require.True(t, terror.ErrorEqual(err, types.ErrWrongValue), "err %v", err) + tk.MustExec(`set sql_mode='STRICT_TRANS_TABLES'`) // without zero date + tk.MustExec(`insert into t select year("0000-00-00 00:00:00")`) + tk.MustExec(`set sql_mode="NO_ZERO_DATE";`) // with zero date + tk.MustExec(`insert into t select year("0000-00-00 00:00:00")`) + tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1292|Incorrect datetime value: '0000-00-00 00:00:00.000000'")) + tk.MustExec(`set sql_mode="NO_ZERO_DATE,STRICT_TRANS_TABLES";`) + _, err = tk.Exec(`insert into t select year("0000-00-00 00:00:00");`) + require.Error(t, err) + require.True(t, types.ErrWrongValue.Equal(err), "err %v", err) + + tk.MustExec(`insert into t select 1`) + tk.MustExec(`set sql_mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION";`) + _, err = tk.Exec(`update t set a = year("aa")`) + require.True(t, terror.ErrorEqual(err, types.ErrWrongValue), "err %v", err) + _, err = tk.Exec(`delete from t where a = year("aa")`) + // Only `code` can be used to compare because the error `class` information + // will be lost after expression push-down + require.Equal(t, types.ErrWrongValue.Code(), errors.Cause(err).(*terror.Error).Code(), "err %v", err) + + // for month + result = tk.MustQuery(`select month("2013-01-09"), month("2013-00-09"), month("000-01-09"), month("1-01-09"), month("20131-01-09"), month(null);`) + result.Check(testkit.Rows("1 0 1 1 ")) + result = tk.MustQuery(`select month("2013-00-00"), month("2013-00-00 00:00:00"), month("0000-00-00 12:12:12"), month("2017-00-00 12:12:12");`) + result.Check(testkit.Rows("0 0 0 0")) + result = tk.MustQuery(`select month("aa"), month(2013), month(2012.09), month("1-01"), month("-09");`) + result.Check(testkit.Rows(" ")) + result = tk.MustQuery(`select month("2013-012-09"), month("2013-0000000012-09"), month("2013-30-09"), month("000-41-09");`) + result.Check(testkit.Rows("12 12 ")) + tk.MustExec(`drop table if exists t`) + tk.MustExec(`create table t(a bigint)`) + _, err = tk.Exec(`insert into t select month("aa")`) + require.Error(t, err) + require.True(t, terror.ErrorEqual(err, types.ErrWrongValue), "err: %v", err) + tk.MustExec(`insert into t select month("0000-00-00 00:00:00")`) + tk.MustExec(`set sql_mode="NO_ZERO_DATE";`) + tk.MustExec(`insert into t select month("0000-00-00 00:00:00")`) + tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Warning|1292|Incorrect datetime value: '0000-00-00 00:00:00.000000'")) + tk.MustExec(`set sql_mode="NO_ZERO_DATE,STRICT_TRANS_TABLES";`) + _, err = tk.Exec(`insert into t select month("0000-00-00 00:00:00");`) + require.Error(t, err) + require.True(t, types.ErrWrongValue.Equal(err), "err: %v", err) + tk.MustExec(`insert into t select 1`) + tk.MustExec(`set sql_mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION";`) + tk.MustExec(`insert into t select 1`) + _, err = tk.Exec(`update t set a = month("aa")`) + require.True(t, terror.ErrorEqual(err, types.ErrWrongValue)) + _, err = tk.Exec(`delete from t where a = month("aa")`) + require.Equal(t, types.ErrWrongValue.Code(), errors.Cause(err).(*terror.Error).Code(), "err %v", err) + + // for week + result = tk.MustQuery(`select week("2012-12-22"), week("2012-12-22", -2), week("2012-12-22", 0), week("2012-12-22", 1), week("2012-12-22", 2), week("2012-12-22", 200);`) + result.Check(testkit.Rows("51 51 51 51 51 51")) + result = tk.MustQuery(`select week("2008-02-20"), week("2008-02-20", 0), week("2008-02-20", 1), week("2009-02-20", 2), week("2008-02-20", 3), week("2008-02-20", 4);`) + result.Check(testkit.Rows("7 7 8 7 8 8")) + result = tk.MustQuery(`select week("2008-02-20", 5), week("2008-02-20", 6), week("2009-02-20", 7), week("2008-02-20", 8), week("2008-02-20", 9);`) + result.Check(testkit.Rows("7 8 7 7 8")) + result = tk.MustQuery(`select week("aa", 1), week(null, 2), week(11, 2), week(12.99, 2);`) + result.Check(testkit.Rows(" ")) + result = tk.MustQuery(`select week("aa"), week(null), week(11), week(12.99);`) + result.Check(testkit.Rows(" ")) + tk.MustExec(`drop table if exists t`) + tk.MustExec(`create table t(a datetime)`) + _, err = tk.Exec(`insert into t select week("aa", 1)`) + require.Error(t, err) + require.True(t, terror.ErrorEqual(err, types.ErrWrongValue)) + tk.MustExec(`insert into t select now()`) + _, err = tk.Exec(`update t set a = week("aa", 1)`) + require.True(t, terror.ErrorEqual(err, types.ErrWrongValue)) + _, err = tk.Exec(`delete from t where a = week("aa", 1)`) + require.Equal(t, types.ErrWrongValue.Code(), errors.Cause(err).(*terror.Error).Code(), "err %v", err) + + // for weekofyear + result = tk.MustQuery(`select weekofyear("2012-12-22"), weekofyear("2008-02-20"), weekofyear("aa"), weekofyear(null), weekofyear(11), weekofyear(12.99);`) + result.Check(testkit.Rows("51 8 ")) + tk.MustExec(`drop table if exists t`) + tk.MustExec(`create table t(a bigint)`) + _, err = tk.Exec(`insert into t select weekofyear("aa")`) + require.Error(t, err) + require.True(t, terror.ErrorEqual(err, types.ErrWrongValue)) + + tk.MustExec(`insert into t select 1`) + _, err = tk.Exec(`update t set a = weekofyear("aa")`) + require.True(t, terror.ErrorEqual(err, types.ErrWrongValue)) + _, err = tk.Exec(`delete from t where a = weekofyear("aa")`) + require.Equal(t, types.ErrWrongValue.Code(), errors.Cause(err).(*terror.Error).Code(), "err %v", err) + + // for weekday + result = tk.MustQuery(`select weekday("2012-12-20"), weekday("2012-12-21"), weekday("2012-12-22"), weekday("2012-12-23"), weekday("2012-12-24"), weekday("2012-12-25"), weekday("2012-12-26"), weekday("2012-12-27");`) + result.Check(testkit.Rows("3 4 5 6 0 1 2 3")) + result = tk.MustQuery(`select weekday("2012-12-90"), weekday("0000-00-00"), weekday("aa"), weekday(null), weekday(11), weekday(12.99);`) + result.Check(testkit.Rows(" ")) + + // for quarter + result = tk.MustQuery(`select quarter("2012-00-20"), quarter("2012-01-21"), quarter("2012-03-22"), quarter("2012-05-23"), quarter("2012-08-24"), quarter("2012-09-25"), quarter("2012-11-26"), quarter("2012-12-27");`) + result.Check(testkit.Rows("0 1 1 2 3 3 4 4")) + result = tk.MustQuery(`select quarter("2012-14-20"), quarter("aa"), quarter(null), quarter(11), quarter(12.99);`) + result.Check(testkit.Rows(" ")) + result = tk.MustQuery(`select quarter("0000-00-00"), quarter("0000-00-00 00:00:00");`) + result.Check(testkit.Rows("0 0")) + tk.MustQuery("show warnings").Check(testkit.Rows()) + result = tk.MustQuery(`select quarter(0), quarter(0.0), quarter(0e1), quarter(0.00);`) + result.Check(testkit.Rows("0 0 0 0")) + tk.MustQuery("show warnings").Check(testkit.Rows()) + + // for from_days + result = tk.MustQuery(`select from_days(0), from_days(-199), from_days(1111), from_days(120), from_days(1), from_days(1111111), from_days(9999999), from_days(22222);`) + result.Check(testkit.Rows("0000-00-00 0000-00-00 0003-01-16 0000-00-00 0000-00-00 3042-02-13 0000-00-00 0060-11-03")) + result = tk.MustQuery(`select from_days("2012-14-20"), from_days("111a"), from_days("aa"), from_days(null), from_days("123asf"), from_days(12.99);`) + result.Check(testkit.Rows("0005-07-05 0000-00-00 0000-00-00 0000-00-00 0000-00-00")) + + // Fix issue #3923 + result = tk.MustQuery("select timediff(cast('2004-12-30 12:00:00' as time), '12:00:00');") + result.Check(testkit.Rows("00:00:00")) + result = tk.MustQuery("select timediff('12:00:00', cast('2004-12-30 12:00:00' as time));") + result.Check(testkit.Rows("00:00:00")) + result = tk.MustQuery("select timediff(cast('2004-12-30 12:00:00' as time), '2004-12-30 12:00:00');") + result.Check(testkit.Rows("")) + result = tk.MustQuery("select timediff('2004-12-30 12:00:00', cast('2004-12-30 12:00:00' as time));") + result.Check(testkit.Rows("")) + result = tk.MustQuery("select timediff(cast('2004-12-30 12:00:01' as datetime), '2004-12-30 12:00:00');") + result.Check(testkit.Rows("00:00:01")) + result = tk.MustQuery("select timediff('2004-12-30 12:00:00', cast('2004-12-30 12:00:01' as datetime));") + result.Check(testkit.Rows("-00:00:01")) + result = tk.MustQuery("select timediff(cast('2004-12-30 12:00:01' as time), '-34 00:00:00');") + result.Check(testkit.Rows("828:00:01")) + result = tk.MustQuery("select timediff('-34 00:00:00', cast('2004-12-30 12:00:01' as time));") + result.Check(testkit.Rows("-828:00:01")) + result = tk.MustQuery("select timediff(cast('2004-12-30 12:00:01' as datetime), cast('2004-12-30 11:00:01' as datetime));") + result.Check(testkit.Rows("01:00:00")) + result = tk.MustQuery("select timediff(cast('2004-12-30 12:00:01' as datetime), '2004-12-30 12:00:00.1');") + result.Check(testkit.Rows("00:00:00.9")) + result = tk.MustQuery("select timediff('2004-12-30 12:00:00.1', cast('2004-12-30 12:00:01' as datetime));") + result.Check(testkit.Rows("-00:00:00.9")) + result = tk.MustQuery("select timediff(cast('2004-12-30 12:00:01' as datetime), '-34 124:00:00');") + result.Check(testkit.Rows("")) + result = tk.MustQuery("select timediff('-34 124:00:00', cast('2004-12-30 12:00:01' as datetime));") + result.Check(testkit.Rows("")) + result = tk.MustQuery("select timediff(cast('2004-12-30 12:00:01' as time), '-34 124:00:00');") + result.Check(testkit.Rows("838:59:59")) + result = tk.MustQuery("select timediff('-34 124:00:00', cast('2004-12-30 12:00:01' as time));") + result.Check(testkit.Rows("-838:59:59")) + result = tk.MustQuery("select timediff(cast('2004-12-30' as datetime), '12:00:00');") + result.Check(testkit.Rows("")) + result = tk.MustQuery("select timediff('12:00:00', cast('2004-12-30' as datetime));") + result.Check(testkit.Rows("")) + result = tk.MustQuery("select timediff('12:00:00', '-34 12:00:00');") + result.Check(testkit.Rows("838:59:59")) + result = tk.MustQuery("select timediff('12:00:00', '34 12:00:00');") + result.Check(testkit.Rows("-816:00:00")) + result = tk.MustQuery("select timediff('2014-1-2 12:00:00', '-34 12:00:00');") + result.Check(testkit.Rows("")) + result = tk.MustQuery("select timediff('-34 12:00:00', '2014-1-2 12:00:00');") + result.Check(testkit.Rows("")) + result = tk.MustQuery("select timediff('2014-1-2 12:00:00', '12:00:00');") + result.Check(testkit.Rows("")) + result = tk.MustQuery("select timediff('12:00:00', '2014-1-2 12:00:00');") + result.Check(testkit.Rows("")) + result = tk.MustQuery("select timediff('2014-1-2 12:00:00', '2014-1-1 12:00:00');") + result.Check(testkit.Rows("24:00:00")) + tk.MustQuery("select timediff(cast('10:10:10' as time), cast('10:10:11' as time))").Check(testkit.Rows("-00:00:01")) + + result = tk.MustQuery("select timestampadd(MINUTE, 1, '2003-01-02'), timestampadd(WEEK, 1, '2003-01-02 23:59:59')" + + ", timestampadd(MICROSECOND, 1, 950501);") + result.Check(testkit.Rows("2003-01-02 00:01:00 2003-01-09 23:59:59 1995-05-01 00:00:00.000001")) + result = tk.MustQuery("select timestampadd(day, 2, 950501), timestampadd(MINUTE, 37.5,'2003-01-02'), timestampadd(MINUTE, 37.49,'2003-01-02')," + + " timestampadd(YeAr, 1, '2003-01-02');") + result.Check(testkit.Rows("1995-05-03 00:00:00 2003-01-02 00:38:00 2003-01-02 00:37:00 2004-01-02 00:00:00")) + result = tk.MustQuery("select to_seconds(950501), to_seconds('2009-11-29'), to_seconds('2009-11-29 13:43:32'), to_seconds('09-11-29 13:43:32');") + result.Check(testkit.Rows("62966505600 63426672000 63426721412 63426721412")) + result = tk.MustQuery("select to_days(950501), to_days('2007-10-07'), to_days('2007-10-07 00:00:59'), to_days('0000-01-01')") + result.Check(testkit.Rows("728779 733321 733321 1")) + + result = tk.MustQuery("select last_day('2003-02-05'), last_day('2004-02-05'), last_day('2004-01-01 01:01:01'), last_day(950501);") + result.Check(testkit.Rows("2003-02-28 2004-02-29 2004-01-31 1995-05-31")) + + tk.MustExec("SET SQL_MODE='';") + result = tk.MustQuery("select last_day('0000-00-00');") + result.Check(testkit.Rows("")) + result = tk.MustQuery("select to_days('0000-00-00');") + result.Check(testkit.Rows("")) + result = tk.MustQuery("select to_seconds('0000-00-00');") + result.Check(testkit.Rows("")) + + result = tk.MustQuery("select timestamp('2003-12-31'), timestamp('2003-12-31 12:00:00','12:00:00');") + result.Check(testkit.Rows("2003-12-31 00:00:00 2004-01-01 00:00:00")) + result = tk.MustQuery("select timestamp(20170118123950.123), timestamp(20170118123950.999);") + result.Check(testkit.Rows("2017-01-18 12:39:50.123 2017-01-18 12:39:50.999")) + // Issue https://github.com/pingcap/tidb/issues/20003 + result = tk.MustQuery("select timestamp(0.0001, 0.00001);") + result.Check(testkit.Rows("")) + result = tk.MustQuery("select timestamp('2003-12-31', '01:01:01.01'), timestamp('2003-12-31 12:34', '01:01:01.01')," + + " timestamp('2008-12-31','00:00:00.0'), timestamp('2008-12-31 00:00:00.000');") + + tk.MustQuery(`select timestampadd(second, 1, cast("2001-01-01" as date))`).Check(testkit.Rows("2001-01-01 00:00:01")) + tk.MustQuery(`select timestampadd(hour, 1, cast("2001-01-01" as date))`).Check(testkit.Rows("2001-01-01 01:00:00")) + tk.MustQuery(`select timestampadd(day, 1, cast("2001-01-01" as date))`).Check(testkit.Rows("2001-01-02")) + tk.MustQuery(`select timestampadd(month, 1, cast("2001-01-01" as date))`).Check(testkit.Rows("2001-02-01")) + tk.MustQuery(`select timestampadd(year, 1, cast("2001-01-01" as date))`).Check(testkit.Rows("2002-01-01")) + tk.MustQuery(`select timestampadd(second, 1, cast("2001-01-01" as datetime))`).Check(testkit.Rows("2001-01-01 00:00:01")) + tk.MustQuery(`select timestampadd(hour, 1, cast("2001-01-01" as datetime))`).Check(testkit.Rows("2001-01-01 01:00:00")) + tk.MustQuery(`select timestampadd(day, 1, cast("2001-01-01" as datetime))`).Check(testkit.Rows("2001-01-02 00:00:00")) + tk.MustQuery(`select timestampadd(month, 1, cast("2001-01-01" as datetime))`).Check(testkit.Rows("2001-02-01 00:00:00")) + tk.MustQuery(`select timestampadd(year, 1, cast("2001-01-01" as datetime))`).Check(testkit.Rows("2002-01-01 00:00:00")) + + result.Check(testkit.Rows("2003-12-31 01:01:01.01 2003-12-31 13:35:01.01 2008-12-31 00:00:00.0 2008-12-31 00:00:00.000")) + result = tk.MustQuery("select timestamp('2003-12-31', 1), timestamp('2003-12-31', -1);") + result.Check(testkit.Rows("2003-12-31 00:00:01 2003-12-30 23:59:59")) + result = tk.MustQuery("select timestamp('2003-12-31', '2000-12-12 01:01:01.01'), timestamp('2003-14-31','01:01:01.01');") + result.Check(testkit.Rows(" ")) + + result = tk.MustQuery("select TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'), TIMESTAMPDIFF(yEaR,'2002-05-01', " + + "'2001-01-01'), TIMESTAMPDIFF(minute,binary('2003-02-01'),'2003-05-01 12:05:55'), TIMESTAMPDIFF(day," + + "'1995-05-02', 950501);") + result.Check(testkit.Rows("3 -1 128885 -1")) + + result = tk.MustQuery("select datediff('2007-12-31 23:59:59','2007-12-30'), datediff('2010-11-30 23:59:59', " + + "'2010-12-31'), datediff(950501,'2016-01-13'), datediff(950501.9,'2016-01-13'), datediff(binary(950501), '2016-01-13');") + result.Check(testkit.Rows("1 -31 -7562 -7562 -7562")) + result = tk.MustQuery("select datediff('0000-01-01','0001-01-01'), datediff('0001-00-01', '0001-00-01'), datediff('0001-01-00','0001-01-00'), datediff('2017-01-01','2017-01-01');") + result.Check(testkit.Rows("-365 0")) + + // for ADDTIME + result = tk.MustQuery("select addtime('01:01:11', '00:00:01.013'), addtime('01:01:11.00', '00:00:01'), addtime" + + "('2017-01-01 01:01:11.12', '00:00:01'), addtime('2017-01-01 01:01:11.12', '00:00:01.88');") + result.Check(testkit.Rows("01:01:12.013000 01:01:12 2017-01-01 01:01:12.120000 2017-01-01 01:01:13")) + result = tk.MustQuery("select addtime(cast('01:01:11' as time(4)), '00:00:01.013'), addtime(cast('01:01:11.00' " + + "as datetime(3)), '00:00:01')," + " addtime(cast('2017-01-01 01:01:11.12' as date), '00:00:01'), addtime(cast" + + "(cast('2017-01-01 01:01:11.12' as date) as datetime(2)), '00:00:01.88');") + result.Check(testkit.Rows("01:01:12.0130 2001-01-11 00:00:01.000 00:00:01 2017-01-01 00:00:01.88")) + result = tk.MustQuery("select addtime('2017-01-01 01:01:01', 5), addtime('2017-01-01 01:01:01', -5), addtime('2017-01-01 01:01:01', 0.0), addtime('2017-01-01 01:01:01', 1.34);") + result.Check(testkit.Rows("2017-01-01 01:01:06 2017-01-01 01:00:56 2017-01-01 01:01:01 2017-01-01 01:01:02.340000")) + result = tk.MustQuery("select addtime(cast('01:01:11.00' as datetime(3)), cast('00:00:01' as time)), addtime(cast('01:01:11.00' as datetime(3)), cast('00:00:01' as time(5)))") + result.Check(testkit.Rows("2001-01-11 00:00:01.000 2001-01-11 00:00:01.00000")) + result = tk.MustQuery("select addtime(cast('01:01:11.00' as date), cast('00:00:01' as time));") + result.Check(testkit.Rows("00:00:01")) + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(a datetime, b timestamp, c time)") + tk.MustExec(`insert into t values("2017-01-01 12:30:31", "2017-01-01 12:30:31", "01:01:01")`) + result = tk.MustQuery("select addtime(a, b), addtime(cast(a as date), b), addtime(b,a), addtime(a,c), addtime(b," + + "c), addtime(c,a), addtime(c,b)" + + " from t;") + result.Check(testkit.Rows(" 2017-01-01 13:31:32 2017-01-01 13:31:32 ")) + result = tk.MustQuery("select addtime('01:01:11', cast('1' as time))") + result.Check(testkit.Rows("01:01:12")) + tk.MustQuery("select addtime(cast(null as char(20)), cast('1' as time))").Check(testkit.Rows("")) + require.NoError(t, tk.QueryToErr(`select addtime("01:01:11", cast('sdf' as time))`)) + tk.MustQuery(`select addtime("01:01:11", cast(null as char(20)))`).Check(testkit.Rows("")) + tk.MustQuery(`select addtime(cast(1 as time), cast(1 as time))`).Check(testkit.Rows("00:00:02")) + tk.MustQuery(`select addtime(cast(null as time), cast(1 as time))`).Check(testkit.Rows("")) + tk.MustQuery(`select addtime(cast(1 as time), cast(null as time))`).Check(testkit.Rows("")) + + // for SUBTIME + result = tk.MustQuery("select subtime('01:01:11', '00:00:01.013'), subtime('01:01:11.00', '00:00:01'), subtime" + + "('2017-01-01 01:01:11.12', '00:00:01'), subtime('2017-01-01 01:01:11.12', '00:00:01.88');") + result.Check(testkit.Rows("01:01:09.987000 01:01:10 2017-01-01 01:01:10.120000 2017-01-01 01:01:09.240000")) + result = tk.MustQuery("select subtime(cast('01:01:11' as time(4)), '00:00:01.013'), subtime(cast('01:01:11.00' " + + "as datetime(3)), '00:00:01')," + " subtime(cast('2017-01-01 01:01:11.12' as date), '00:00:01'), subtime(cast" + + "(cast('2017-01-01 01:01:11.12' as date) as datetime(2)), '00:00:01.88');") + result.Check(testkit.Rows("01:01:09.9870 2001-01-10 23:59:59.000 -00:00:01 2016-12-31 23:59:58.12")) + result = tk.MustQuery("select subtime('2017-01-01 01:01:01', 5), subtime('2017-01-01 01:01:01', -5), subtime('2017-01-01 01:01:01', 0.0), subtime('2017-01-01 01:01:01', 1.34);") + result.Check(testkit.Rows("2017-01-01 01:00:56 2017-01-01 01:01:06 2017-01-01 01:01:01 2017-01-01 01:00:59.660000")) + result = tk.MustQuery("select subtime('01:01:11', '0:0:1.013'), subtime('01:01:11.00', '0:0:1'), subtime('2017-01-01 01:01:11.12', '0:0:1'), subtime('2017-01-01 01:01:11.12', '0:0:1.120000');") + result.Check(testkit.Rows("01:01:09.987000 01:01:10 2017-01-01 01:01:10.120000 2017-01-01 01:01:10")) + result = tk.MustQuery("select subtime(cast('01:01:11.00' as datetime(3)), cast('00:00:01' as time)), subtime(cast('01:01:11.00' as datetime(3)), cast('00:00:01' as time(5)))") + result.Check(testkit.Rows("2001-01-10 23:59:59.000 2001-01-10 23:59:59.00000")) + result = tk.MustQuery("select subtime(cast('01:01:11.00' as date), cast('00:00:01' as time));") + result.Check(testkit.Rows("-00:00:01")) + result = tk.MustQuery("select subtime(a, b), subtime(cast(a as date), b), subtime(b,a), subtime(a,c), subtime(b," + + "c), subtime(c,a), subtime(c,b) from t;") + result.Check(testkit.Rows(" 2017-01-01 11:29:30 2017-01-01 11:29:30 ")) + tk.MustQuery("select subtime(cast('10:10:10' as time), cast('9:10:10' as time))").Check(testkit.Rows("01:00:00")) + tk.MustQuery("select subtime('10:10:10', cast('9:10:10' as time))").Check(testkit.Rows("01:00:00")) + + // SUBTIME issue #31868 + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(a DATETIME(6))") + tk.MustExec(`insert into t values ("1000-01-01 01:00:00.000000"), ("1000-01-01 01:00:00.000001")`) + tk.MustQuery(`SELECT SUBTIME(a, '00:00:00.000001') FROM t ORDER BY a;`).Check(testkit.Rows("1000-01-01 00:59:59.999999", "1000-01-01 01:00:00.000000")) + tk.MustQuery(`SELECT SUBTIME(a, '10:00:00.000001') FROM t ORDER BY a;`).Check(testkit.Rows("0999-12-31 14:59:59.999999", "0999-12-31 15:00:00.000000")) + + // ADDTIME & SUBTIME issue #5966 + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(a datetime, b timestamp, c time, d date, e bit(1))") + tk.MustExec(`insert into t values("2017-01-01 12:30:31", "2017-01-01 12:30:31", "01:01:01", "2017-01-01", 0b1)`) + + result = tk.MustQuery("select addtime(a, e), addtime(b, e), addtime(c, e), addtime(d, e) from t") + result.Check(testkit.Rows(" ")) + result = tk.MustQuery("select addtime('2017-01-01 01:01:01', 0b1), addtime('2017-01-01', b'1'), addtime('01:01:01', 0b1011)") + result.Check(testkit.Rows(" ")) + result = tk.MustQuery("select addtime('2017-01-01', 1), addtime('2017-01-01 01:01:01', 1), addtime(cast('2017-01-01' as date), 1)") + result.Check(testkit.Rows("2017-01-01 00:00:01 2017-01-01 01:01:02 00:00:01")) + result = tk.MustQuery("select subtime(a, e), subtime(b, e), subtime(c, e), subtime(d, e) from t") + result.Check(testkit.Rows(" ")) + result = tk.MustQuery("select subtime('2017-01-01 01:01:01', 0b1), subtime('2017-01-01', b'1'), subtime('01:01:01', 0b1011)") + result.Check(testkit.Rows(" ")) + result = tk.MustQuery("select subtime('2017-01-01', 1), subtime('2017-01-01 01:01:01', 1), subtime(cast('2017-01-01' as date), 1)") + result.Check(testkit.Rows("2016-12-31 23:59:59 2017-01-01 01:01:00 -00:00:01")) + + result = tk.MustQuery("select addtime(-32073, 0), addtime(0, -32073);") + result.Check(testkit.Rows(" ")) + tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", + "Warning|1292|Truncated incorrect time value: '-32073'", + "Warning|1292|Truncated incorrect time value: '-32073'")) + result = tk.MustQuery("select addtime(-32073, c), addtime(c, -32073) from t;") + result.Check(testkit.Rows(" ")) + tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", + "Warning|1292|Truncated incorrect time value: '-32073'", + "Warning|1292|Truncated incorrect time value: '-32073'")) + result = tk.MustQuery("select addtime(a, -32073), addtime(b, -32073), addtime(d, -32073) from t;") + result.Check(testkit.Rows(" ")) + tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", + "Warning|1292|Truncated incorrect time value: '-32073'", + "Warning|1292|Truncated incorrect time value: '-32073'", + "Warning|1292|Truncated incorrect time value: '-32073'")) + + result = tk.MustQuery("select subtime(-32073, 0), subtime(0, -32073);") + result.Check(testkit.Rows(" ")) + tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", + "Warning|1292|Truncated incorrect time value: '-32073'", + "Warning|1292|Truncated incorrect time value: '-32073'")) + result = tk.MustQuery("select subtime(-32073, c), subtime(c, -32073) from t;") + result.Check(testkit.Rows(" ")) + tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", + "Warning|1292|Truncated incorrect time value: '-32073'", + "Warning|1292|Truncated incorrect time value: '-32073'")) + result = tk.MustQuery("select subtime(a, -32073), subtime(b, -32073), subtime(d, -32073) from t;") + result.Check(testkit.Rows(" ")) + tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", + "Warning|1292|Truncated incorrect time value: '-32073'", + "Warning|1292|Truncated incorrect time value: '-32073'", + "Warning|1292|Truncated incorrect time value: '-32073'")) + + // fixed issue #3986 + tk.MustExec("SET SQL_MODE='NO_ENGINE_SUBSTITUTION';") + tk.MustExec("SET TIME_ZONE='+03:00';") + tk.MustExec("DROP TABLE IF EXISTS t;") + tk.MustExec("CREATE TABLE t (ix TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);") + tk.MustExec("INSERT INTO t VALUES (0), (20030101010160), (20030101016001), (20030101240101), (20030132010101), (20031301010101), (20031200000000), (20030000000000);") + result = tk.MustQuery("SELECT CAST(ix AS SIGNED) FROM t;") + result.Check(testkit.Rows("0", "0", "0", "0", "0", "0", "0", "0")) + + // test time + result = tk.MustQuery("select time('2003-12-31 01:02:03')") + result.Check(testkit.Rows("01:02:03")) + result = tk.MustQuery("select time('2003-12-31 01:02:03.000123')") + result.Check(testkit.Rows("01:02:03.000123")) + result = tk.MustQuery("select time('01:02:03.000123')") + result.Check(testkit.Rows("01:02:03.000123")) + result = tk.MustQuery("select time('01:02:03')") + result.Check(testkit.Rows("01:02:03")) + result = tk.MustQuery("select time('-838:59:59.000000')") + result.Check(testkit.Rows("-838:59:59.000000")) + result = tk.MustQuery("select time('-838:59:59.000001')") + result.Check(testkit.Rows("-838:59:59.000000")) + result = tk.MustQuery("select time('-839:59:59.000000')") + result.Check(testkit.Rows("-838:59:59.000000")) + result = tk.MustQuery("select time('840:59:59.000000')") + result.Check(testkit.Rows("838:59:59.000000")) + // FIXME: #issue 4193 + // result = tk.MustQuery("select time('840:59:60.000000')") + // result.Check(testkit.Rows("")) + // result = tk.MustQuery("select time('800:59:59.9999999')") + // result.Check(testkit.Rows("801:00:00.000000")) + // result = tk.MustQuery("select time('12003-12-10 01:02:03.000123')") + // result.Check(testkit.Rows("") + // result = tk.MustQuery("select time('')") + // result.Check(testkit.Rows("") + // result = tk.MustQuery("select time('2003-12-10-10 01:02:03.000123')") + // result.Check(testkit.Rows("00:20:03") + + // Issue 20995 + result = tk.MustQuery("select time('0.1234567')") + result.Check(testkit.Rows("00:00:00.123457")) + + // for hour + result = tk.MustQuery(`SELECT hour("12:13:14.123456"), hour("12:13:14.000010"), hour("272:59:55"), hour(020005), hour(null), hour("27aaaa2:59:55");`) + result.Check(testkit.Rows("12 12 272 2 ")) + + // for hour, issue #4340 + result = tk.MustQuery(`SELECT HOUR(20171222020005);`) + result.Check(testkit.Rows("2")) + result = tk.MustQuery(`SELECT HOUR(20171222020005.1);`) + result.Check(testkit.Rows("2")) + result = tk.MustQuery(`SELECT HOUR(20171222020005.1e0);`) + result.Check(testkit.Rows("2")) + result = tk.MustQuery(`SELECT HOUR("20171222020005");`) + result.Check(testkit.Rows("2")) + result = tk.MustQuery(`SELECT HOUR("20171222020005.1");`) + result.Check(testkit.Rows("2")) + result = tk.MustQuery(`select hour(20171222);`) + result.Check(testkit.Rows("")) + result = tk.MustQuery(`select hour(8381222);`) + result.Check(testkit.Rows("838")) + result = tk.MustQuery(`select hour(10000000000);`) + result.Check(testkit.Rows("")) + result = tk.MustQuery(`select hour(10100000000);`) + result.Check(testkit.Rows("")) + result = tk.MustQuery(`select hour(10001000000);`) + result.Check(testkit.Rows("")) + result = tk.MustQuery(`select hour(10101000000);`) + result.Check(testkit.Rows("0")) + + // for minute + result = tk.MustQuery(`SELECT minute("12:13:14.123456"), minute("12:13:14.000010"), minute("272:59:55"), minute(null), minute("27aaaa2:59:55");`) + result.Check(testkit.Rows("13 13 59 ")) + + // for second + result = tk.MustQuery(`SELECT second("12:13:14.123456"), second("12:13:14.000010"), second("272:59:55"), second(null), second("27aaaa2:59:55");`) + result.Check(testkit.Rows("14 14 55 ")) + + // for microsecond + result = tk.MustQuery(`SELECT microsecond("12:00:00.123456"), microsecond("12:00:00.000010"), microsecond(null), microsecond("27aaaa2:59:55");`) + result.Check(testkit.Rows("123456 10 ")) + + // for period_add + result = tk.MustQuery(`SELECT period_add(200807, 2), period_add(200807, -2);`) + result.Check(testkit.Rows("200809 200805")) + result = tk.MustQuery(`SELECT period_add(NULL, 2), period_add(-191, NULL), period_add(NULL, NULL), period_add(12.09, -2), period_add("200207aa", "1aa");`) + result.Check(testkit.Rows(" 200010 200208")) + for _, errPeriod := range []string{ + "period_add(0, 20)", "period_add(0, 0)", "period_add(-1, 1)", "period_add(200013, 1)", "period_add(-200012, 1)", "period_add('', '')", + } { + err := tk.QueryToErr(fmt.Sprintf("SELECT %v;", errPeriod)) + require.Error(t, err, "[expression:1210]Incorrect arguments to period_add") + } + + // for period_diff + result = tk.MustQuery(`SELECT period_diff(200807, 200705), period_diff(200807, 200908);`) + result.Check(testkit.Rows("14 -13")) + result = tk.MustQuery(`SELECT period_diff(NULL, 2), period_diff(-191, NULL), period_diff(NULL, NULL), period_diff(12.09, 2), period_diff("12aa", "11aa");`) + result.Check(testkit.Rows(" 10 1")) + for _, errPeriod := range []string{ + "period_diff(-00013,1)", "period_diff(00013,1)", "period_diff(0, 0)", "period_diff(200013, 1)", "period_diff(5612, 4513)", "period_diff('', '')", + } { + err := tk.QueryToErr(fmt.Sprintf("SELECT %v;", errPeriod)) + require.Error(t, err, "[expression:1210]Incorrect arguments to period_diff") + } + + // TODO: fix `CAST(xx as duration)` and release the test below: + // result = tk.MustQuery(`SELECT hour("aaa"), hour(123456), hour(1234567);`) + // result = tk.MustQuery(`SELECT minute("aaa"), minute(123456), minute(1234567);`) + // result = tk.MustQuery(`SELECT second("aaa"), second(123456), second(1234567);`) + // result = tk.MustQuery(`SELECT microsecond("aaa"), microsecond(123456), microsecond(1234567);`) + + // for time_format + result = tk.MustQuery("SELECT TIME_FORMAT('150:02:28', '%H:%i:%s %p');") + result.Check(testkit.Rows("150:02:28 AM")) + result = tk.MustQuery("SELECT TIME_FORMAT('bad string', '%H:%i:%s %p');") + result.Check(testkit.Rows("")) + result = tk.MustQuery("SELECT TIME_FORMAT(null, '%H:%i:%s %p');") + result.Check(testkit.Rows("")) + result = tk.MustQuery("SELECT TIME_FORMAT(123, '%H:%i:%s %p');") + result.Check(testkit.Rows("00:01:23 AM")) + result = tk.MustQuery("SELECT TIME_FORMAT('24:00:00', '%r');") + result.Check(testkit.Rows("12:00:00 AM")) + result = tk.MustQuery("SELECT TIME_FORMAT('25:00:00', '%r');") + result.Check(testkit.Rows("01:00:00 AM")) + result = tk.MustQuery("SELECT TIME_FORMAT('24:00:00', '%l %p');") + result.Check(testkit.Rows("12 AM")) + + // for date_format + result = tk.MustQuery(`SELECT DATE_FORMAT('2017-06-15', '%W %M %e %Y %r %y');`) + result.Check(testkit.Rows("Thursday June 15 2017 12:00:00 AM 17")) + result = tk.MustQuery(`SELECT DATE_FORMAT(151113102019.12, '%W %M %e %Y %r %y');`) + result.Check(testkit.Rows("Friday November 13 2015 10:20:19 AM 15")) + result = tk.MustQuery(`SELECT DATE_FORMAT('0000-00-00', '%W %M %e %Y %r %y');`) + result.Check(testkit.Rows("")) + tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", + "Warning|1292|Incorrect datetime value: '0000-00-00 00:00:00.000000'")) + result = tk.MustQuery(`SELECT DATE_FORMAT('0', '%W %M %e %Y %r %y'), DATE_FORMAT('0.0', '%W %M %e %Y %r %y'), DATE_FORMAT(0, 0);`) + result.Check(testkit.Rows(" 0")) + tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", + "Warning|1292|Incorrect time value: '0'", + "Warning|1292|Incorrect datetime value: '0.0'")) + result = tk.MustQuery(`SELECT DATE_FORMAT(0, '%W %M %e %Y %r %y'), DATE_FORMAT(0.0, '%W %M %e %Y %r %y');`) + result.Check(testkit.Rows(" ")) + tk.MustQuery("show warnings").Check(testkit.Rows()) + + // for yearweek + result = tk.MustQuery(`select yearweek("2014-12-27"), yearweek("2014-29-27"), yearweek("2014-00-27"), yearweek("2014-12-27 12:38:32"), yearweek("2014-12-27 12:38:32.1111111"), yearweek("2014-12-27 12:90:32"), yearweek("2014-12-27 89:38:32.1111111");`) + result.Check(testkit.Rows("201451 201451 201451 ")) + result = tk.MustQuery(`select yearweek(12121), yearweek(1.00009), yearweek("aaaaa"), yearweek(""), yearweek(NULL);`) + result.Check(testkit.Rows(" ")) + result = tk.MustQuery(`select yearweek("0000-00-00"), yearweek("2019-01-29", "aa"), yearweek("2011-01-01", null);`) + result.Check(testkit.Rows(" 201904 201052")) + + // for dayOfWeek, dayOfMonth, dayOfYear + result = tk.MustQuery(`select dayOfWeek(null), dayOfWeek("2017-08-12"), dayOfWeek("0000-00-00"), dayOfWeek("2017-00-00"), dayOfWeek("0000-00-00 12:12:12"), dayOfWeek("2017-00-00 12:12:12")`) + result.Check(testkit.Rows(" 7 ")) + result = tk.MustQuery(`select dayOfYear(null), dayOfYear("2017-08-12"), dayOfYear("0000-00-00"), dayOfYear("2017-00-00"), dayOfYear("0000-00-00 12:12:12"), dayOfYear("2017-00-00 12:12:12")`) + result.Check(testkit.Rows(" 224 ")) + result = tk.MustQuery(`select dayOfMonth(null), dayOfMonth("2017-08-12"), dayOfMonth("0000-00-00"), dayOfMonth("2017-00-00"), dayOfMonth("0000-00-00 12:12:12"), dayOfMonth("2017-00-00 12:12:12")`) + result.Check(testkit.Rows(" 12 0 0 0 0")) + + tk.MustExec("set sql_mode = 'NO_ZERO_DATE'") + result = tk.MustQuery(`select dayOfWeek(null), dayOfWeek("2017-08-12"), dayOfWeek("0000-00-00"), dayOfWeek("2017-00-00"), dayOfWeek("0000-00-00 12:12:12"), dayOfWeek("2017-00-00 12:12:12")`) + result.Check(testkit.Rows(" 7 ")) + result = tk.MustQuery(`select dayOfYear(null), dayOfYear("2017-08-12"), dayOfYear("0000-00-00"), dayOfYear("2017-00-00"), dayOfYear("0000-00-00 12:12:12"), dayOfYear("2017-00-00 12:12:12")`) + result.Check(testkit.Rows(" 224 ")) + result = tk.MustQuery(`select dayOfMonth(null), dayOfMonth("2017-08-12"), dayOfMonth("0000-00-00"), dayOfMonth("2017-00-00"), dayOfMonth("0000-00-00 12:12:12"), dayOfMonth("2017-00-00 12:12:12")`) + result.Check(testkit.Rows(" 12 0 0 0")) + + tk.MustExec(`drop table if exists t`) + tk.MustExec(`create table t(a bigint)`) + tk.MustExec(`insert into t value(1)`) + tk.MustExec("set sql_mode = 'STRICT_TRANS_TABLES'") + + _, err = tk.Exec("insert into t value(dayOfWeek('0000-00-00'))") + require.True(t, types.ErrWrongValue.Equal(err), "%v", err) + _, err = tk.Exec(`update t set a = dayOfWeek("0000-00-00")`) + require.True(t, types.ErrWrongValue.Equal(err)) + _, err = tk.Exec(`delete from t where a = dayOfWeek(123)`) + require.NoError(t, err) + + tk.MustExec("insert into t value(dayOfMonth('2017-00-00'))") + tk.MustExec("insert into t value(dayOfMonth('0000-00-00'))") + tk.MustExec(`update t set a = dayOfMonth("0000-00-00")`) + tk.MustExec("set sql_mode = 'NO_ZERO_DATE';") + tk.MustExec("insert into t value(dayOfMonth('0000-00-00'))") + tk.MustQuery("show warnings").CheckContain("Incorrect datetime value: '0000-00-00 00:00:00.000000'") + tk.MustExec(`update t set a = dayOfMonth("0000-00-00")`) + tk.MustExec("set sql_mode = 'NO_ZERO_DATE,STRICT_TRANS_TABLES';") + _, err = tk.Exec("insert into t value(dayOfMonth('0000-00-00'))") + require.True(t, types.ErrWrongValue.Equal(err)) + tk.MustExec("insert into t value(0)") + _, err = tk.Exec(`update t set a = dayOfMonth("0000-00-00")`) + require.True(t, types.ErrWrongValue.Equal(err)) + _, err = tk.Exec(`delete from t where a = dayOfMonth(123)`) + require.NoError(t, err) + + _, err = tk.Exec("insert into t value(dayOfYear('0000-00-00'))") + require.True(t, types.ErrWrongValue.Equal(err)) + _, err = tk.Exec(`update t set a = dayOfYear("0000-00-00")`) + require.True(t, types.ErrWrongValue.Equal(err)) + _, err = tk.Exec(`delete from t where a = dayOfYear(123)`) + require.NoError(t, err) + + tk.MustExec("set sql_mode = ''") + + // for unix_timestamp + tk.MustExec("SET time_zone = '+00:00';") + tk.MustQuery("SELECT UNIX_TIMESTAMP('1970-01-01 00:00:00.000001');").Check(testkit.Rows("0.000000")) + tk.MustQuery("SELECT UNIX_TIMESTAMP('1970-01-01 00:00:00.999999');").Check(testkit.Rows("0.000000")) + tk.MustQuery("SELECT UNIX_TIMESTAMP('1970-01-01 00:00:01.000000');").Check(testkit.Rows("1.000000")) + tk.MustQuery("SELECT UNIX_TIMESTAMP('2038-01-19 03:14:07.999999');").Check(testkit.Rows("2147483647.999999")) + tk.MustQuery("SELECT UNIX_TIMESTAMP('2038-01-19 03:14:08.000000');").Check(testkit.Rows("2147483648.000000")) + tk.MustQuery("SELECT UNIX_TIMESTAMP('3001-01-18 23:59:59.999999');").Check(testkit.Rows("32536771199.999999")) + tk.MustQuery("SELECT UNIX_TIMESTAMP('3001-01-19 00:00:00.000000');").Check(testkit.Rows("0.000000")) + + result = tk.MustQuery("SELECT UNIX_TIMESTAMP(151113);") + result.Check(testkit.Rows("1447372800")) + result = tk.MustQuery("SELECT UNIX_TIMESTAMP(20151113);") + result.Check(testkit.Rows("1447372800")) + result = tk.MustQuery("SELECT UNIX_TIMESTAMP(151113102019);") + result.Check(testkit.Rows("1447410019")) + result = tk.MustQuery("SELECT UNIX_TIMESTAMP(151113102019e0);") + result.Check(testkit.Rows("1447410019.000000")) + result = tk.MustQuery("SELECT UNIX_TIMESTAMP(15111310201912e-2);") + result.Check(testkit.Rows("1447410019.120000")) + result = tk.MustQuery("SELECT UNIX_TIMESTAMP(151113102019.12);") + result.Check(testkit.Rows("1447410019.12")) + result = tk.MustQuery("SELECT UNIX_TIMESTAMP(151113102019.1234567);") + result.Check(testkit.Rows("1447410019.123457")) + result = tk.MustQuery("SELECT UNIX_TIMESTAMP(20151113102019);") + result.Check(testkit.Rows("1447410019")) + result = tk.MustQuery("SELECT UNIX_TIMESTAMP('2015-11-13 10:20:19');") + result.Check(testkit.Rows("1447410019")) + result = tk.MustQuery("SELECT UNIX_TIMESTAMP('2015-11-13 10:20:19.012');") + result.Check(testkit.Rows("1447410019.012")) + result = tk.MustQuery("SELECT UNIX_TIMESTAMP('1970-01-01 00:00:00');") + result.Check(testkit.Rows("0")) + result = tk.MustQuery("SELECT UNIX_TIMESTAMP('1969-12-31 23:59:59');") + result.Check(testkit.Rows("0")) + result = tk.MustQuery("SELECT UNIX_TIMESTAMP('1970-13-01 00:00:00');") + // FIXME: MySQL returns 0 here. + result.Check(testkit.Rows("")) + result = tk.MustQuery("SELECT UNIX_TIMESTAMP('2038-01-19 03:14:07.999999');") + result.Check(testkit.Rows("2147483647.999999")) + result = tk.MustQuery("SELECT UNIX_TIMESTAMP('3001-01-18 23:59:59.999999');") + result.Check(testkit.Rows("32536771199.999999")) + result = tk.MustQuery("SELECT UNIX_TIMESTAMP('3001-01-19 00:00:00');") + result.Check(testkit.Rows("0")) + result = tk.MustQuery("SELECT UNIX_TIMESTAMP(0);") + result.Check(testkit.Rows("0")) + // result = tk.MustQuery("SELECT UNIX_TIMESTAMP(-1);") + // result.Check(testkit.Rows("0")) + // result = tk.MustQuery("SELECT UNIX_TIMESTAMP(12345);") + // result.Check(testkit.Rows("0")) + result = tk.MustQuery("SELECT UNIX_TIMESTAMP('2017-01-01')") + result.Check(testkit.Rows("1483228800")) + // Test different time zone. + tk.MustExec("SET time_zone = '+08:00';") + result = tk.MustQuery("SELECT UNIX_TIMESTAMP('1970-01-01 00:00:00');") + result.Check(testkit.Rows("0")) + result = tk.MustQuery("SELECT UNIX_TIMESTAMP('1970-01-01 08:00:00');") + result.Check(testkit.Rows("0")) + result = tk.MustQuery("SELECT UNIX_TIMESTAMP('2015-11-13 18:20:19.012'), UNIX_TIMESTAMP('2015-11-13 18:20:19.0123');") + result.Check(testkit.Rows("1447410019.012 1447410019.0123")) + result = tk.MustQuery("SELECT UNIX_TIMESTAMP('2038-01-19 11:14:07.999999');") + result.Check(testkit.Rows("2147483647.999999")) + result = tk.MustQuery("SELECT TIME_FORMAT('bad string', '%H:%i:%s %p');") + result.Check(testkit.Rows("")) + result = tk.MustQuery("SELECT TIME_FORMAT(null, '%H:%i:%s %p');") + result.Check(testkit.Rows("")) + result = tk.MustQuery("SELECT TIME_FORMAT(123, '%H:%i:%s %p');") + result.Check(testkit.Rows("00:01:23 AM")) + + // for monthname + tk.MustExec(`drop table if exists t`) + tk.MustExec(`create table t(a varchar(10))`) + tk.MustExec(`insert into t value("abc")`) + tk.MustExec("set sql_mode = 'STRICT_TRANS_TABLES'") + + tk.MustExec("insert into t value(monthname('0000-00-00'))") + tk.MustExec(`update t set a = monthname("0000-00-00")`) + tk.MustExec("set sql_mode = 'NO_ZERO_DATE'") + tk.MustExec("insert into t value(monthname('0000-00-00'))") + tk.MustQuery("show warnings").CheckContain("Incorrect datetime value: '0000-00-00 00:00:00.000000'") + tk.MustExec(`update t set a = monthname("0000-00-00")`) + tk.MustExec("set sql_mode = ''") + tk.MustExec("insert into t value(monthname('0000-00-00'))") + tk.MustExec("set sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_DATE'") + _, err = tk.Exec(`update t set a = monthname("0000-00-00")`) + require.True(t, types.ErrWrongValue.Equal(err)) + _, err = tk.Exec(`delete from t where a = monthname(123)`) + require.NoError(t, err) + result = tk.MustQuery(`select monthname("2017-12-01"), monthname("0000-00-00"), monthname("0000-01-00"), monthname("0000-01-00 00:00:00")`) + result.Check(testkit.Rows("December January January")) + tk.MustQuery("show warnings").CheckContain("Incorrect datetime value: '0000-00-00 00:00:00.000000'") + + // for dayname + tk.MustExec(`drop table if exists t`) + tk.MustExec(`create table t(a varchar(10))`) + tk.MustExec(`insert into t value("abc")`) + tk.MustExec("set sql_mode = 'STRICT_TRANS_TABLES'") + + _, err = tk.Exec("insert into t value(dayname('0000-00-00'))") + require.True(t, types.ErrWrongValue.Equal(err)) + _, err = tk.Exec(`update t set a = dayname("0000-00-00")`) + require.True(t, types.ErrWrongValue.Equal(err)) + _, err = tk.Exec(`delete from t where a = dayname(123)`) + require.NoError(t, err) + result = tk.MustQuery(`select dayname("2017-12-01"), dayname("0000-00-00"), dayname("0000-01-00"), dayname("0000-01-00 00:00:00")`) + result.Check(testkit.Rows("Friday ")) + tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", + "Warning|1292|Incorrect datetime value: '0000-00-00 00:00:00.000000'", + "Warning|1292|Incorrect datetime value: '0000-01-00 00:00:00.000000'", + "Warning|1292|Incorrect datetime value: '0000-01-00 00:00:00.000000'")) + // for dayname implicit cast to boolean and real + result = tk.MustQuery(`select 1 from dual where dayname('2016-03-07')`) + result.Check(testkit.Rows()) + result = tk.MustQuery(`select 1 from dual where dayname('2016-03-07') is true`) + result.Check(testkit.Rows()) + result = tk.MustQuery(`select 1 from dual where dayname('2016-03-07') is false`) + result.Check(testkit.Rows("1")) + result = tk.MustQuery(`select 1 from dual where dayname('2016-03-08')`) + result.Check(testkit.Rows("1")) + result = tk.MustQuery(`select 1 from dual where dayname('2016-03-08') is true`) + result.Check(testkit.Rows("1")) + result = tk.MustQuery(`select 1 from dual where dayname('2016-03-08') is false`) + result.Check(testkit.Rows()) + result = tk.MustQuery(`select cast(dayname("2016-03-07") as double), cast(dayname("2016-03-08") as double)`) + result.Check(testkit.Rows("0 1")) + + // for sec_to_time + result = tk.MustQuery("select sec_to_time(NULL)") + result.Check(testkit.Rows("")) + result = tk.MustQuery("select sec_to_time(2378), sec_to_time(3864000), sec_to_time(-3864000)") + result.Check(testkit.Rows("00:39:38 838:59:59 -838:59:59")) + result = tk.MustQuery("select sec_to_time(86401.4), sec_to_time(-86401.4), sec_to_time(864014e-1), sec_to_time(-864014e-1), sec_to_time('86401.4'), sec_to_time('-86401.4')") + result.Check(testkit.Rows("24:00:01.4 -24:00:01.4 24:00:01.400000 -24:00:01.400000 24:00:01.400000 -24:00:01.400000")) + result = tk.MustQuery("select sec_to_time(86401.54321), sec_to_time(86401.543212345)") + result.Check(testkit.Rows("24:00:01.54321 24:00:01.543212")) + result = tk.MustQuery("select sec_to_time('123.4'), sec_to_time('123.4567891'), sec_to_time('123')") + result.Check(testkit.Rows("00:02:03.400000 00:02:03.456789 00:02:03.000000")) + + // for time_to_sec + result = tk.MustQuery("select time_to_sec(NULL)") + result.Check(testkit.Rows("")) + result = tk.MustQuery("select time_to_sec('22:23:00'), time_to_sec('00:39:38'), time_to_sec('23:00'), time_to_sec('00:00'), time_to_sec('00:00:00'), time_to_sec('23:59:59')") + result.Check(testkit.Rows("80580 2378 82800 0 0 86399")) + result = tk.MustQuery("select time_to_sec('1:0'), time_to_sec('1:00'), time_to_sec('1:0:0'), time_to_sec('-02:00'), time_to_sec('-02:00:05'), time_to_sec('020005')") + result.Check(testkit.Rows("3600 3600 3600 -7200 -7205 7205")) + result = tk.MustQuery("select time_to_sec('20171222020005'), time_to_sec(020005), time_to_sec(20171222020005), time_to_sec(171222020005)") + result.Check(testkit.Rows("7205 7205 7205 7205")) + + // for str_to_date + result = tk.MustQuery("select str_to_date('01-01-2017', '%d-%m-%Y'), str_to_date('59:20:12 01-01-2017', '%s:%i:%H %d-%m-%Y'), str_to_date('59:20:12', '%s:%i:%H')") + result.Check(testkit.Rows("2017-01-01 2017-01-01 12:20:59 12:20:59")) + result = tk.MustQuery("select str_to_date('aaa01-01-2017', 'aaa%d-%m-%Y'), str_to_date('59:20:12 aaa01-01-2017', '%s:%i:%H aaa%d-%m-%Y'), str_to_date('59:20:12aaa', '%s:%i:%Haaa')") + result.Check(testkit.Rows("2017-01-01 2017-01-01 12:20:59 12:20:59")) + + result = tk.MustQuery("select str_to_date('01-01-2017', '%d'), str_to_date('59', '%d-%Y')") + // TODO: MySQL returns " ". + result.Check(testkit.Rows("0000-00-01 ")) + result = tk.MustQuery("show warnings") + result.Sort().Check(testkit.RowsWithSep("|", + "Warning|1292|Incorrect datetime value: '0000-00-00 00:00:00'", + "Warning|1292|Truncated incorrect datetime value: '01-01-2017'")) + + result = tk.MustQuery("select str_to_date('2018-6-1', '%Y-%m-%d'), str_to_date('2018-6-1', '%Y-%c-%d'), str_to_date('59:20:1', '%s:%i:%k'), str_to_date('59:20:1', '%s:%i:%l')") + result.Check(testkit.Rows("2018-06-01 2018-06-01 01:20:59 01:20:59")) + + result = tk.MustQuery("select str_to_date('2020-07-04 11:22:33 PM c', '%Y-%m-%d %r')") + result.Check(testkit.Rows("2020-07-04 23:22:33")) + result = tk.MustQuery("show warnings") + result.Check(testkit.RowsWithSep("|", "Warning|1292|Truncated incorrect datetime value: '2020-07-04 11:22:33 PM c'")) + + result = tk.MustQuery("select str_to_date('11:22:33 PM', ' %r')") + result.Check(testkit.Rows("23:22:33")) + result = tk.MustQuery("show warnings") + result.Check(testkit.Rows()) + + // for maketime + tk.MustExec(`drop table if exists t`) + tk.MustExec(`create table t(a double, b float, c decimal(10,4));`) + tk.MustExec(`insert into t value(1.23, 2.34, 3.1415)`) + result = tk.MustQuery("select maketime(1,1,a), maketime(2,2,b), maketime(3,3,c) from t;") + result.Check(testkit.Rows("01:01:01.230000 02:02:02.340000 03:03:03.1415")) + result = tk.MustQuery("select maketime(12, 13, 14), maketime('12', '15', 30.1), maketime(0, 1, 59.1), maketime(0, 1, '59.1'), maketime(0, 1, 59.5)") + result.Check(testkit.Rows("12:13:14 12:15:30.1 00:01:59.1 00:01:59.100000 00:01:59.5")) + result = tk.MustQuery("select maketime(12, 15, 60), maketime(12, 15, '60'), maketime(12, 60, 0), maketime(12, 15, null)") + result.Check(testkit.Rows(" ")) + result = tk.MustQuery("select maketime('', '', ''), maketime('h', 'm', 's');") + result.Check(testkit.Rows("00:00:00.000000 00:00:00.000000")) + + // for get_format + result = tk.MustQuery(`select GET_FORMAT(DATE,'USA'), GET_FORMAT(DATE,'JIS'), GET_FORMAT(DATE,'ISO'), GET_FORMAT(DATE,'EUR'), + GET_FORMAT(DATE,'INTERNAL'), GET_FORMAT(DATETIME,'USA') , GET_FORMAT(DATETIME,'JIS'), GET_FORMAT(DATETIME,'ISO'), + GET_FORMAT(DATETIME,'EUR') , GET_FORMAT(DATETIME,'INTERNAL'), GET_FORMAT(TIME,'USA') , GET_FORMAT(TIME,'JIS'), + GET_FORMAT(TIME,'ISO'), GET_FORMAT(TIME,'EUR'), GET_FORMAT(TIME,'INTERNAL')`) + result.Check(testkit.Rows("%m.%d.%Y %Y-%m-%d %Y-%m-%d %d.%m.%Y %Y%m%d %Y-%m-%d %H.%i.%s %Y-%m-%d %H:%i:%s %Y-%m-%d %H:%i:%s %Y-%m-%d %H.%i.%s %Y%m%d%H%i%s %h:%i:%s %p %H:%i:%s %H:%i:%s %H.%i.%s %H%i%s")) + + // for convert_tz + result = tk.MustQuery(`select convert_tz("2004-01-01 12:00:00", "+00:00", "+10:32"), convert_tz("2004-01-01 12:00:00.01", "+00:00", "+10:32"), convert_tz("2004-01-01 12:00:00.01234567", "+00:00", "+10:32");`) + result.Check(testkit.Rows("2004-01-01 22:32:00 2004-01-01 22:32:00.01 2004-01-01 22:32:00.012346")) + result = tk.MustQuery(`select convert_tz(20040101, "+00:00", "+10:32"), convert_tz(20040101.01, "+00:00", "+10:32"), convert_tz(20040101.01234567, "+00:00", "+10:32");`) + result.Check(testkit.Rows("2004-01-01 10:32:00 2004-01-01 10:32:00.00 2004-01-01 10:32:00.000000")) + result = tk.MustQuery(`select convert_tz(NULL, "+00:00", "+10:32"), convert_tz("2004-01-01 12:00:00", NULL, "+10:32"), convert_tz("2004-01-01 12:00:00", "+00:00", NULL);`) + result.Check(testkit.Rows(" ")) + result = tk.MustQuery(`select convert_tz("a", "+00:00", "+10:32"), convert_tz("2004-01-01 12:00:00", "a", "+10:32"), convert_tz("2004-01-01 12:00:00", "+00:00", "a");`) + result.Check(testkit.Rows(" ")) + result = tk.MustQuery(`select convert_tz("", "+00:00", "+10:32"), convert_tz("2004-01-01 12:00:00", "", "+10:32"), convert_tz("2004-01-01 12:00:00", "+00:00", "");`) + result.Check(testkit.Rows(" ")) + result = tk.MustQuery(`select convert_tz("0", "+00:00", "+10:32"), convert_tz("2004-01-01 12:00:00", "0", "+10:32"), convert_tz("2004-01-01 12:00:00", "+00:00", "0");`) + result.Check(testkit.Rows(" ")) + + // for from_unixtime + tk.MustExec(`set @@session.time_zone = "+08:00"`) + result = tk.MustQuery(`select from_unixtime(20170101), from_unixtime(20170101.9999999), from_unixtime(20170101.999), from_unixtime(20170101.999, "%Y %D %M %h:%i:%s %x"), from_unixtime(20170101.999, "%Y %D %M %h:%i:%s %x")`) + result.Check(testkit.Rows("1970-08-22 18:48:21 1970-08-22 18:48:22.000000 1970-08-22 18:48:21.999 1970 22nd August 06:48:21 1970 1970 22nd August 06:48:21 1970")) + tk.MustExec(`set @@session.time_zone = "+00:00"`) + result = tk.MustQuery(`select from_unixtime(20170101), from_unixtime(20170101.9999999), from_unixtime(20170101.999), from_unixtime(20170101.999, "%Y %D %M %h:%i:%s %x"), from_unixtime(20170101.999, "%Y %D %M %h:%i:%s %x")`) + result.Check(testkit.Rows("1970-08-22 10:48:21 1970-08-22 10:48:22.000000 1970-08-22 10:48:21.999 1970 22nd August 10:48:21 1970 1970 22nd August 10:48:21 1970")) + tk.MustExec(`set @@session.time_zone = @@global.time_zone`) + + // for extract + result = tk.MustQuery(`select extract(day from '800:12:12'), extract(hour from '800:12:12'), extract(month from 20170101), extract(day_second from '2017-01-01 12:12:12')`) + result.Check(testkit.Rows("12 800 1 1121212")) + result = tk.MustQuery("select extract(day_microsecond from '2017-01-01 12:12:12'), extract(day_microsecond from '01 12:12:12'), extract(day_microsecond from '12:12:12'), extract(day_microsecond from '01 00:00:00.89')") + result.Check(testkit.Rows("1121212000000 361212000000 121212000000 240000890000")) + result = tk.MustQuery("select extract(day_second from '2017-01-01 12:12:12'), extract(day_second from '01 12:12:12'), extract(day_second from '12:12:12'), extract(day_second from '01 00:00:00.89')") + result.Check(testkit.Rows("1121212 361212 121212 240000")) + result = tk.MustQuery("select extract(day_minute from '2017-01-01 12:12:12'), extract(day_minute from '01 12:12:12'), extract(day_minute from '12:12:12'), extract(day_minute from '01 00:00:00.89')") + result.Check(testkit.Rows("11212 3612 1212 2400")) + result = tk.MustQuery("select extract(day_hour from '2017-01-01 12:12:12'), extract(day_hour from '01 12:12:12'), extract(day_hour from '12:12:12'), extract(day_hour from '01 00:00:00.89')") + result.Check(testkit.Rows("112 36 12 24")) + result = tk.MustQuery("select extract(day_microsecond from cast('2017-01-01 12:12:12' as datetime)), extract(day_second from cast('2017-01-01 12:12:12' as datetime)), extract(day_minute from cast('2017-01-01 12:12:12' as datetime)), extract(day_hour from cast('2017-01-01 12:12:12' as datetime))") + result.Check(testkit.Rows("1121212000000 1121212 11212 112")) + result = tk.MustQuery("select extract(day_microsecond from cast(20010101020304.050607 as decimal(20,6))), extract(day_second from cast(20010101020304.050607 as decimal(20,6))), extract(day_minute from cast(20010101020304.050607 as decimal(20,6))), extract(day_hour from cast(20010101020304.050607 as decimal(20,6))), extract(day from cast(20010101020304.050607 as decimal(20,6)))") + result.Check(testkit.Rows("1020304050607 1020304 10203 102 1")) + result = tk.MustQuery("select extract(day_microsecond from cast(1020304.050607 as decimal(20,6))), extract(day_second from cast(1020304.050607 as decimal(20,6))), extract(day_minute from cast(1020304.050607 as decimal(20,6))), extract(day_hour from cast(1020304.050607 as decimal(20,6))), extract(day from cast(1020304.050607 as decimal(20,6)))") + result.Check(testkit.Rows("1020304050607 1020304 10203 102 4")) + + // for adddate, subdate + dateArithmeticalTests := []struct { + Date string + Interval string + Unit string + AddResult string + SubResult string + }{ + {"\"2011-11-11\"", "1", "DAY", "2011-11-12", "2011-11-10"}, + {"NULL", "1", "DAY", "", ""}, + {"\"2011-11-11\"", "NULL", "DAY", "", ""}, + {"\"2011-11-11 10:10:10\"", "1000", "MICROSECOND", "2011-11-11 10:10:10.001000", "2011-11-11 10:10:09.999000"}, + {"\"2011-11-11 10:10:10\"", "\"10\"", "SECOND", "2011-11-11 10:10:20", "2011-11-11 10:10:00"}, + {"\"2011-11-11 10:10:10\"", "\"10\"", "MINUTE", "2011-11-11 10:20:10", "2011-11-11 10:00:10"}, + {"\"2011-11-11 10:10:10\"", "\"10\"", "HOUR", "2011-11-11 20:10:10", "2011-11-11 00:10:10"}, + {"\"2011-11-11 10:10:10\"", "\"11\"", "DAY", "2011-11-22 10:10:10", "2011-10-31 10:10:10"}, + {"\"2011-11-11 10:10:10\"", "\"2\"", "WEEK", "2011-11-25 10:10:10", "2011-10-28 10:10:10"}, + {"\"2011-11-11 10:10:10\"", "\"2\"", "MONTH", "2012-01-11 10:10:10", "2011-09-11 10:10:10"}, + {"\"2011-11-11 10:10:10\"", "\"4\"", "QUARTER", "2012-11-11 10:10:10", "2010-11-11 10:10:10"}, + {"\"2011-11-11 10:10:10\"", "\"2\"", "YEAR", "2013-11-11 10:10:10", "2009-11-11 10:10:10"}, + {"\"2011-11-11 10:10:10\"", "\"10.00100000\"", "SECOND_MICROSECOND", "2011-11-11 10:10:20.100000", "2011-11-11 10:09:59.900000"}, + {"\"2011-11-11 10:10:10\"", "\"10.0010000000\"", "SECOND_MICROSECOND", "2011-11-11 10:10:30", "2011-11-11 10:09:50"}, + {"\"2011-11-11 10:10:10\"", "\"10.0010000010\"", "SECOND_MICROSECOND", "2011-11-11 10:10:30.000010", "2011-11-11 10:09:49.999990"}, + {"\"2011-11-11 10:10:10\"", "\"10:10.100\"", "MINUTE_MICROSECOND", "2011-11-11 10:20:20.100000", "2011-11-11 09:59:59.900000"}, + {"\"2011-11-11 10:10:10\"", "\"10:10\"", "MINUTE_SECOND", "2011-11-11 10:20:20", "2011-11-11 10:00:00"}, + {"\"2011-11-11 10:10:10\"", "\"10:10:10.100\"", "HOUR_MICROSECOND", "2011-11-11 20:20:20.100000", "2011-11-10 23:59:59.900000"}, + {"\"2011-11-11 10:10:10\"", "\"10:10:10\"", "HOUR_SECOND", "2011-11-11 20:20:20", "2011-11-11 00:00:00"}, + {"\"2011-11-11 10:10:10\"", "\"10:10\"", "HOUR_MINUTE", "2011-11-11 20:20:10", "2011-11-11 00:00:10"}, + {"\"2011-11-11 10:10:10\"", "\"11 10:10:10.100\"", "DAY_MICROSECOND", "2011-11-22 20:20:20.100000", "2011-10-30 23:59:59.900000"}, + {"\"2011-11-11 10:10:10\"", "\"11 10:10:10\"", "DAY_SECOND", "2011-11-22 20:20:20", "2011-10-31 00:00:00"}, + {"\"2011-11-11 10:10:10\"", "\"11 10:10\"", "DAY_MINUTE", "2011-11-22 20:20:10", "2011-10-31 00:00:10"}, + {"\"2011-11-11 10:10:10\"", "\"11 10\"", "DAY_HOUR", "2011-11-22 20:10:10", "2011-10-31 00:10:10"}, + {"\"2011-11-11 10:10:10\"", "\"11-1\"", "YEAR_MONTH", "2022-12-11 10:10:10", "2000-10-11 10:10:10"}, + {"\"2011-11-11 10:10:10\"", "\"11-11\"", "YEAR_MONTH", "2023-10-11 10:10:10", "1999-12-11 10:10:10"}, + {"\"2011-11-11 10:10:10\"", "\"20\"", "DAY", "2011-12-01 10:10:10", "2011-10-22 10:10:10"}, + {"\"2011-11-11 10:10:10\"", "19.88", "DAY", "2011-12-01 10:10:10", "2011-10-22 10:10:10"}, + {"\"2011-11-11 10:10:10\"", "\"19.88\"", "DAY", "2011-11-30 10:10:10", "2011-10-23 10:10:10"}, + {"\"2011-11-11 10:10:10\"", "\"prefix19suffix\"", "DAY", "2011-11-30 10:10:10", "2011-10-23 10:10:10"}, + {"\"2011-11-11 10:10:10\"", "\"20-11\"", "DAY", "2011-12-01 10:10:10", "2011-10-22 10:10:10"}, + {"\"2011-11-11 10:10:10\"", "\"20,11\"", "daY", "2011-12-01 10:10:10", "2011-10-22 10:10:10"}, + {"\"2011-11-11 10:10:10\"", "\"1000\"", "dAy", "2014-08-07 10:10:10", "2009-02-14 10:10:10"}, + {"\"2011-11-11 10:10:10\"", "\"true\"", "Day", "2011-11-12 10:10:10", "2011-11-10 10:10:10"}, + {"\"2011-11-11 10:10:10\"", "true", "Day", "2011-11-12 10:10:10", "2011-11-10 10:10:10"}, + {"\"2011-11-11\"", "1", "DAY", "2011-11-12", "2011-11-10"}, + {"\"2011-11-11\"", "10", "HOUR", "2011-11-11 10:00:00", "2011-11-10 14:00:00"}, + {"\"2011-11-11\"", "10", "MINUTE", "2011-11-11 00:10:00", "2011-11-10 23:50:00"}, + {"\"2011-11-11\"", "10", "SECOND", "2011-11-11 00:00:10", "2011-11-10 23:59:50"}, + {"\"2011-11-11\"", "\"10:10\"", "HOUR_MINUTE", "2011-11-11 10:10:00", "2011-11-10 13:50:00"}, + {"\"2011-11-11\"", "\"10:10:10\"", "HOUR_SECOND", "2011-11-11 10:10:10", "2011-11-10 13:49:50"}, + {"\"2011-11-11\"", "\"10:10:10.101010\"", "HOUR_MICROSECOND", "2011-11-11 10:10:10.101010", "2011-11-10 13:49:49.898990"}, + {"\"2011-11-11\"", "\"10:10\"", "MINUTE_SECOND", "2011-11-11 00:10:10", "2011-11-10 23:49:50"}, + {"\"2011-11-11\"", "\"10:10.101010\"", "MINUTE_MICROSECOND", "2011-11-11 00:10:10.101010", "2011-11-10 23:49:49.898990"}, + {"\"2011-11-11\"", "\"10.101010\"", "SECOND_MICROSECOND", "2011-11-11 00:00:10.101010", "2011-11-10 23:59:49.898990"}, + {"\"2011-11-11 00:00:00\"", "1", "DAY", "2011-11-12 00:00:00", "2011-11-10 00:00:00"}, + {"\"2011-11-11 00:00:00\"", "10", "HOUR", "2011-11-11 10:00:00", "2011-11-10 14:00:00"}, + {"\"2011-11-11 00:00:00\"", "10", "MINUTE", "2011-11-11 00:10:00", "2011-11-10 23:50:00"}, + {"\"2011-11-11 00:00:00\"", "10", "SECOND", "2011-11-11 00:00:10", "2011-11-10 23:59:50"}, + {"\"2011-11-11 00:00:00.500\"", "500000", "MICROSECOND", "2011-11-11 00:00:01", "2011-11-11 00:00:00"}, + + {"\"2011-11-11\"", "\"abc1000\"", "MICROSECOND", "2011-11-11 00:00:00", "2011-11-11 00:00:00"}, + {"\"20111111 10:10:10\"", "\"1\"", "DAY", "", ""}, + {"\"2011-11-11\"", "\"10\"", "SECOND_MICROSECOND", "2011-11-11 00:00:00.100000", "2011-11-10 23:59:59.900000"}, + {"\"2011-11-11\"", "\"10.0000\"", "MINUTE_MICROSECOND", "2011-11-11 00:00:10", "2011-11-10 23:59:50"}, + {"\"2011-11-11\"", "\"10:10:10\"", "MINUTE_MICROSECOND", "2011-11-11 00:10:10.100000", "2011-11-10 23:49:49.900000"}, + + {"cast(\"2011-11-11\" as datetime)", "\"10:10:10\"", "MINUTE_MICROSECOND", "2011-11-11 00:10:10.100000", "2011-11-10 23:49:49.900000"}, + {"cast(\"2011-11-11\" as datetime)", "\"1000000\"", "MICROSECOND", "2011-11-11 00:00:01.000000", "2011-11-10 23:59:59.000000"}, + {"cast(\"2011-11-11 00:00:00\" as datetime)", "1", "DAY", "2011-11-12 00:00:00", "2011-11-10 00:00:00"}, + {"cast(\"2011-11-11 00:00:00\" as datetime)", "10", "HOUR", "2011-11-11 10:00:00", "2011-11-10 14:00:00"}, + {"cast(\"2011-11-11 00:00:00\" as datetime)", "10", "MINUTE", "2011-11-11 00:10:00", "2011-11-10 23:50:00"}, + {"cast(\"2011-11-11 00:00:00\" as datetime)", "10", "SECOND", "2011-11-11 00:00:10", "2011-11-10 23:59:50"}, + + {"cast(\"2011-11-11 00:00:00\" as datetime)", "\"1\"", "DAY", "2011-11-12 00:00:00", "2011-11-10 00:00:00"}, + {"cast(\"2011-11-11 00:00:00\" as datetime)", "\"10\"", "HOUR", "2011-11-11 10:00:00", "2011-11-10 14:00:00"}, + {"cast(\"2011-11-11 00:00:00\" as datetime)", "\"10\"", "MINUTE", "2011-11-11 00:10:00", "2011-11-10 23:50:00"}, + {"cast(\"2011-11-11 00:00:00\" as datetime)", "\"10\"", "SECOND", "2011-11-11 00:00:10.000000", "2011-11-10 23:59:50.000000"}, + + {"cast(\"2011-11-11\" as date)", "\"10:10:10\"", "MINUTE_MICROSECOND", "2011-11-11 00:10:10.100000", "2011-11-10 23:49:49.900000"}, + {"cast(\"2011-11-11\" as date)", "\"1000000\"", "MINUTE_MICROSECOND", "2011-11-11 00:00:01.000000", "2011-11-10 23:59:59.000000"}, + {"cast(\"2011-11-11 00:00:00\" as date)", "1", "DAY", "2011-11-12", "2011-11-10"}, + {"cast(\"2011-11-11 00:00:00\" as date)", "10", "HOUR", "2011-11-11 10:00:00", "2011-11-10 14:00:00"}, + {"cast(\"2011-11-11 00:00:00\" as date)", "10", "MINUTE", "2011-11-11 00:10:00", "2011-11-10 23:50:00"}, + {"cast(\"2011-11-11 00:00:00\" as date)", "10", "SECOND", "2011-11-11 00:00:10", "2011-11-10 23:59:50"}, + + {"cast(\"2011-11-11 00:00:00\" as date)", "\"1\"", "DAY", "2011-11-12", "2011-11-10"}, + {"cast(\"2011-11-11 00:00:00\" as date)", "\"10\"", "HOUR", "2011-11-11 10:00:00", "2011-11-10 14:00:00"}, + {"cast(\"2011-11-11 00:00:00\" as date)", "\"10\"", "MINUTE", "2011-11-11 00:10:00", "2011-11-10 23:50:00"}, + {"cast(\"2011-11-11 00:00:00\" as date)", "\"10\"", "SECOND", "2011-11-11 00:00:10.000000", "2011-11-10 23:59:50.000000"}, + + // interval decimal support + {"\"2011-01-01 00:00:00\"", "10.10", "YEAR_MONTH", "2021-11-01 00:00:00", "2000-03-01 00:00:00"}, + {"\"2011-01-01 00:00:00\"", "10.10", "DAY_HOUR", "2011-01-11 10:00:00", "2010-12-21 14:00:00"}, + {"\"2011-01-01 00:00:00\"", "10.10", "HOUR_MINUTE", "2011-01-01 10:10:00", "2010-12-31 13:50:00"}, + {"\"2011-01-01 00:00:00\"", "10.10", "DAY_MINUTE", "2011-01-01 10:10:00", "2010-12-31 13:50:00"}, + {"\"2011-01-01 00:00:00\"", "10.10", "DAY_SECOND", "2011-01-01 00:10:10", "2010-12-31 23:49:50"}, + {"\"2011-01-01 00:00:00\"", "10.10", "HOUR_SECOND", "2011-01-01 00:10:10", "2010-12-31 23:49:50"}, + {"\"2011-01-01 00:00:00\"", "10.10", "MINUTE_SECOND", "2011-01-01 00:10:10", "2010-12-31 23:49:50"}, + {"\"2011-01-01 00:00:00\"", "10.10", "DAY_MICROSECOND", "2011-01-01 00:00:10.100000", "2010-12-31 23:59:49.900000"}, + {"\"2011-01-01 00:00:00\"", "10.10", "HOUR_MICROSECOND", "2011-01-01 00:00:10.100000", "2010-12-31 23:59:49.900000"}, + {"\"2011-01-01 00:00:00\"", "10.10", "MINUTE_MICROSECOND", "2011-01-01 00:00:10.100000", "2010-12-31 23:59:49.900000"}, + {"\"2011-01-01 00:00:00\"", "10.10", "SECOND_MICROSECOND", "2011-01-01 00:00:10.100000", "2010-12-31 23:59:49.900000"}, + {"\"2011-01-01 00:00:00\"", "10.10", "YEAR", "2021-01-01 00:00:00", "2001-01-01 00:00:00"}, + {"\"2011-01-01 00:00:00\"", "10.10", "QUARTER", "2013-07-01 00:00:00", "2008-07-01 00:00:00"}, + {"\"2011-01-01 00:00:00\"", "10.10", "MONTH", "2011-11-01 00:00:00", "2010-03-01 00:00:00"}, + {"\"2011-01-01 00:00:00\"", "10.10", "WEEK", "2011-03-12 00:00:00", "2010-10-23 00:00:00"}, + {"\"2011-01-01 00:00:00\"", "10.10", "DAY", "2011-01-11 00:00:00", "2010-12-22 00:00:00"}, + {"\"2011-01-01 00:00:00\"", "10.10", "HOUR", "2011-01-01 10:00:00", "2010-12-31 14:00:00"}, + {"\"2011-01-01 00:00:00\"", "10.10", "MINUTE", "2011-01-01 00:10:00", "2010-12-31 23:50:00"}, + {"\"2011-01-01 00:00:00\"", "10.10", "SECOND", "2011-01-01 00:00:10.100000", "2010-12-31 23:59:49.900000"}, + {"\"2011-01-01 00:00:00\"", "10.10", "MICROSECOND", "2011-01-01 00:00:00.000010", "2010-12-31 23:59:59.999990"}, + {"\"2011-01-01 00:00:00\"", "10.90", "MICROSECOND", "2011-01-01 00:00:00.000011", "2010-12-31 23:59:59.999989"}, + {"cast(\"2011-01-01\" as date)", "1.1", "SECOND", "2011-01-01 00:00:01.1", "2010-12-31 23:59:58.9"}, + {"cast(\"2011-01-01\" as datetime)", "1.1", "SECOND", "2011-01-01 00:00:01.1", "2010-12-31 23:59:58.9"}, + {"cast(\"2011-01-01\" as datetime(3))", "1.1", "SECOND", "2011-01-01 00:00:01.100", "2010-12-31 23:59:58.900"}, + + {"\"2009-01-01\"", "6/4", "HOUR_MINUTE", "2009-01-04 12:20:00", "2008-12-28 11:40:00"}, + {"\"2009-01-01\"", "6/0", "HOUR_MINUTE", "", ""}, + {"\"1970-01-01 12:00:00\"", "CAST(6/4 AS DECIMAL(3,1))", "HOUR_MINUTE", "1970-01-01 13:05:00", "1970-01-01 10:55:00"}, + // for issue #8077 + {"\"2012-01-02\"", "\"prefix8\"", "HOUR", "2012-01-02 08:00:00", "2012-01-01 16:00:00"}, + {"\"2012-01-02\"", "\"prefix8prefix\"", "HOUR", "2012-01-02 08:00:00", "2012-01-01 16:00:00"}, + {"\"2012-01-02\"", "\"8:00\"", "HOUR", "2012-01-02 08:00:00", "2012-01-01 16:00:00"}, + {"\"2012-01-02\"", "\"8:00:00\"", "HOUR", "2012-01-02 08:00:00", "2012-01-01 16:00:00"}, + } + for _, tc := range dateArithmeticalTests { + addDate := fmt.Sprintf("select adddate(%s, interval %s %s);", tc.Date, tc.Interval, tc.Unit) + subDate := fmt.Sprintf("select subdate(%s, interval %s %s);", tc.Date, tc.Interval, tc.Unit) + result = tk.MustQuery(addDate) + result.Check(testkit.Rows(tc.AddResult)) + result = tk.MustQuery(subDate) + result.Check(testkit.Rows(tc.SubResult)) + } + + // Customized check for the cases of adddate(time, ...) - it returns datetime with current date padded. + // 1. Check if the result contains space, that is, it must contain YMD part. + // 2. Check if the result's suffix matches expected, that is, the HMS part is an exact match. + checkHmsMatch := func(actual []string, expected []interface{}) bool { + return strings.Contains(actual[0], " ") && strings.HasSuffix(actual[0], expected[0].(string)) + } + + // for date_add/sub(duration, ...) + dateAddSubDurationAnyTests := []struct { + Date string + Interval string + Unit string + AddResult string + SubResult string + checkHmsOnly bool // Duration + day returns datetime with current date padded, only check HMS part for them. + }{ + {"cast('01:02:03' as time)", "'1000'", "MICROSECOND", "01:02:03.001000", "01:02:02.999000", false}, + {"cast('01:02:03' as time)", "1000", "MICROSECOND", "01:02:03.001000", "01:02:02.999000", false}, + {"cast('01:02:03' as time)", "'1'", "SECOND", "01:02:04.000000", "01:02:02.000000", false}, + {"cast('01:02:03' as time)", "1", "SECOND", "01:02:04", "01:02:02", false}, + {"cast('01:02:03' as time)", "'1.1'", "SECOND", "01:02:04.100000", "01:02:01.900000", false}, + {"cast('01:02:03' as time)", "1.1", "SECOND", "01:02:04.1", "01:02:01.9", false}, + {"cast('01:02:03' as time(3))", "1.1", "SECOND", "01:02:04.100", "01:02:01.900", false}, + {"cast('01:02:03' as time)", "cast(1.1 as decimal(10, 3))", "SECOND", "01:02:04.100", "01:02:01.900", false}, + {"cast('01:02:03' as time)", "cast('1.5' as double)", "SECOND", "01:02:04.500000", "01:02:01.500000", false}, + {"cast('01:02:03' as time)", "1", "DAY_MICROSECOND", "01:02:03.100000", "01:02:02.900000", false}, + {"cast('01:02:03' as time)", "1.1", "DAY_MICROSECOND", "01:02:04.100000", "01:02:01.900000", false}, + {"cast('01:02:03' as time)", "100", "DAY_MICROSECOND", "01:02:03.100000", "01:02:02.900000", false}, + {"cast('01:02:03' as time)", "1000000", "DAY_MICROSECOND", "01:02:04.000000", "01:02:02.000000", false}, + {"cast('01:02:03' as time)", "1", "DAY_SECOND", "01:02:04", "01:02:02", true}, + {"cast('01:02:03' as time)", "1.1", "DAY_SECOND", "01:03:04", "01:01:02", true}, + {"cast('01:02:03' as time)", "1", "DAY_MINUTE", "01:03:03", "01:01:03", true}, + {"cast('01:02:03' as time)", "1.1", "DAY_MINUTE", "02:03:03", "00:01:03", true}, + {"cast('01:02:03' as time)", "1", "DAY_HOUR", "02:02:03", "00:02:03", true}, + {"cast('01:02:03' as time)", "1.1", "DAY_HOUR", "02:02:03", "00:02:03", true}, + {"cast('01:02:03' as time)", "1", "DAY", "01:02:03", "01:02:03", true}, + {"cast('01:02:03' as time)", "1", "WEEK", "01:02:03", "01:02:03", true}, + {"cast('01:02:03' as time)", "1", "MONTH", "01:02:03", "01:02:03", true}, + {"cast('01:02:03' as time)", "1", "QUARTER", "01:02:03", "01:02:03", true}, + {"cast('01:02:03' as time)", "1", "YEAR", "01:02:03", "01:02:03", true}, + {"cast('01:02:03' as time)", "1", "YEAR_MONTH", "01:02:03", "01:02:03", true}, + } + for _, tc := range dateAddSubDurationAnyTests { + addDate := fmt.Sprintf("select date_add(%s, interval %s %s);", tc.Date, tc.Interval, tc.Unit) + subDate := fmt.Sprintf("select date_sub(%s, interval %s %s);", tc.Date, tc.Interval, tc.Unit) + if tc.checkHmsOnly { + result = tk.MustQuery(addDate) + result.CheckWithFunc(testkit.Rows(tc.AddResult), checkHmsMatch) + result = tk.MustQuery(subDate) + result.CheckWithFunc(testkit.Rows(tc.SubResult), checkHmsMatch) + } else { + result = tk.MustQuery(addDate) + result.Check(testkit.Rows(tc.AddResult)) + result = tk.MustQuery(subDate) + result.Check(testkit.Rows(tc.SubResult)) + } + } + + tk.MustQuery(`select subdate(cast("2000-02-01" as datetime), cast(1 as decimal))`).Check(testkit.Rows("2000-01-31 00:00:00")) + tk.MustQuery(`select subdate(cast("2000-02-01" as datetime), cast(null as decimal))`).Check(testkit.Rows("")) + tk.MustQuery(`select subdate(cast(null as datetime), cast(1 as decimal))`).Check(testkit.Rows("")) + tk.MustQuery(`select subdate(cast("2000-02-01" as datetime), cast("xxx" as decimal))`).Check(testkit.Rows("2000-02-01 00:00:00")) + tk.MustQuery(`select subdate(cast("xxx" as datetime), cast(1 as decimal))`).Check(testkit.Rows("")) + tk.MustQuery(`select subdate(cast(20000101 as SIGNED), cast("1" as decimal))`).Check(testkit.Rows("1999-12-31")) + tk.MustQuery(`select subdate(cast(20000101 as SIGNED), cast("xxx" as decimal))`).Check(testkit.Rows("2000-01-01")) + tk.MustQuery(`select subdate(cast("abc" as SIGNED), cast("1" as decimal))`).Check(testkit.Rows("")) + tk.MustQuery(`select subdate(cast(null as SIGNED), cast("1" as decimal))`).Check(testkit.Rows("")) + tk.MustQuery(`select subdate(cast(20000101 as SIGNED), cast(null as decimal))`).Check(testkit.Rows("")) + tk.MustQuery(`select adddate(cast("2000-02-01" as datetime), cast(1 as decimal))`).Check(testkit.Rows("2000-02-02 00:00:00")) + tk.MustQuery(`select adddate(cast("2000-02-01" as datetime), cast(null as decimal))`).Check(testkit.Rows("")) + tk.MustQuery(`select adddate(cast(null as datetime), cast(1 as decimal))`).Check(testkit.Rows("")) + tk.MustQuery(`select adddate(cast("2000-02-01" as datetime), cast("xxx" as decimal))`).Check(testkit.Rows("2000-02-01 00:00:00")) + tk.MustQuery(`select adddate(cast("xxx" as datetime), cast(1 as decimal))`).Check(testkit.Rows("")) + tk.MustQuery(`select adddate(cast("2000-02-01" as datetime), cast(1 as SIGNED))`).Check(testkit.Rows("2000-02-02 00:00:00")) + tk.MustQuery(`select adddate(cast("2000-02-01" as datetime), cast(null as SIGNED))`).Check(testkit.Rows("")) + tk.MustQuery(`select adddate(cast(null as datetime), cast(1 as SIGNED))`).Check(testkit.Rows("")) + tk.MustQuery(`select adddate(cast("2000-02-01" as datetime), cast("xxx" as SIGNED))`).Check(testkit.Rows("2000-02-01 00:00:00")) + tk.MustQuery(`select adddate(cast("xxx" as datetime), cast(1 as SIGNED))`).Check(testkit.Rows("")) + tk.MustQuery(`select adddate(20100101, cast(1 as decimal))`).Check(testkit.Rows("2010-01-02")) + tk.MustQuery(`select adddate(cast('10:10:10' as time), 1)`).CheckWithFunc(testkit.Rows("10:10:10"), checkHmsMatch) + tk.MustQuery(`select adddate(cast('10:10:10' as time), cast(1 as decimal))`).CheckWithFunc(testkit.Rows("10:10:10"), checkHmsMatch) + + // for localtime, localtimestamp + result = tk.MustQuery(`select localtime() = now(), localtime = now(), localtimestamp() = now(), localtimestamp = now()`) + result.Check(testkit.Rows("1 1 1 1")) + + // for current_timestamp, current_timestamp() + result = tk.MustQuery(`select current_timestamp() = now(), current_timestamp = now()`) + result.Check(testkit.Rows("1 1")) + + // for tidb_parse_tso + tk.MustExec("SET time_zone = '+00:00';") + result = tk.MustQuery(`select tidb_parse_tso(404411537129996288)`) + result.Check(testkit.Rows("2018-11-20 09:53:04.877000")) + result = tk.MustQuery(`select tidb_parse_tso("404411537129996288")`) + result.Check(testkit.Rows("2018-11-20 09:53:04.877000")) + result = tk.MustQuery(`select tidb_parse_tso(1)`) + result.Check(testkit.Rows("1970-01-01 00:00:00.000000")) + result = tk.MustQuery(`select tidb_parse_tso(0)`) + result.Check(testkit.Rows("")) + result = tk.MustQuery(`select tidb_parse_tso(-1)`) + result.Check(testkit.Rows("")) + + // for tidb_parse_tso_logical + result = tk.MustQuery(`SELECT TIDB_PARSE_TSO_LOGICAL(404411537129996288)`) + result.Check(testkit.Rows("0")) + result = tk.MustQuery(`SELECT TIDB_PARSE_TSO_LOGICAL(404411537129996289)`) + result.Check(testkit.Rows("1")) + result = tk.MustQuery(`SELECT TIDB_PARSE_TSO_LOGICAL(404411537129996290)`) + result.Check(testkit.Rows("2")) + result = tk.MustQuery(`SELECT TIDB_PARSE_TSO_LOGICAL(-1)`) + result.Check(testkit.Rows("")) + + // for tidb_bounded_staleness + tk.MustExec("SET time_zone = '+00:00';") + tt := time.Now().UTC() + ts := oracle.GoTimeToTS(tt) + tidbBoundedStalenessTests := []struct { + sql string + injectSafeTS uint64 + expect string + }{ + { + sql: `select tidb_bounded_staleness(DATE_SUB(NOW(), INTERVAL 600 SECOND), DATE_ADD(NOW(), INTERVAL 600 SECOND))`, + injectSafeTS: ts, + expect: tt.Format(types.TimeFSPFormat[:len(types.TimeFSPFormat)-3]), + }, + { + sql: `select tidb_bounded_staleness("2021-04-27 12:00:00.000", "2021-04-27 13:00:00.000")`, + injectSafeTS: func() uint64 { + tt, err := time.Parse("2006-01-02 15:04:05.000", "2021-04-27 13:30:04.877") + require.NoError(t, err) + return oracle.GoTimeToTS(tt) + }(), + expect: "2021-04-27 13:00:00.000", + }, + { + sql: `select tidb_bounded_staleness("2021-04-27 12:00:00.000", "2021-04-27 13:00:00.000")`, + injectSafeTS: func() uint64 { + tt, err := time.Parse("2006-01-02 15:04:05.000", "2021-04-27 11:30:04.877") + require.NoError(t, err) + return oracle.GoTimeToTS(tt) + }(), + expect: "2021-04-27 12:00:00.000", + }, + { + sql: `select tidb_bounded_staleness("2021-04-27 12:00:00.000", "2021-04-27 11:00:00.000")`, + injectSafeTS: 0, + expect: "", + }, + // Time is too small. + { + sql: `select tidb_bounded_staleness("0020-04-27 12:00:00.000", "2021-04-27 11:00:00.000")`, + injectSafeTS: 0, + expect: "1970-01-01 00:00:00.000", + }, + // Wrong value. + { + sql: `select tidb_bounded_staleness(1, 2)`, + injectSafeTS: 0, + expect: "", + }, + { + sql: `select tidb_bounded_staleness("invalid_time_1", "invalid_time_2")`, + injectSafeTS: 0, + expect: "", + }, + } + for _, test := range tidbBoundedStalenessTests { + require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/expression/injectSafeTS", + fmt.Sprintf("return(%v)", test.injectSafeTS))) + tk.MustQuery(test.sql).Check(testkit.Rows(test.expect)) + } + failpoint.Disable("github.com/pingcap/tidb/expression/injectSafeTS") + // test whether tidb_bounded_staleness is deterministic + result = tk.MustQuery(`select tidb_bounded_staleness(NOW(), DATE_ADD(NOW(), INTERVAL 600 SECOND)), tidb_bounded_staleness(NOW(), DATE_ADD(NOW(), INTERVAL 600 SECOND))`) + require.Len(t, result.Rows()[0], 2) + require.Equal(t, result.Rows()[0][0], result.Rows()[0][1]) + preResult := result.Rows()[0][0] + time.Sleep(time.Second) + result = tk.MustQuery(`select tidb_bounded_staleness(NOW(), DATE_ADD(NOW(), INTERVAL 600 SECOND)), tidb_bounded_staleness(NOW(), DATE_ADD(NOW(), INTERVAL 600 SECOND))`) + require.Len(t, result.Rows()[0], 2) + require.Equal(t, result.Rows()[0][0], result.Rows()[0][1]) + require.NotEqual(t, preResult, result.Rows()[0][0]) + + // fix issue 10308 + result = tk.MustQuery("select time(\"- -\");") + result.Check(testkit.Rows("00:00:00")) + tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1292 Truncated incorrect time value: '- -'")) + result = tk.MustQuery("select time(\"---1\");") + result.Check(testkit.Rows("00:00:00")) + tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1292 Truncated incorrect time value: '---1'")) + result = tk.MustQuery("select time(\"-- --1\");") + result.Check(testkit.Rows("00:00:00")) + tk.MustQuery("show warnings;").Check(testkit.Rows("Warning 1292 Truncated incorrect time value: '-- --1'")) + + // fix issue #15185 + result = tk.MustQuery(`select timestamp(11111.1111)`) + result.Check(testkit.Rows("2001-11-11 00:00:00.0000")) + result = tk.MustQuery(`select timestamp(cast(11111.1111 as decimal(60, 5)))`) + result.Check(testkit.Rows("2001-11-11 00:00:00.00000")) + result = tk.MustQuery(`select timestamp(1021121141105.4324)`) + result.Check(testkit.Rows("0102-11-21 14:11:05.4324")) + result = tk.MustQuery(`select timestamp(cast(1021121141105.4324 as decimal(60, 5)))`) + result.Check(testkit.Rows("0102-11-21 14:11:05.43240")) + result = tk.MustQuery(`select timestamp(21121141105.101)`) + result.Check(testkit.Rows("2002-11-21 14:11:05.101")) + result = tk.MustQuery(`select timestamp(cast(21121141105.101 as decimal(60, 5)))`) + result.Check(testkit.Rows("2002-11-21 14:11:05.10100")) + result = tk.MustQuery(`select timestamp(1121141105.799055)`) + result.Check(testkit.Rows("2000-11-21 14:11:05.799055")) + result = tk.MustQuery(`select timestamp(cast(1121141105.799055 as decimal(60, 5)))`) + result.Check(testkit.Rows("2000-11-21 14:11:05.79906")) + result = tk.MustQuery(`select timestamp(121141105.123)`) + result.Check(testkit.Rows("2000-01-21 14:11:05.123")) + result = tk.MustQuery(`select timestamp(cast(121141105.123 as decimal(60, 5)))`) + result.Check(testkit.Rows("2000-01-21 14:11:05.12300")) + result = tk.MustQuery(`select timestamp(1141105)`) + result.Check(testkit.Rows("0114-11-05 00:00:00")) + result = tk.MustQuery(`select timestamp(cast(1141105 as decimal(60, 5)))`) + result.Check(testkit.Rows("0114-11-05 00:00:00.00000")) + result = tk.MustQuery(`select timestamp(41105.11)`) + result.Check(testkit.Rows("2004-11-05 00:00:00.00")) + result = tk.MustQuery(`select timestamp(cast(41105.11 as decimal(60, 5)))`) + result.Check(testkit.Rows("2004-11-05 00:00:00.00000")) + result = tk.MustQuery(`select timestamp(1105.3)`) + result.Check(testkit.Rows("2000-11-05 00:00:00.0")) + result = tk.MustQuery(`select timestamp(cast(1105.3 as decimal(60, 5)))`) + result.Check(testkit.Rows("2000-11-05 00:00:00.00000")) + result = tk.MustQuery(`select timestamp(105)`) + result.Check(testkit.Rows("2000-01-05 00:00:00")) + result = tk.MustQuery(`select timestamp(cast(105 as decimal(60, 5)))`) + result.Check(testkit.Rows("2000-01-05 00:00:00.00000")) +} + +func TestSetVariables(t *testing.T) { + store := testkit.CreateMockStore(t) + + tk := testkit.NewTestKit(t, store) + _, err := tk.Exec("set sql_mode='adfasdfadsfdasd';") + require.Error(t, err) + _, err = tk.Exec("set @@sql_mode='adfasdfadsfdasd';") + require.Error(t, err) + _, err = tk.Exec("set @@global.sql_mode='adfasdfadsfdasd';") + require.Error(t, err) + _, err = tk.Exec("set @@session.sql_mode='adfasdfadsfdasd';") + require.Error(t, err) + + var r *testkit.Result + _, err = tk.Exec("set @@session.sql_mode=',NO_ZERO_DATE,ANSI,ANSI_QUOTES';") + require.NoError(t, err) + r = tk.MustQuery(`select @@session.sql_mode`) + r.Check(testkit.Rows("NO_ZERO_DATE,REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ONLY_FULL_GROUP_BY,ANSI")) + r = tk.MustQuery(`show variables like 'sql_mode'`) + r.Check(testkit.Rows("sql_mode NO_ZERO_DATE,REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ONLY_FULL_GROUP_BY,ANSI")) + + // for invalid SQL mode. + tk.MustExec("use test") + tk.MustExec("drop table if exists tab0") + tk.MustExec("CREATE TABLE tab0(col1 time)") + _, err = tk.Exec("set sql_mode='STRICT_TRANS_TABLES';") + require.NoError(t, err) + _, err = tk.Exec("INSERT INTO tab0 select cast('999:44:33' as time);") + require.Error(t, err) + require.Error(t, err, "[types:1292]Truncated incorrect time value: '999:44:33'") + _, err = tk.Exec("set sql_mode=' ,';") + require.Error(t, err) + _, err = tk.Exec("INSERT INTO tab0 select cast('999:44:33' as time);") + require.Error(t, err) + require.Error(t, err, "[types:1292]Truncated incorrect time value: '999:44:33'") + + // issue #5478 + _, err = tk.Exec("set session transaction read write;") + require.NoError(t, err) + _, err = tk.Exec("set global transaction read write;") + require.NoError(t, err) + r = tk.MustQuery(`select @@session.tx_read_only, @@global.tx_read_only, @@session.transaction_read_only, @@global.transaction_read_only;`) + r.Check(testkit.Rows("0 0 0 0")) + + _, err = tk.Exec("set session transaction read only;") + require.Error(t, err) + + _, err = tk.Exec("start transaction read only;") + require.Error(t, err) + + _, err = tk.Exec("set tidb_enable_noop_functions=1") + require.NoError(t, err) + + tk.MustExec("set session transaction read only;") + tk.MustExec("start transaction read only;") + + r = tk.MustQuery(`select @@session.tx_read_only, @@global.tx_read_only, @@session.transaction_read_only, @@global.transaction_read_only;`) + r.Check(testkit.Rows("1 0 1 0")) + _, err = tk.Exec("set global transaction read only;") + require.Error(t, err) + tk.MustExec("set global tidb_enable_noop_functions=1;") + tk.MustExec("set global transaction read only;") + r = tk.MustQuery(`select @@session.tx_read_only, @@global.tx_read_only, @@session.transaction_read_only, @@global.transaction_read_only;`) + r.Check(testkit.Rows("1 1 1 1")) + + _, err = tk.Exec("set session transaction read write;") + require.NoError(t, err) + _, err = tk.Exec("set global transaction read write;") + require.NoError(t, err) + r = tk.MustQuery(`select @@session.tx_read_only, @@global.tx_read_only, @@session.transaction_read_only, @@global.transaction_read_only;`) + r.Check(testkit.Rows("0 0 0 0")) + + // reset + tk.MustExec("set tidb_enable_noop_functions=0") + tk.MustExec("set global tidb_enable_noop_functions=1") + + _, err = tk.Exec("set @@global.max_user_connections='';") + require.Error(t, err) + require.Error(t, err, variable.ErrWrongTypeForVar.GenWithStackByArgs("max_user_connections").Error()) + _, err = tk.Exec("set @@global.max_prepared_stmt_count='';") + require.Error(t, err) + require.Error(t, err, variable.ErrWrongTypeForVar.GenWithStackByArgs("max_prepared_stmt_count").Error()) + + // Previously global values were cached. This is incorrect. + // See: https://github.com/pingcap/tidb/issues/24368 + tk.MustQuery("SHOW VARIABLES LIKE 'max_connections'").Check(testkit.Rows("max_connections 0")) + tk.MustExec("SET GLOBAL max_connections=1234") + tk.MustQuery("SHOW VARIABLES LIKE 'max_connections'").Check(testkit.Rows("max_connections 1234")) + // restore + tk.MustExec("SET GLOBAL max_connections=0") +} + +func TestPreparePlanCacheOnCachedTable(t *testing.T) { + store := testkit.CreateMockStore(t) + + tk := testkit.NewTestKit(t, store) + tk.MustExec("set tidb_enable_prepared_plan_cache=ON") + tk.Session() + + var err error + se, err := session.CreateSession4TestWithOpt(store, &session.Opt{ + PreparedPlanCache: plannercore.NewLRUPlanCache(100, 0.1, math.MaxUint64, tk.Session(), false), + }) + require.NoError(t, err) + tk.SetSession(se) + + tk.MustExec("use test") + tk.MustExec("drop table if exists t;") + tk.MustExec("create table t(a int);") + tk.MustExec("alter table t cache") + + var readFromTableCache bool + for i := 0; i < 50; i++ { + tk.MustQuery("select * from t where a = 1") + if tk.Session().GetSessionVars().StmtCtx.ReadFromTableCache { + readFromTableCache = true + break + } + time.Sleep(50 * time.Millisecond) + } + require.True(t, readFromTableCache) + // already read cache after reading first time + tk.MustExec("prepare stmt from 'select * from t where a = ?';") + tk.MustExec("set @a = 1;") + tk.MustExec("execute stmt using @a;") + tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("0")) + tk.MustExec("execute stmt using @a;") + readFromTableCache = tk.Session().GetSessionVars().StmtCtx.ReadFromTableCache + require.True(t, readFromTableCache) + tk.MustQuery("select @@last_plan_from_cache;").Check(testkit.Rows("1")) +} + +func TestIssue16205(t *testing.T) { + store := testkit.CreateMockStore(t) + + tk := testkit.NewTestKit(t, store) + tk.MustExec("set tidb_enable_prepared_plan_cache=ON") + tk.MustExec("use test") + tk.MustExec("prepare stmt from 'select random_bytes(3)'") + rows1 := tk.MustQuery("execute stmt").Rows() + require.Len(t, rows1, 1) + rows2 := tk.MustQuery("execute stmt").Rows() + require.Len(t, rows2, 1) + require.NotEqual(t, rows1[0][0].(string), rows2[0][0].(string)) +} + +// issues 14448, 19383, 17734 +func TestNoopFunctions(t *testing.T) { + store := testkit.CreateMockStore(t) + + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec(`set tidb_enable_non_prepared_plan_cache=0`) // variable changes in the test will not affect the plan cache + 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)") + + message := `.* has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions` + stmts := []string{ + "SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1", + "SELECT * FROM t1 LOCK IN SHARE MODE", + "SELECT * FROM t1 GROUP BY a DESC", + "SELECT * FROM t1 GROUP BY a ASC", + } + + for _, stmt := range stmts { + // test on + tk.MustExec("SET tidb_enable_noop_functions='ON'") + tk.MustExec(stmt) + // test warning + tk.MustExec("SET tidb_enable_noop_functions='WARN'") + tk.MustExec(stmt) + warn := tk.Session().GetSessionVars().StmtCtx.GetWarnings() + require.Regexp(t, message, warn[0].Err.Error()) + // test off + tk.MustExec("SET tidb_enable_noop_functions='OFF'") + _, err := tk.Exec(stmt) + require.Regexp(t, message, err.Error()) + } + + // These statements return a different error message + // to the above. Test for error, not specifically the message. + // After they execute, we need to reset the values because + // otherwise tidb_enable_noop_functions can't be changed. + + stmts = []string{ + "START TRANSACTION READ ONLY", + "SET TRANSACTION READ ONLY", + "SET tx_read_only = 1", + "SET transaction_read_only = 1", + } + + for _, stmt := range stmts { + // test off + tk.MustExec("SET tidb_enable_noop_functions='OFF'") + _, err := tk.Exec(stmt) + require.Error(t, err) + // test warning + tk.MustExec("SET tidb_enable_noop_functions='WARN'") + tk.MustExec(stmt) + warn := tk.Session().GetSessionVars().StmtCtx.GetWarnings() + require.Len(t, warn, 1) + // test on + tk.MustExec("SET tidb_enable_noop_functions='ON'") + tk.MustExec(stmt) + + // Reset (required for future loop iterations and future tests) + tk.MustExec("SET tx_read_only = 0") + tk.MustExec("SET transaction_read_only = 0") + } +} + +func TestCrossDCQuery(t *testing.T) { + store := testkit.CreateMockStore(t) + + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t1") + tk.MustExec("drop placement policy if exists p1") + tk.MustExec("drop placement policy if exists p2") + tk.MustExec("create placement policy p1 leader_constraints='[+zone=sh]'") + tk.MustExec("create placement policy p2 leader_constraints='[+zone=bj]'") + tk.MustExec(`create table t1 (c int primary key, d int,e int,index idx_d(d),index idx_e(e)) +PARTITION BY RANGE (c) ( + PARTITION p0 VALUES LESS THAN (6) placement policy p1, + PARTITION p1 VALUES LESS THAN (11) placement policy p2 +);`) + defer func() { + tk.MustExec("drop table if exists t1") + tk.MustExec("drop placement policy if exists p1") + tk.MustExec("drop placement policy if exists p2") + }() + + tk.MustExec(`insert into t1 (c,d,e) values (1,1,1);`) + tk.MustExec(`insert into t1 (c,d,e) values (2,3,5);`) + tk.MustExec(`insert into t1 (c,d,e) values (3,5,7);`) + + testcases := []struct { + name string + txnScope string + zone string + sql string + expectErr error + }{ + // FIXME: block by https://github.com/pingcap/tidb/issues/21872 + //{ + // name: "cross dc read to sh by holding bj, IndexReader", + // txnScope: "bj", + // sql: "select /*+ USE_INDEX(t1, idx_d) */ d from t1 where c < 5 and d < 1;", + // expectErr: fmt.Errorf(".*can not be read by.*"), + //}, + // FIXME: block by https://github.com/pingcap/tidb/issues/21847 + //{ + // name: "cross dc read to sh by holding bj, BatchPointGet", + // txnScope: "bj", + // sql: "select * from t1 where c in (1,2,3,4);", + // expectErr: fmt.Errorf(".*can not be read by.*"), + //}, + { + name: "cross dc read to sh by holding bj, PointGet", + txnScope: "local", + zone: "bj", + sql: "select * from t1 where c = 1", + expectErr: fmt.Errorf(".*can not be read by.*"), + }, + { + name: "cross dc read to sh by holding bj, IndexLookUp", + txnScope: "local", + zone: "bj", + sql: "select * from t1 use index (idx_d) where c < 5 and d < 5;", + expectErr: fmt.Errorf(".*can not be read by.*"), + }, + { + name: "cross dc read to sh by holding bj, IndexMerge", + txnScope: "local", + zone: "bj", + sql: "select /*+ USE_INDEX_MERGE(t1, idx_d, idx_e) */ * from t1 where c <5 and (d =5 or e=5);", + expectErr: fmt.Errorf(".*can not be read by.*"), + }, + { + name: "cross dc read to sh by holding bj, TableReader", + txnScope: "local", + zone: "bj", + sql: "select * from t1 where c < 6", + expectErr: fmt.Errorf(".*can not be read by.*"), + }, + { + name: "cross dc read to global by holding bj", + txnScope: "local", + zone: "bj", + sql: "select * from t1", + expectErr: fmt.Errorf(".*can not be read by.*"), + }, + { + name: "read sh dc by holding sh", + txnScope: "local", + zone: "sh", + sql: "select * from t1 where c < 6", + expectErr: nil, + }, + { + name: "read sh dc by holding global", + txnScope: "global", + zone: "", + sql: "select * from t1 where c < 6", + expectErr: nil, + }, + } + tk.MustExec("set global tidb_enable_local_txn = on;") + for _, testcase := range testcases { + t.Log(testcase.name) + require.NoError(t, failpoint.Enable("tikvclient/injectTxnScope", + fmt.Sprintf(`return("%v")`, testcase.zone))) + tk.MustExec(fmt.Sprintf("set @@txn_scope='%v'", testcase.txnScope)) + tk.Exec("begin") + res, err := tk.Exec(testcase.sql) + _, resErr := session.GetRows4Test(context.Background(), tk.Session(), res) + var checkErr error + if err != nil { + checkErr = err + } else { + checkErr = resErr + } + if testcase.expectErr != nil { + require.Error(t, checkErr) + require.Regexp(t, ".*can not be read by.*", checkErr.Error()) + } else { + require.NoError(t, checkErr) + } + if res != nil { + res.Close() + } + tk.Exec("commit") + } + require.NoError(t, failpoint.Disable("tikvclient/injectTxnScope")) + tk.MustExec("set global tidb_enable_local_txn = off;") +} + +func TestTiDBRowChecksumBuiltin(t *testing.T) { + store := testkit.CreateMockStore(t) + + checksum := func(cols ...interface{}) uint32 { + buf := make([]byte, 0, 64) + for _, col := range cols { + switch x := col.(type) { + case int: + buf = binary.LittleEndian.AppendUint64(buf, uint64(x)) + case string: + buf = binary.LittleEndian.AppendUint32(buf, uint32(len(x))) + buf = append(buf, []byte(x)...) + } + } + return crc32.ChecksumIEEE(buf) + } + + tk := testkit.NewTestKit(t, store) + tk.MustExec("set global tidb_enable_row_level_checksum = 1") tk.MustExec("use test") - tk.MustExec("CREATE TABLE poi_clearing_time_topic (effective_date datetime DEFAULT NULL , clearing_time int(11) DEFAULT NULL);") - tk.MustExec("insert into poi_clearing_time_topic values ('2023:08:25', 1)") - // shouldn't report they can't find column error and return the right result. - tk.MustQuery("SELECT GROUP_CONCAT(effective_date order by stlmnt_hour DESC) FROM ( SELECT (COALESCE(pct.clearing_time, 0)/3600000) AS stlmnt_hour ,COALESCE(pct.effective_date, '1970-01-01 08:00:00') AS effective_date FROM poi_clearing_time_topic pct ORDER BY pct.effective_date DESC ) a;").Check(testkit.Rows("2023-08-25 00:00:00")) + tk.MustExec("create table t (id int primary key, c int)") + + // row with 2 checksums + tk.MustExec("insert into t values (1, 10)") + tk.MustExec("alter table t change column c c varchar(10)") + checksum1 := fmt.Sprintf("%d,%d", checksum(1, 10), checksum(1, "10")) + // row with 1 checksum + tk.Session().GetSessionVars().EnableRowLevelChecksum = true + tk.MustExec("insert into t values (2, '20')") + checksum2 := fmt.Sprintf("%d", checksum(2, "20")) + // row without checksum + tk.Session().GetSessionVars().EnableRowLevelChecksum = false + tk.MustExec("insert into t values (3, '30')") + checksum3 := "" + + // fast point-get + tk.MustQuery("select tidb_row_checksum() from t where id = 1").Check(testkit.Rows(checksum1)) + tk.MustQuery("select tidb_row_checksum() from t where id = 2").Check(testkit.Rows(checksum2)) + tk.MustQuery("select tidb_row_checksum() from t where id = 3").Check(testkit.Rows(checksum3)) + // fast batch-point-get + tk.MustQuery("select tidb_row_checksum() from t where id in (1, 2, 3)").Check(testkit.Rows(checksum1, checksum2, checksum3)) + + // non-fast point-get + tk.MustGetDBError("select length(tidb_row_checksum()) from t where id = 1", expression.ErrNotSupportedYet) + tk.MustGetDBError("select c from t where id = 1 and tidb_row_checksum() is not null", expression.ErrNotSupportedYet) + // non-fast batch-point-get + tk.MustGetDBError("select length(tidb_row_checksum()) from t where id in (1, 2, 3)", expression.ErrNotSupportedYet) + tk.MustGetDBError("select c from t where id in (1, 2, 3) and tidb_row_checksum() is not null", expression.ErrNotSupportedYet) + + // other plans + tk.MustGetDBError("select tidb_row_checksum() from t", expression.ErrNotSupportedYet) + tk.MustGetDBError("select tidb_row_checksum() from t where id > 0", expression.ErrNotSupportedYet) } diff --git a/session/nontransactionaltest/BUILD.bazel b/session/nontransactionaltest/BUILD.bazel index ea000f8a6a9cb..506ff14e46ca6 100644 --- a/session/nontransactionaltest/BUILD.bazel +++ b/session/nontransactionaltest/BUILD.bazel @@ -8,7 +8,7 @@ go_test( "nontransactional_test.go", ], flaky = True, - shard_count = 21, + shard_count = 3, deps = [ "//config", "//testkit", diff --git a/session/nontransactionaltest/nontransactional_test.go b/session/nontransactionaltest/nontransactional_test.go index c04fc58edf130..1c741897317a4 100644 --- a/session/nontransactionaltest/nontransactional_test.go +++ b/session/nontransactionaltest/nontransactional_test.go @@ -121,51 +121,6 @@ func testSharding(tables []string, tk *testkit.TestKit, tp string) { } } -func TestNonTransactionalDMLDryRun(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("set @@tidb_max_chunk_size=35") - tk.MustExec("use test") - tk.MustExec("drop table if exists t, t1") - tk.MustExec("create table t(a int, b int, primary key(a, b) clustered)") - tk.MustExec("create table t1(a int, b int, primary key(a, b) clustered)") - for i := 0; i < 100; i++ { - tk.MustExec(fmt.Sprintf("insert into t values ('%d', %d)", i, i*2)) - } - rows := tk.MustQuery("batch on a limit 3 dry run insert into t1 select * from t").Rows() - for _, row := range rows { - col := row[0].(string) - require.True(t, strings.HasPrefix(col, - "INSERT INTO `test`.`t1` SELECT * FROM `test`.`t` WHERE `a` BETWEEN"), col) - } - rows = tk.MustQuery("batch on a limit 3 dry run insert into t1 select * from t on duplicate key update t1.b=t.b").Rows() - for _, row := range rows { - col := row[0].(string) - require.True(t, strings.HasPrefix(col, - "INSERT INTO `test`.`t1` SELECT * FROM `test`.`t` WHERE `a` BETWEEN"), col) - require.True(t, strings.HasSuffix(col, - "ON DUPLICATE KEY UPDATE `t1`.`b`=`t`.`b`"), col) - } - rows = tk.MustQuery("batch on a limit 3 dry run delete from t").Rows() - for _, row := range rows { - col := row[0].(string) - require.True(t, strings.HasPrefix(col, "DELETE FROM `test`.`t` WHERE `a` BETWEEN"), col) - } - rows = tk.MustQuery("batch on a limit 3 dry run update t set b = b + 42").Rows() - for _, row := range rows { - col := row[0].(string) - require.True(t, strings.HasPrefix(col, "UPDATE `test`.`t` SET `b`=(`b` + 42) WHERE `a` BETWEEN"), col) - } - querySQL := "SELECT `a` FROM `test`.`t` WHERE TRUE ORDER BY IF(ISNULL(`a`),0,1),`a`" - tk.MustQuery("batch on a limit 3 dry run query insert into t1 select * from t").Check(testkit.Rows(querySQL)) - tk.MustQuery("batch on a limit 3 dry run query insert into t1 select * from t on duplicate key update t1.b=t.b"). - Check(testkit.Rows(querySQL)) - tk.MustQuery("batch on a limit 3 dry run query delete from t").Check(testkit.Rows(querySQL)) - tk.MustQuery("batch on a limit 3 dry run query update t set b = b + 42").Check(testkit.Rows(querySQL)) - tk.MustQuery("select count(*) from t").Check(testkit.Rows("100")) - tk.MustQuery("select sum(b) from t").Check(testkit.Rows("9900")) -} - func TestNonTransactionalDMLErrorMessage(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -286,325 +241,6 @@ func TestNonTransactionalDMLErrorMessage(t *testing.T) { ) } -func TestNonTransactionalDMLShardingOnTiDBRowID(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("set @@tidb_max_chunk_size=35") - tk.MustExec("use test") - tk.MustExec("create table t(a int, b int)") - tk.MustExec("create table t1(a int, b int, unique key(a))") - for i := 0; i < 100; i++ { - tk.MustExec(fmt.Sprintf("insert into t values ('%d', %d)", i, i*2)) - } - // auto select results in full col name - tk.MustQuery("batch limit 3 dry run delete from t").Check( - testkit.Rows( - "DELETE FROM `test`.`t` WHERE `test`.`t`.`_tidb_rowid` BETWEEN 1 AND 3", - "DELETE FROM `test`.`t` WHERE `test`.`t`.`_tidb_rowid` BETWEEN 100 AND 100", - ), - ) - tk.MustQuery("batch limit 3 dry run update t set b = 42").Check( - testkit.Rows( - "UPDATE `test`.`t` SET `b`=42 WHERE `test`.`t`.`_tidb_rowid` BETWEEN 1 AND 3", - "UPDATE `test`.`t` SET `b`=42 WHERE `test`.`t`.`_tidb_rowid` BETWEEN 100 AND 100", - ), - ) - tk.MustQuery("batch limit 3 dry run insert into t1 select * from t").Check( - testkit.Rows( - "INSERT INTO `test`.`t1` SELECT * FROM `test`.`t` WHERE `test`.`t`.`_tidb_rowid` BETWEEN 1 AND 3", - "INSERT INTO `test`.`t1` SELECT * FROM `test`.`t` WHERE `test`.`t`.`_tidb_rowid` BETWEEN 100 AND 100", - ), - ) - tk.MustQuery("batch limit 3 dry run insert into t1 select * from t on duplicate key update t1.b=t.b").Check( - testkit.Rows( - "INSERT INTO `test`.`t1` SELECT * FROM `test`.`t` WHERE `test`.`t`.`_tidb_rowid` BETWEEN 1 AND 3"+ - " ON DUPLICATE KEY UPDATE `t1`.`b`=`t`.`b`", - "INSERT INTO `test`.`t1` SELECT * FROM `test`.`t` WHERE `test`.`t`.`_tidb_rowid` BETWEEN 100 AND 100"+ - " ON DUPLICATE KEY UPDATE `t1`.`b`=`t`.`b`", - ), - ) - - // otherwise the name is the same as what is given - tk.MustQuery("batch on _tidb_rowid limit 3 dry run delete from t").Check( - testkit.Rows( - "DELETE FROM `test`.`t` WHERE `_tidb_rowid` BETWEEN 1 AND 3", - "DELETE FROM `test`.`t` WHERE `_tidb_rowid` BETWEEN 100 AND 100", - ), - ) - tk.MustQuery("batch on t._tidb_rowid limit 3 dry run delete from t").Check( - testkit.Rows( - "DELETE FROM `test`.`t` WHERE `t`.`_tidb_rowid` BETWEEN 1 AND 3", - "DELETE FROM `test`.`t` WHERE `t`.`_tidb_rowid` BETWEEN 100 AND 100", - ), - ) - tk.MustQuery("batch on _tidb_rowid limit 3 dry run update t set b = 42").Check( - testkit.Rows( - "UPDATE `test`.`t` SET `b`=42 WHERE `_tidb_rowid` BETWEEN 1 AND 3", - "UPDATE `test`.`t` SET `b`=42 WHERE `_tidb_rowid` BETWEEN 100 AND 100", - ), - ) - tk.MustQuery("batch on t._tidb_rowid limit 3 dry run update t set b = 42").Check( - testkit.Rows( - "UPDATE `test`.`t` SET `b`=42 WHERE `t`.`_tidb_rowid` BETWEEN 1 AND 3", - "UPDATE `test`.`t` SET `b`=42 WHERE `t`.`_tidb_rowid` BETWEEN 100 AND 100", - ), - ) - tk.MustQuery("batch on _tidb_rowid limit 3 dry run insert into t1 select * from t").Check( - testkit.Rows( - "INSERT INTO `test`.`t1` SELECT * FROM `test`.`t` WHERE `_tidb_rowid` BETWEEN 1 AND 3", - "INSERT INTO `test`.`t1` SELECT * FROM `test`.`t` WHERE `_tidb_rowid` BETWEEN 100 AND 100", - ), - ) - tk.MustQuery("batch on t._tidb_rowid limit 3 dry run insert into t1 select * from t").Check( - testkit.Rows( - "INSERT INTO `test`.`t1` SELECT * FROM `test`.`t` WHERE `t`.`_tidb_rowid` BETWEEN 1 AND 3", - "INSERT INTO `test`.`t1` SELECT * FROM `test`.`t` WHERE `t`.`_tidb_rowid` BETWEEN 100 AND 100", - ), - ) - tk.MustQuery("batch on _tidb_rowid limit 3 dry run insert into t1 select * from t on duplicate key update t1.b=t.b").Check( - testkit.Rows( - "INSERT INTO `test`.`t1` SELECT * FROM `test`.`t` WHERE `_tidb_rowid` BETWEEN 1 AND 3"+ - " ON DUPLICATE KEY UPDATE `t1`.`b`=`t`.`b`", - "INSERT INTO `test`.`t1` SELECT * FROM `test`.`t` WHERE `_tidb_rowid` BETWEEN 100 AND 100"+ - " ON DUPLICATE KEY UPDATE `t1`.`b`=`t`.`b`", - ), - ) - tk.MustQuery("batch on t._tidb_rowid limit 3 dry run insert into t1 select * from t on duplicate key update t1.b=t.b").Check( - testkit.Rows( - "INSERT INTO `test`.`t1` SELECT * FROM `test`.`t` WHERE `t`.`_tidb_rowid` BETWEEN 1 AND 3"+ - " ON DUPLICATE KEY UPDATE `t1`.`b`=`t`.`b`", - "INSERT INTO `test`.`t1` SELECT * FROM `test`.`t` WHERE `t`.`_tidb_rowid` BETWEEN 100 AND 100"+ - " ON DUPLICATE KEY UPDATE `t1`.`b`=`t`.`b`", - ), - ) - - tk.MustExec("batch on _tidb_rowid limit 3 insert into t1 select * from t") - tk.MustQuery("select * from t1 order by a"). - Check(tk.MustQuery("select * from t order by a").Rows()) - tk.MustExec("update t1 set b = 0") - tk.MustExec("batch on _tidb_rowid limit 3 insert into t1 select * from t on duplicate key update t1.b=t.b") - tk.MustQuery("select * from t1 order by a"). - Check(tk.MustQuery("select * from t order by a").Rows()) - tk.MustExec("batch on _tidb_rowid limit 3 update t set b = 42") - tk.MustQuery("select sum(b) from t").Check(testkit.Rows("4200")) - tk.MustExec("batch on _tidb_rowid limit 3 delete from t") - tk.MustQuery("select count(*) from t").Check(testkit.Rows("0")) -} - -func TestNonTransactionalWithNull(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("set @@tidb_max_chunk_size=35") - tk.MustExec("use test") - tk.MustExec("drop table if exists t, t1") - tk.MustExec("create table t(a int, b int, key(a))") - tk.MustExec("create table t1(a int, b int, key(a))") - for i := 0; i < 100; i++ { - tk.MustExec(fmt.Sprintf("insert into t values ('%d', %d)", i, i*2)) - tk.MustExec("insert into t values (null, null)") - } - - tk.MustExec("batch on a limit 3 delete from t") - tk.MustQuery("select count(*) from t").Check(testkit.Rows("0")) - - // all values are null - for i := 0; i < 100; i++ { - tk.MustExec("insert into t values (null, null)") - } - tk.MustExec("batch on a limit 3 insert into t1 select * from t") - tk.MustQuery("select * from t1 order by a"). - Check(tk.MustQuery("select * from t order by a").Rows()) - tk.MustExec("batch on a limit 3 insert into t1 select * from t on duplicate key update t1.b=t.b") - tk.MustQuery("select count(*) from t1").Check(testkit.Rows("200")) - tk.MustExec("batch on a limit 3 delete from t") - tk.MustQuery("select count(*) from t").Check(testkit.Rows("0")) -} - -func TestNonTransactionalWithSmallBatch(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("set @@tidb_max_chunk_size=1024") - tk.MustExec("use test") - tk.MustExec("drop table if exists t, t1") - tk.MustExec("create table t(a int, b int, key(a))") - tk.MustExec("create table t1(a int, b int, unique key(a))") - for i := 0; i < 10; i++ { - tk.MustExec(fmt.Sprintf("insert into t values ('%d', %d)", i, i*2)) - tk.MustExec("insert into t values (null, null)") - } - require.Equal(t, 1, len(tk.MustQuery("batch on a limit 1000 dry run delete from t").Rows())) - require.Equal(t, 1, len(tk.MustQuery("batch on a limit 1000 dry run insert into t1 select * from t").Rows())) - require.Equal(t, 1, len(tk.MustQuery("batch on a limit 1000 dry run insert into t1 select * from t on duplicate key update t1.b=t.b").Rows())) - tk.MustExec("batch on a limit 1000 insert into t1 select * from t") - tk.MustQuery("select * from t1 order by a"). - Check(tk.MustQuery("select * from t order by a").Rows()) - tk.MustExec("update t1 set b = a") - // non-null rows will be updated, and null rows will be duplicated - tk.MustExec("batch on a limit 1000 insert into t1 select * from t on duplicate key update t1.b=t.b") - tk.MustQuery("select * from t1 where a is not null order by a"). - Check(tk.MustQuery("select * from t where a is not null order by a").Rows()) - tk.MustQuery("select count(*) from t1 where a is null").Check(testkit.Rows("20")) - tk.MustExec("batch on a limit 1000 delete from t") - tk.MustQuery("select count(*) from t").Check(testkit.Rows("0")) -} - -func TestNonTransactionalWithShardOnGeneratedColumn(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("set @@tidb_max_chunk_size=35") - tk.MustExec("use test") - tk.MustExec("drop table if exists t, t1") - tk.MustExec("create table t(a int, b int, c double as (sqrt(a * a + b * b)), key(c))") - tk.MustExec("create table t1(a int, b int, c double as (sqrt(a * a + b * b)), unique key(c))") - for i := 0; i < 100; i++ { - tk.MustExec(fmt.Sprintf("insert into t values (%d, %d, default)", i, i*2)) - } - tk.MustExec("batch on c limit 10 insert into t1(a, b) select a, b from t") - tk.MustQuery("select * from t1 order by a"). - Check(tk.MustQuery("select * from t order by a").Rows()) - // swap a and b - tk.MustExec("update t1 set a=b, b=a") - tk.MustQuery("select b, a from t1 order by a"). - Check(tk.MustQuery("select a, b from t order by a").Rows()) - tk.MustExec("batch on c limit 10 insert into t1(a, b) select a, b from t on duplicate key update t1.a=t.a, t1.b=t.b") - // insert on duplicate key update should swap back a and b - tk.MustQuery("select * from t1 order by a"). - Check(tk.MustQuery("select * from t order by a").Rows()) - tk.MustExec("batch on c limit 10 delete from t") - tk.MustQuery("select count(*) from t").Check(testkit.Rows("0")) -} - -func TestNonTransactionalWithAutoDetectShardColumn(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("set @@tidb_max_chunk_size=35") - tk.MustExec("use test") - - goodTables := []string{ - "create table t(a int, b int)", - "create table t(a int, b int, primary key(a) clustered)", - "create table t(a int, b int, primary key(a) nonclustered)", - "create table t(a int, b int, primary key(a, b) nonclustered)", - "create table t(a varchar(30), b int, primary key(a) clustered)", - "create table t(a varchar(30), b int, primary key(a, b) nonclustered)", - } - badTables := []string{ - "create table t(a int, b int, primary key(a, b) clustered)", - "create table t(a varchar(30), b int, primary key(a, b) clustered)", - } - - testFunc := func(table string, expectSuccess bool) { - tk.MustExec("drop table if exists t, t1") - tk.MustExec(table) - tk.MustExec(strings.Replace(table, "create table t", "create table t1", 1)) - for i := 0; i < 100; i++ { - tk.MustExec(fmt.Sprintf("insert into t values ('%d', %d)", i, i*2)) - } - _, err := tk.Exec("batch limit 3 insert into t1 select * from t") - require.Equal(t, expectSuccess, err == nil) - _, err = tk.Exec("batch limit 3 insert into t1 select * from t on duplicate key update t1.a=t.a, t1.b=t.b") - require.Equal(t, expectSuccess, err == nil) - _, err = tk.Exec("batch limit 3 delete from t") - require.Equal(t, expectSuccess, err == nil) - } - - for _, table := range goodTables { - testFunc(table, true) - } - for _, table := range badTables { - testFunc(table, false) - } -} - -func TestNonTransactionalWithInvisibleIndex(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("set @@tidb_max_chunk_size=35") - tk.MustExec("use test") - tk.MustExec("drop table if exists t, t1") - tk.MustExec("create table t(a int, b int)") - tk.MustExec("create table t1(a int, b int)") - for i := 0; i < 100; i++ { - tk.MustExec(fmt.Sprintf("insert into t values (%d, %d)", i, i*2)) - } - err := tk.ExecToErr("batch on a limit 10 insert into t1 select * from t") - require.Error(t, err) - err = tk.ExecToErr("batch on a limit 10 insert into t1 select * from t on duplicate key update t1.b=t.b") - require.Error(t, err) - err = tk.ExecToErr("batch on a limit 10 delete from t") - require.Error(t, err) - tk.MustExec("CREATE UNIQUE INDEX c1 ON t (a) INVISIBLE") - tk.MustExec("CREATE UNIQUE INDEX c1 ON t1 (a) INVISIBLE") - err = tk.ExecToErr("batch on a limit 10 insert into t1 select * from t") - require.Error(t, err) - err = tk.ExecToErr("batch on a limit 10 insert into t1 select * from t on duplicate key update t1.b=t.b") - require.Error(t, err) - err = tk.ExecToErr("batch on a limit 10 delete from t") - require.Error(t, err) - tk.MustExec("CREATE UNIQUE INDEX c2 ON t (a)") - tk.MustExec("CREATE UNIQUE INDEX c2 ON t1 (a)") - tk.MustExec("batch on a limit 10 insert into t1 select * from t") - tk.MustQuery("select * from t1 order by a"). - Check(tk.MustQuery("select * from t order by a").Rows()) - tk.MustExec("update t1 set b=a") - tk.MustExec("batch on a limit 10 insert into t1 select * from t on duplicate key update t1.b=t.b") - tk.MustQuery("select * from t1 order by a"). - Check(tk.MustQuery("select * from t order by a").Rows()) - tk.MustExec("batch on a limit 10 delete from t") - tk.MustQuery("select count(*) from t").Check(testkit.Rows("0")) -} - -func TestNonTransactionalWithIgnoreSelectLimit(t *testing.T) { - store := testkit.CreateMockStore(t) - checkTk := testkit.NewTestKit(t, store) - checkTk.MustExec("use test") - tk := testkit.NewTestKit(t, store) - tk.MustExec("set @@tidb_max_chunk_size=35") - tk.MustExec("set @@sql_select_limit=3") - tk.MustExec("use test") - tk.MustExec("drop table if exists t, t1") - tk.MustExec("create table t(a int, b int, key(a))") - tk.MustExec("create table t1(a int, b int, unique key(a))") - for i := 0; i < 100; i++ { - tk.MustExec(fmt.Sprintf("insert into t values (%d, %d)", i, i*2)) - } - tk.MustExec("batch on a limit 10 insert into t1 select * from t") - checkTk.MustQuery("select * from t1 order by a"). - Check(checkTk.MustQuery("select * from t order by a").Rows()) - tk.MustExec("update t1 set b=a") - tk.MustExec("batch on a limit 10 insert into t1 select * from t on duplicate key update t1.b=t.b") - checkTk.MustQuery("select * from t1 order by a"). - Check(checkTk.MustQuery("select * from t order by a").Rows()) - tk.MustExec("batch on a limit 10 delete from t") - checkTk.MustQuery("select * from t").Check(testkit.Rows()) -} - -func TestNonTransactionalWithReadStaleness(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - checkTk := testkit.NewTestKit(t, store) - tk.MustExec("set @@tidb_max_chunk_size=35") - tk.MustExec("set @@tidb_read_staleness=-100") - tk.MustExec("use test") - checkTk.MustExec("use test") - tk.MustExec("drop table if exists t, t1") - tk.MustExec("create table t(a int, b int, key(a))") - tk.MustExec("create table t1(a int, b int, unique key(a))") - rows := make([]string, 0, 100) - for i := 0; i < 100; i++ { - tk.MustExec(fmt.Sprintf("insert into t values (%d, %d)", i, i*2)) - rows = append(rows, fmt.Sprintf("%d %d", i, i*2)) - } - tk.MustExec("batch on a limit 10 insert into t1 select * from t") - checkTk.MustQuery("select * from t1 order by a").Check(testkit.Rows(rows...)) - checkTk.MustExec("update t1 set b=a") - tk.MustExec("batch on a limit 10 insert into t1 select * from t on duplicate key update t1.b=t.b") - tk.MustExec("batch on a limit 10 delete from t") - tk.MustExec("set @@tidb_read_staleness=0") - tk.MustQuery("select * from t").Check(testkit.Rows()) - tk.MustQuery("select * from t1 order by a").Check(testkit.Rows(rows...)) -} - func TestNonTransactionalWithCheckConstraint(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -719,291 +355,3 @@ func TestNonTransactionalWithCheckConstraint(t *testing.T) { err = tk.ExecToErr("batch limit 1 insert into t select * from (select 1, 2) tmp") require.EqualError(t, err, "Non-transactional DML, table name not found in join") } - -func TestNonTransactionalWithOptimizerHints(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t, t1") - tk.MustExec("create table t(a int, b int, key(a))") - tk.MustExec("create table t1(a int, b int, key(a))") - for i := 0; i < 10; i++ { - tk.MustExec(fmt.Sprintf("insert into t values ('%d', %d)", i, i*2)) - } - result := tk.MustQuery("batch on a limit 10 dry run insert into t1 select /*+ USE_INDEX(t) */ * from t").Rows()[0][0].(string) - require.Equal(t, result, "INSERT INTO `test`.`t1` SELECT /*+ USE_INDEX(`t` )*/ * FROM `test`.`t` WHERE `a` BETWEEN 0 AND 9") - result = tk.MustQuery("batch on a limit 10 dry run insert into t1 select /*+ USE_INDEX(t) */ * from t on duplicate key update t1.b=t.b").Rows()[0][0].(string) - require.Equal(t, result, "INSERT INTO `test`.`t1` SELECT /*+ USE_INDEX(`t` )*/ * FROM `test`.`t` WHERE `a` BETWEEN 0 AND 9 ON DUPLICATE KEY UPDATE `t1`.`b`=`t`.`b`") - result = tk.MustQuery("batch on a limit 10 dry run delete /*+ USE_INDEX(t) */ from t").Rows()[0][0].(string) - require.Equal(t, result, "DELETE /*+ USE_INDEX(`t` )*/ FROM `test`.`t` WHERE `a` BETWEEN 0 AND 9") -} - -func TestNonTransactionalWithMultiTables(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("drop table if exists t, t1, t2") - tk.MustExec("create table t(a int, b int, key(a))") - tk.MustExec("create table t1(a int, b int, key(a))") - tk.MustExec("create table t2(a int, b int, key(a))") - for i := 0; i < 100; i++ { - tk.MustExec(fmt.Sprintf("insert into t values (%d, %d)", i, i*2)) - } - tk.MustExec("insert into t1 values (1, 1)") - - err := tk.ExecToErr("batch limit 1 insert into t2 select t.a, t1.b from t, t1 where t.a = t1.a") - require.Error(t, err) - tk.MustQuery("select count(*) from t2").Check(testkit.Rows("0")) - err = tk.ExecToErr("batch limit 1 insert into t2 select t.a, t1.b from t, t1 where t.a = t1.a on duplicate key update t2.b=t.b") - require.Error(t, err) - tk.MustQuery("select count(*) from t2").Check(testkit.Rows("0")) - err = tk.ExecToErr("batch limit 1 delete t, t1 from t, t1 where t.a = t1.a") - require.Error(t, err) - tk.MustQuery("select count(*) from t").Check(testkit.Rows("100")) - tk.MustQuery("select count(*) from t1").Check(testkit.Rows("1")) -} - -func TestNonTransactionalWithAlias(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - goodBatchDeletes := []string{ - "batch on test.t1.a limit 5 delete t1.* from test.t as t1", - "batch on a limit 5 delete t1.* from test.t as t1", - "batch on _tidb_rowid limit 5 delete from test.t as t1", - "batch on t1._tidb_rowid limit 5 delete from test.t as t1", - "batch on test.t1._tidb_rowid limit 5 delete from test.t as t1", - "batch limit 5 delete from test.t as t1", // auto assigns table name to be the alias - } - - badBatchDeletes := []string{ - "batch on test.t.a limit 5 delete t1.* from test.t as t1", - "batch on t.a limit 5 delete t1.* from test.t as t1", - "batch on t._tidb_rowid limit 5 delete from test.t as t1", - "batch on test.t._tidb_rowid limit 5 delete from test.t as t1", - } - - goodBatchInserts := []string{ - "batch on test.t1.a limit 5 insert into test.s select t1.* from test.t as t1", - "batch on a limit 5 insert into test.s select t1.* from test.t as t1", - "batch on _tidb_rowid limit 5 insert into test.s select t1.* from test.t as t1", - "batch on t1._tidb_rowid limit 5 insert into test.s select t1.* from test.t as t1", - "batch on test.t1._tidb_rowid limit 5 insert into test.s select t1.* from test.t as t1", - "batch limit 5 insert into test.s select t1.* from test.t as t1", // auto assigns table name to be the alias - } - - badBatchInserts := []string{ - "batch on test.t.a limit 5 insert into test.s select t1.* from test.t as t1", - "batch on t.a limit 5 insert into test.s select t1.* from test.t as t1", - "batch on t._tidb_rowid limit 5 insert into test.s select t1.* from test.t as t1", - "batch on test.t._tidb_rowid limit 5 insert into test.s select t1.* from test.t as t1", - } - - tk.MustExec("drop table if exists test.t, test.s, test.t2") - tk.MustExec("create table test.t(a int, b int, key(a))") - tk.MustExec("create table test.s(a int, b int, unique key(a))") - tk.MustExec("create table test.t2(a int, b int, key(a))") - - for _, sql := range goodBatchDeletes { - for i := 0; i < 5; i++ { - tk.MustExec(fmt.Sprintf("insert into test.t values (%d, %d)", i, i*2)) - } - tk.MustExec(sql) - tk.MustQuery("select count(*) from test.t").Check(testkit.Rows("0")) - } - - rows := make([]string, 0, 5) - for i := 0; i < 5; i++ { - tk.MustExec(fmt.Sprintf("insert into test.t values (%d, %d)", i, i*2)) - rows = append(rows, fmt.Sprintf("%d %d", i, i*2)) - } - - for _, sql := range goodBatchInserts { - tk.MustExec(sql) - tk.MustQuery("select * from test.s order by a").Check(testkit.Rows(rows...)) - tk.MustExec("update test.s set b=a") - tk.MustExec(sql + " on duplicate key update s.b=t1.b") - tk.MustQuery("select * from test.s order by a").Check(testkit.Rows(rows...)) - tk.MustExec("truncate test.s") - } - - for _, sql := range badBatchDeletes { - err := tk.ExecToErr(sql) - require.Error(t, err) - tk.MustQuery("select count(*) from test.t").Check(testkit.Rows("5")) - } - - for _, sql := range badBatchInserts { - err := tk.ExecToErr(sql) - require.Error(t, err) - tk.MustQuery("select count(*) from test.s").Check(testkit.Rows("0")) - } -} - -func TestNonTransactionalWithShardOnUnsupportedTypes(t *testing.T) { - // When some day the test fail because such types are supported, we can update related docs and consider remove the test. - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t, t1, t2") - tk.MustExec("create table t(a set('e0', 'e1', 'e2'), b int, primary key(a) clustered, key(b))") - tk.MustExec("create table t1(a set('e0', 'e1', 'e2'), b int, primary key(a) clustered, key(b))") - tk.MustExec("insert into t values ('e2,e0', 3)") - err := tk.ExecToErr("batch limit 1 insert into t1 select * from t where a = 'e0,e2'") - require.Error(t, err) - tk.MustQuery("select count(*) from t1").Check(testkit.Rows("0")) - err = tk.ExecToErr("batch limit 1 insert into t1 select * from t where a = 'e0,e2' on duplicate key update t1.b=t.b") - require.Error(t, err) - tk.MustQuery("select count(*) from t1").Check(testkit.Rows("0")) - err = tk.ExecToErr("batch limit 1 delete from t where a = 'e0,e2'") - require.Error(t, err) - tk.MustQuery("select count(*) from t").Check(testkit.Rows("1")) - - tk.MustExec("create table t2(a enum('e0', 'e1', 'e2'), b int, key(a))") - tk.MustExec("insert into t2 values ('e0', 1)") - err = tk.ExecToErr("batch on a limit 1 insert into t1 select * from t2") - require.Error(t, err) - tk.MustQuery("select count(*) from t1").Check(testkit.Rows("0")) - err = tk.ExecToErr("batch on a limit 1 insert into t1 select * from t2 on duplicate key update t1.b=t2.b") - require.Error(t, err) - tk.MustQuery("select count(*) from t1").Check(testkit.Rows("0")) - err = tk.ExecToErr("batch on a limit 1 delete from t2") - require.Error(t, err) - tk.MustQuery("select count(*) from t2").Check(testkit.Rows("1")) -} - -func TestNonTransactionalWithJoin(t *testing.T) { - // insert - // BATCH ON t2.id LIMIT 10000 insert into t1 select id, name from t2 inner join t3 on t2.id = t3.id; - // insert into t1 select id, name from t2 inner join t3 on t2.id = t3.id where t2.id between 1 and 10000 - - // replace - // BATCH ON t1.id LIMIT 10000 replace into t3 - // select * from t1 left join t2 on t1.id = t2.id; - - // update - // BATCH ON t1.id LIMIT 10000 update t1 join t2 on t1.a=t2.a set t1.a=t1.a*1000; - // update t1 join t2 on t1.a=t2.a set t1.a=t1.a*1000 where t1.id between 1 and 10000; - - // delete - // BATCH ON pa.id LIMIT 10000 DELETE pa - // FROM pets_activities pa JOIN pets p ON pa.id = p.pet_id - // WHERE p.order > :order AND p.pet_id = :pet_id - // delete pa - // from pets_activities pa join pets p on pa.id = p.pet_id - // WHERE p.order > :order AND p.pet_id = :pet_id and pa.id between 1 and 10000; - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t(id int, v1 int, v2 int, unique key (id))") - tk.MustExec("create table t2(id int, v int, key i1(id))") - tk.MustExec("create table t3(id int, v int, key i1(id))") - tk.MustExec("insert into t2 values (1, 2), (2, 3), (3, 4)") - tk.MustExec("insert into t3 values (1, 4), (2, 5), (4, 6)") - - tk.MustExec("batch on test.t2.id limit 1 insert into t select t2.id, t2.v, t3.v from t2 join t3 on t2.id=t3.id") - tk.MustQuery("select * from t").Check(testkit.Rows("1 2 4", "2 3 5")) - - tk.MustContainErrMsg( - "batch on id limit 1 insert into t select t2.id, t2.v, t3.v from t2 join t3 on t2.id=t3.id", - "Non-transactional DML, shard column must be fully specified", - ) - tk.MustContainErrMsg( - "batch on test.t1.id limit 1 insert into t select t2.id, t2.v, t3.v from t2 join t3 on t2.id=t3.id", - "shard column test.t1.id is not in the tables involved in the join", - ) - - tk.MustExec("batch on test.t2.id limit 1 update t2 join t3 on t2.id=t3.id set t2.v=t2.v*100, t3.v=t3.v*200") - tk.MustQuery("select * from t2").Check(testkit.Rows("1 200", "2 300", "3 4")) - tk.MustQuery("select * from t3").Check(testkit.Rows("1 800", "2 1000", "4 6")) - - tk.MustExec("batch limit 1 delete t2 from t2 join t3 on t2.id=t3.id") - tk.MustQuery("select * from t2").Check(testkit.Rows("3 4")) - - tk.MustExec("insert into t2 values (1, 11), (2, 22)") - tk.MustExec("batch limit 1 replace into t select t2.id, t2.v, t3.v from t2 join t3 on t2.id=t3.id") - tk.MustQuery("select * from t").Check(testkit.Rows("1 11 800", "2 22 1000")) -} - -func TestAnomalousNontransactionalDML(t *testing.T) { - // some weird and error-prone behavior - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t(id int, v int)") - - // self-insert, this is allowed but can be dangerous - tk.MustExec("insert into t values (1, 1)") - tk.MustExec("batch limit 1 insert into t select * from t") - tk.MustQuery("select * from t").Check(testkit.Rows("1 1", "1 1")) - tk.MustExec("drop table t") - - tk.MustExec("create table t(id int, v int, key(id))") - tk.MustExec("create table t2(id int, v int, key(id))") - tk.MustExec("insert into t values (1, 1), (2, 2), (3, 3)") - tk.MustExec("insert into t2 values (1, 1), (2, 2), (4, 4)") - - tk.MustExec("batch on test.t.id limit 1 update t join t2 on t.id=t2.id set t2.id = t2.id+1") - tk.MustQuery("select * from t2").Check(testkit.Rows("4 1", "4 2", "4 4")) -} - -func TestAlias(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t(id int, v1 int, v2 int, unique key (id))") - tk.MustExec("create table t2(id int, v int, key (id))") - tk.MustExec("create table t3(id int, v int, key (id))") - tk.MustExec("insert into t values (1, 1, 1), (2, 2, 2), (3, 3, 3)") - tk.MustExec("insert into t2 values (1, 1), (2, 20), (4, 40)") - tk.MustExec("insert into t3 values (2, 21), (4, 41), (5, 50)") - tk.MustExec("update t as t1 set v1 = test.t1.id + 1") - tk.MustQuery("select * from t").Check(testkit.Rows("1 2 1", "2 3 2", "3 4 3")) - - tk.MustExec("batch on test.tt2.id limit 1 replace into t select tt2.id, tt2.v, t3.v from t2 as tt2 join t3 on tt2.id=t3.id") - tk.MustQuery("select * from t order by id").Check(testkit.Rows("1 2 1", "2 20 21", "3 4 3", "4 40 41")) -} - -func TestUpdatingShardColumn(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t(id int, v int, unique key(id))") - tk.MustExec("create table t2(id int, v int, unique key(id))") - tk.MustExec("insert into t values (1, 1), (2, 2), (3, 3)") - tk.MustExec("insert into t2 values (1, 1), (2, 2), (4, 4)") - - // update stmt - tk.MustContainErrMsg("batch on id limit 1 update t set id=id+1", "Non-transactional DML, shard column cannot be updated") - // insert on dup update - tk.MustContainErrMsg("batch on id limit 1 insert into t select * from t on duplicate key update t.id=t.id+10", "Non-transactional DML, shard column cannot be updated") - // update with table alias - tk.MustContainErrMsg("batch on id limit 1 update t as t1 set t1.id=t1.id+1", "Non-transactional DML, shard column cannot be updated") - // insert on dup update with table alias - tk.MustContainErrMsg("batch on id limit 1 insert into t select * from t as t1 on duplicate key update t1.id=t1.id+10", "Non-transactional DML, shard column cannot be updated") - // update stmt, multiple table - tk.MustContainErrMsg("batch on test.t.id limit 1 update t join t2 on t.id=t2.id set t.id=t.id+1", "Non-transactional DML, shard column cannot be updated") - // update stmt, multiple table, alias - tk.MustContainErrMsg("batch on test.tt.id limit 1 update t as tt join t2 as tt2 on tt.id=tt2.id set tt.id=tt.id+10", "Non-transactional DML, shard column cannot be updated") -} - -func TestNameAmbiguity(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t(id int, v1 int, v2 int, unique key (id))") - tk.MustExec("create table t2(id int, v int, key (id))") - tk.MustExec("create table t3(id int, v int, key (id))") - - tk.MustExec("create database test2") - tk.MustExec("use test2") - tk.MustExec("create table t(id int, v1 int, v2 int, unique key (id))") - tk.MustExec("create table t2(id int, v int, key (id))") - tk.MustExec("create table t3(id int, v int, key (id))") - tk.MustExec("insert into t values (1, 1, 1), (2, 2, 2)") - - tk.MustExec("use test") - tk.MustExec("batch on id limit 1 insert into t select * from test2.t") - tk.MustQuery("select * from t").Check(testkit.Rows("1 1 1", "2 2 2")) -} diff --git a/tests/integrationtest/r/expression/builtin.result b/tests/integrationtest/r/expression/builtin.result index f7cb299e1012a..b2a7d175e27a9 100644 --- a/tests/integrationtest/r/expression/builtin.result +++ b/tests/integrationtest/r/expression/builtin.result @@ -2920,3 +2920,387 @@ e f g set tidb_enable_vectorized_expression=default; +drop table if exists t; +create table t(a char(41), b char(41), c char(41)); +insert into t values(NULL, '', 'abc'); +select password(a) from t; +password(a) + +select password(b) from t; +password(b) + +select password(c) from t; +password(c) +*0D3CED9BEC10A777AEC23CCC353A8C08A633045E +drop table if exists t; +create table t(a char(10), b int, c double, d datetime, e time, f bit(4), g binary(20), h blob(10), i text(30)); +insert into t values('2', 2, 2.3, "2017-01-01 12:01:01", "12:01:01", 0b1010, "512", "48", "tidb"); +select md5(a), md5(b), md5(c), md5(d), md5(e), md5(f), md5(g), md5(h), md5(i) from t; +md5(a) md5(b) md5(c) md5(d) md5(e) md5(f) md5(g) md5(h) md5(i) +c81e728d9d4c2f636f067f89cc14862c c81e728d9d4c2f636f067f89cc14862c 1a18da63cbbfb49cb9616e6bfd35f662 bad2fa88e1f35919ec7584cc2623a310 991f84d41d7acff6471e536caa8d97db 68b329da9893e34099c7d8ad5cb9c940 5c9f0e9b3b36276731bfba852a73ccc6 642e92efb79421734881b53e1e1b18b6 c337e11bfca9f12ae9b1342901e04379 +select md5('123'), md5(123), md5(''), md5('你好'), md5(NULL), md5('👍'); +md5('123') md5(123) md5('') md5('你好') md5(NULL) md5('👍') +202cb962ac59075b964b07152d234b70 202cb962ac59075b964b07152d234b70 d41d8cd98f00b204e9800998ecf8427e 7eca689f0d3389d9dea66ae112e5cfd7 NULL 0215ac4dab1ecaf71d83f98af5726984 +drop table if exists t; +create table t(a char(10), b int, c double, d datetime, e time, f bit(4), g binary(20), h blob(10), i text(30)); +insert into t values('2', 2, 2.3, "2017-01-01 12:01:01", "12:01:01", 0b1010, "512", "48", "tidb"); +select sha1(a), sha1(b), sha1(c), sha1(d), sha1(e), sha1(f), sha1(g), sha1(h), sha1(i) from t; +sha1(a) sha1(b) sha1(c) sha1(d) sha1(e) sha1(f) sha1(g) sha1(h) sha1(i) +da4b9237bacccdf19c0760cab7aec4a8359010b0 da4b9237bacccdf19c0760cab7aec4a8359010b0 ce0d88c5002b6cf7664052f1fc7d652cbdadccec 6c6956de323692298e4e5ad3028ff491f7ad363c 1906f8aeb5a717ca0f84154724045839330b0ea9 adc83b19e793491b1c6ea0fd8b46cd9f32e592fc 9aadd14ceb737b28697b8026f205f4b3e31de147 64e095fe763fc62418378753f9402623bea9e227 4df56fc09a3e66b48fb896e90b0a6fc02c978e9e +select sha1('123'), sha1(123), sha1(''), sha1('你好'), sha1(NULL); +sha1('123') sha1(123) sha1('') sha1('你好') sha1(NULL) +40bd001563085fc35165329ea1ff5c5ecbdbbeef 40bd001563085fc35165329ea1ff5c5ecbdbbeef da39a3ee5e6b4b0d3255bfef95601890afd80709 440ee0853ad1e99f962b63e459ef992d7c211722 NULL +drop table if exists t; +create table t(a char(10), b int, c double, d datetime, e time, f bit(4), g binary(20), h blob(10), i text(30)); +insert into t values('2', 2, 2.3, "2017-01-01 12:01:01", "12:01:01", 0b1010, "512", "48", "tidb"); +select sha(a), sha(b), sha(c), sha(d), sha(e), sha(f), sha(g), sha(h), sha(i) from t; +sha(a) sha(b) sha(c) sha(d) sha(e) sha(f) sha(g) sha(h) sha(i) +da4b9237bacccdf19c0760cab7aec4a8359010b0 da4b9237bacccdf19c0760cab7aec4a8359010b0 ce0d88c5002b6cf7664052f1fc7d652cbdadccec 6c6956de323692298e4e5ad3028ff491f7ad363c 1906f8aeb5a717ca0f84154724045839330b0ea9 adc83b19e793491b1c6ea0fd8b46cd9f32e592fc 9aadd14ceb737b28697b8026f205f4b3e31de147 64e095fe763fc62418378753f9402623bea9e227 4df56fc09a3e66b48fb896e90b0a6fc02c978e9e +select sha('123'), sha(123), sha(''), sha('你好'), sha(NULL); +sha('123') sha(123) sha('') sha('你好') sha(NULL) +40bd001563085fc35165329ea1ff5c5ecbdbbeef 40bd001563085fc35165329ea1ff5c5ecbdbbeef da39a3ee5e6b4b0d3255bfef95601890afd80709 440ee0853ad1e99f962b63e459ef992d7c211722 NULL +drop table if exists t; +create table t(a char(10), b int, c double, d datetime, e time, f bit(4), g binary(20), h blob(10), i text(30)); +insert into t values('2', 2, 2.3, "2017-01-01 12:01:01", "12:01:01", 0b1010, "512", "48", "tidb"); +select sha2(a, 224), sha2(b, 0), sha2(c, 512), sha2(d, 256), sha2(e, 384), sha2(f, 0), sha2(g, 512), sha2(h, 256), sha2(i, 224) from t; +sha2(a, 224) sha2(b, 0) sha2(c, 512) sha2(d, 256) sha2(e, 384) sha2(f, 0) sha2(g, 512) sha2(h, 256) sha2(i, 224) +58b2aaa0bfae7acc021b3260e941117b529b2e69de878fd7d45c61a9 d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35 42415572557b0ca47e14fa928e83f5746d33f90c74270172cc75c61a78db37fe1485159a4fd75f33ab571b154572a5a300938f7d25969bdd05d8ac9dd6c66123 8c2fa3f276952c92b0b40ed7d27454e44b8399a19769e6bceb40da236e45a20a b11d35f1a37e54d5800d210d8e6b80b42c9f6d20ea7ae548c762383ebaa12c5954c559223c6c7a428e37af96bb4f1e0d 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b 9550da35ea1683abaf5bfa8de68fe02b9c6d756c64589d1ef8367544c254f5f09218a6466cadcee8d74214f0c0b7fb342d1a9f3bd4d406aacf7be59c327c9306 98010bd9270f9b100b6214a21754fd33bdc8d41b2bc9f9dd16ff54d3c34ffd71 a7cddb7346fbc66ab7f803e865b74cbd99aace8e7dabbd8884c148cb +select sha2('123', 512), sha2(123, 512), sha2('', 512), sha2('你好', 224), sha2(NULL, 256), sha2('foo', 123); +sha2('123', 512) sha2(123, 512) sha2('', 512) sha2('你好', 224) sha2(NULL, 256) sha2('foo', 123) +3c9909afec25354d551dae21590bb26e38d53f2173b8d3dc3eee4c047e7ab1c1eb8b85103e3be7ba613b31bb5c9c36214dc9f14a42fd7a2fdb84856bca5c44c2 3c9909afec25354d551dae21590bb26e38d53f2173b8d3dc3eee4c047e7ab1c1eb8b85103e3be7ba613b31bb5c9c36214dc9f14a42fd7a2fdb84856bca5c44c2 cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e e91f006ed4e0882de2f6a3c96ec228a6a5c715f356d00091bce842b5 NULL NULL +drop table if exists t; +create table t(a char(10), b int, c double, d datetime, e time, f bit(4), g binary(20), h blob(10), i text(30)); +insert into t values('2', 2, 2.3, "2017-01-01 12:01:01", "12:01:01", 0b1010, "512", "48", "tidb"); +select sm3(a), sm3(b), sm3(c), sm3(d), sm3(e), sm3(f), sm3(g), sm3(h), sm3(i) from t; +sm3(a) sm3(b) sm3(c) sm3(d) sm3(e) sm3(f) sm3(g) sm3(h) sm3(i) +a0dc2d74b9b0e3c87e076003dbfe472a424cb3032463cb339e351460765a822e a0dc2d74b9b0e3c87e076003dbfe472a424cb3032463cb339e351460765a822e b01f6234a2c1d98af2d8bfb79a8c95677c6e9f5750eb756890f29b33b712f804 8485b2ccde69acf41e333e8fba2f55a1b3556e1a42443095235db1d5c78b25d1 f71ab1aad211e14a47b549e8df55b627c36fa75c1aa75b9682cccae2de00babc f4051d239b766c4111e92979aa31af0b35def053646e347bc41e8b73cfd080bc d42cb1657149a8057cef0ba0ededef7f23c9a2f133bfd286ad0f4a6a8bdb5cb2 19dfccdab83e610f04c414a96edb45007b9a022af01473fccf2073b546ad092e 5e0fb8467c33dae5879fb296c9766c78b0a6fc966372f76ac000cc1fcafc2876 +select sm3('123'), sm3(123), sm3(''), sm3('你好'), sm3(NULL); +sm3('123') sm3(123) sm3('') sm3('你好') sm3(NULL) +6e0f9e14344c5406a0cf5a3b4dfb665f87f4a771a31f7edbb5c72874a32b2957 6e0f9e14344c5406a0cf5a3b4dfb665f87f4a771a31f7edbb5c72874a32b2957 1ab21d8355cfa17f8e61194831e81a8f22bec8c728fefb747ed035eb5082aa2b 78e5c78c5322ca174089e58dc7790acf8ce9d542bee6ae4a5a0797d5e356be61 NULL +drop table if exists t; +create table t(a char(10), b int, c double, d datetime, e time, f bit(4), g binary(20), h blob(10), i text(30)); +insert into t values('2', 2, 2.3, "2017-01-01 12:01:01", "12:01:01", 0b1010, "512", "48", "tidb"); +select sm3(a), sm3(b), sm3(c), sm3(d), sm3(e), sm3(f), sm3(g), sm3(h), sm3(i) from t; +sm3(a) sm3(b) sm3(c) sm3(d) sm3(e) sm3(f) sm3(g) sm3(h) sm3(i) +a0dc2d74b9b0e3c87e076003dbfe472a424cb3032463cb339e351460765a822e a0dc2d74b9b0e3c87e076003dbfe472a424cb3032463cb339e351460765a822e b01f6234a2c1d98af2d8bfb79a8c95677c6e9f5750eb756890f29b33b712f804 8485b2ccde69acf41e333e8fba2f55a1b3556e1a42443095235db1d5c78b25d1 f71ab1aad211e14a47b549e8df55b627c36fa75c1aa75b9682cccae2de00babc f4051d239b766c4111e92979aa31af0b35def053646e347bc41e8b73cfd080bc d42cb1657149a8057cef0ba0ededef7f23c9a2f133bfd286ad0f4a6a8bdb5cb2 19dfccdab83e610f04c414a96edb45007b9a022af01473fccf2073b546ad092e 5e0fb8467c33dae5879fb296c9766c78b0a6fc966372f76ac000cc1fcafc2876 +select sm3('123'), sm3(123), sm3(''), sm3('你好'), sm3(NULL); +sm3('123') sm3(123) sm3('') sm3('你好') sm3(NULL) +6e0f9e14344c5406a0cf5a3b4dfb665f87f4a771a31f7edbb5c72874a32b2957 6e0f9e14344c5406a0cf5a3b4dfb665f87f4a771a31f7edbb5c72874a32b2957 1ab21d8355cfa17f8e61194831e81a8f22bec8c728fefb747ed035eb5082aa2b 78e5c78c5322ca174089e58dc7790acf8ce9d542bee6ae4a5a0797d5e356be61 NULL +drop table if exists t; +create table t(a char(10), b int, c double, d datetime, e time, f bit(4), g binary(20), h blob(10), i text(30)); +insert into t values('2', 2, 2.3, "2017-01-01 12:01:01", "12:01:01", 0b1010, "512", "48", "tidb"); +SET block_encryption_mode='aes-128-ecb'; +select HEX(AES_ENCRYPT(a, 'key')), HEX(AES_ENCRYPT(b, 'key')), HEX(AES_ENCRYPT(c, 'key')), HEX(AES_ENCRYPT(d, 'key')), HEX(AES_ENCRYPT(e, 'key')), HEX(AES_ENCRYPT(f, 'key')), HEX(AES_ENCRYPT(g, 'key')), HEX(AES_ENCRYPT(h, 'key')), HEX(AES_ENCRYPT(i, 'key')) from t; +HEX(AES_ENCRYPT(a, 'key')) HEX(AES_ENCRYPT(b, 'key')) HEX(AES_ENCRYPT(c, 'key')) HEX(AES_ENCRYPT(d, 'key')) HEX(AES_ENCRYPT(e, 'key')) HEX(AES_ENCRYPT(f, 'key')) HEX(AES_ENCRYPT(g, 'key')) HEX(AES_ENCRYPT(h, 'key')) HEX(AES_ENCRYPT(i, 'key')) +B3800B3A3CB4ECE2051A3E80FE373EAC B3800B3A3CB4ECE2051A3E80FE373EAC 9E018F7F2838DBA23C57F0E4CCF93287 E764D3E9D4AF8F926CD0979DDB1D0AF40C208B20A6C39D5D028644885280973A C452FFEEB76D3F5E9B26B8D48F7A228C 181BD5C81CBD36779A3C9DD5FF486B35 CE15F14AC7FF4E56ECCF148DE60E4BEDBDB6900AD51383970A5F32C59B3AC6E3 E1B29995CCF423C75519790F54A08CD2 84525677E95AC97698D22E1125B67E92 +select HEX(AES_ENCRYPT('123', 'foobar')), HEX(AES_ENCRYPT(123, 'foobar')), HEX(AES_ENCRYPT('', 'foobar')), HEX(AES_ENCRYPT('你好', 'foobar')), AES_ENCRYPT(NULL, 'foobar'); +HEX(AES_ENCRYPT('123', 'foobar')) HEX(AES_ENCRYPT(123, 'foobar')) HEX(AES_ENCRYPT('', 'foobar')) HEX(AES_ENCRYPT('你好', 'foobar')) AES_ENCRYPT(NULL, 'foobar') +45ABDD5C4802EFA6771A94C43F805208 45ABDD5C4802EFA6771A94C43F805208 791F1AEB6A6B796E6352BF381895CA0E D0147E2EB856186F146D9F6DE33F9546 NULL +select HEX(AES_ENCRYPT(a, 'key', 'iv')), HEX(AES_ENCRYPT(b, 'key', 'iv')) from t; +HEX(AES_ENCRYPT(a, 'key', 'iv')) HEX(AES_ENCRYPT(b, 'key', 'iv')) +B3800B3A3CB4ECE2051A3E80FE373EAC B3800B3A3CB4ECE2051A3E80FE373EAC +show warnings; +Level Code Message +Warning 1618 option ignored +Warning 1618 option ignored +SET block_encryption_mode='aes-128-cbc'; +select HEX(AES_ENCRYPT(a, 'key', '1234567890123456')), HEX(AES_ENCRYPT(b, 'key', '1234567890123456')), HEX(AES_ENCRYPT(c, 'key', '1234567890123456')), HEX(AES_ENCRYPT(d, 'key', '1234567890123456')), HEX(AES_ENCRYPT(e, 'key', '1234567890123456')), HEX(AES_ENCRYPT(f, 'key', '1234567890123456')), HEX(AES_ENCRYPT(g, 'key', '1234567890123456')), HEX(AES_ENCRYPT(h, 'key', '1234567890123456')), HEX(AES_ENCRYPT(i, 'key', '1234567890123456')) from t; +HEX(AES_ENCRYPT(a, 'key', '1234567890123456')) HEX(AES_ENCRYPT(b, 'key', '1234567890123456')) HEX(AES_ENCRYPT(c, 'key', '1234567890123456')) HEX(AES_ENCRYPT(d, 'key', '1234567890123456')) HEX(AES_ENCRYPT(e, 'key', '1234567890123456')) HEX(AES_ENCRYPT(f, 'key', '1234567890123456')) HEX(AES_ENCRYPT(g, 'key', '1234567890123456')) HEX(AES_ENCRYPT(h, 'key', '1234567890123456')) HEX(AES_ENCRYPT(i, 'key', '1234567890123456')) +341672829F84CB6B0BE690FEC4C4DAE9 341672829F84CB6B0BE690FEC4C4DAE9 D43734E147A12BB96C6897C4BBABA283 16F2C972411948DCEF3659B726D2CCB04AD1379A1A367FA64242058A50211B67 41E71D0C58967C1F50EEC074523946D1 1117D292E2D39C3EAA3B435371BE56FC 8ACB7ECC0883B672D7BD1CFAA9FA5FAF5B731ADE978244CD581F114D591C2E7E D2B13C30937E3251AEDA73859BA32E4B 2CF4A6051FF248A67598A17AA2C17267 +select HEX(AES_ENCRYPT('123', 'foobar', '1234567890123456')), HEX(AES_ENCRYPT(123, 'foobar', '1234567890123456')), HEX(AES_ENCRYPT('', 'foobar', '1234567890123456')), HEX(AES_ENCRYPT('你好', 'foobar', '1234567890123456')), AES_ENCRYPT(NULL, 'foobar', '1234567890123456'); +HEX(AES_ENCRYPT('123', 'foobar', '1234567890123456')) HEX(AES_ENCRYPT(123, 'foobar', '1234567890123456')) HEX(AES_ENCRYPT('', 'foobar', '1234567890123456')) HEX(AES_ENCRYPT('你好', 'foobar', '1234567890123456')) AES_ENCRYPT(NULL, 'foobar', '1234567890123456') +80D5646F07B4654B05A02D9085759770 80D5646F07B4654B05A02D9085759770 B3C14BA15030D2D7E99376DBE011E752 0CD2936EE4FEC7A8CDF6208438B2BC05 NULL +SET block_encryption_mode='aes-128-ofb'; +select HEX(AES_ENCRYPT(a, 'key', '1234567890123456')), HEX(AES_ENCRYPT(b, 'key', '1234567890123456')), HEX(AES_ENCRYPT(c, 'key', '1234567890123456')), HEX(AES_ENCRYPT(d, 'key', '1234567890123456')), HEX(AES_ENCRYPT(e, 'key', '1234567890123456')), HEX(AES_ENCRYPT(f, 'key', '1234567890123456')), HEX(AES_ENCRYPT(g, 'key', '1234567890123456')), HEX(AES_ENCRYPT(h, 'key', '1234567890123456')), HEX(AES_ENCRYPT(i, 'key', '1234567890123456')) from t; +HEX(AES_ENCRYPT(a, 'key', '1234567890123456')) HEX(AES_ENCRYPT(b, 'key', '1234567890123456')) HEX(AES_ENCRYPT(c, 'key', '1234567890123456')) HEX(AES_ENCRYPT(d, 'key', '1234567890123456')) HEX(AES_ENCRYPT(e, 'key', '1234567890123456')) HEX(AES_ENCRYPT(f, 'key', '1234567890123456')) HEX(AES_ENCRYPT(g, 'key', '1234567890123456')) HEX(AES_ENCRYPT(h, 'key', '1234567890123456')) HEX(AES_ENCRYPT(i, 'key', '1234567890123456')) +40 40 40C35C 40DD5EBDFCAA397102386E27DDF97A39ECCEC5 43DF55BAE0A0386D 78 47DC5D8AD19A085C32094E16EFC34A08D6FEF459 46D5 06840BE8 +select HEX(AES_ENCRYPT('123', 'foobar', '1234567890123456')), HEX(AES_ENCRYPT(123, 'foobar', '1234567890123456')), HEX(AES_ENCRYPT('', 'foobar', '1234567890123456')), HEX(AES_ENCRYPT('你好', 'foobar', '1234567890123456')), AES_ENCRYPT(NULL, 'foobar', '1234567890123456'); +HEX(AES_ENCRYPT('123', 'foobar', '1234567890123456')) HEX(AES_ENCRYPT(123, 'foobar', '1234567890123456')) HEX(AES_ENCRYPT('', 'foobar', '1234567890123456')) HEX(AES_ENCRYPT('你好', 'foobar', '1234567890123456')) AES_ENCRYPT(NULL, 'foobar', '1234567890123456') +48E38A 48E38A 9D6C199101C3 NULL +SET block_encryption_mode='aes-192-ofb'; +select HEX(AES_ENCRYPT(a, 'key', '1234567890123456')), HEX(AES_ENCRYPT(b, 'key', '1234567890123456')), HEX(AES_ENCRYPT(c, 'key', '1234567890123456')), HEX(AES_ENCRYPT(d, 'key', '1234567890123456')), HEX(AES_ENCRYPT(e, 'key', '1234567890123456')), HEX(AES_ENCRYPT(f, 'key', '1234567890123456')), HEX(AES_ENCRYPT(g, 'key', '1234567890123456')), HEX(AES_ENCRYPT(h, 'key', '1234567890123456')), HEX(AES_ENCRYPT(i, 'key', '1234567890123456')) from t; +HEX(AES_ENCRYPT(a, 'key', '1234567890123456')) HEX(AES_ENCRYPT(b, 'key', '1234567890123456')) HEX(AES_ENCRYPT(c, 'key', '1234567890123456')) HEX(AES_ENCRYPT(d, 'key', '1234567890123456')) HEX(AES_ENCRYPT(e, 'key', '1234567890123456')) HEX(AES_ENCRYPT(f, 'key', '1234567890123456')) HEX(AES_ENCRYPT(g, 'key', '1234567890123456')) HEX(AES_ENCRYPT(h, 'key', '1234567890123456')) HEX(AES_ENCRYPT(i, 'key', '1234567890123456')) +4B 4B 4B573F 4B493D42572E6477233A429BF3E0AD39DB816D 484B36454B24656B 73 4C483E757A1E555A130B62AAC1DA9D08E1B15C47 4D41 0D106817 +select HEX(AES_ENCRYPT('123', 'foobar', '1234567890123456')), HEX(AES_ENCRYPT(123, 'foobar', '1234567890123456')), HEX(AES_ENCRYPT('', 'foobar', '1234567890123456')), HEX(AES_ENCRYPT('你好', 'foobar', '1234567890123456')), AES_ENCRYPT(NULL, 'foobar', '1234567890123456'); +HEX(AES_ENCRYPT('123', 'foobar', '1234567890123456')) HEX(AES_ENCRYPT(123, 'foobar', '1234567890123456')) HEX(AES_ENCRYPT('', 'foobar', '1234567890123456')) HEX(AES_ENCRYPT('你好', 'foobar', '1234567890123456')) AES_ENCRYPT(NULL, 'foobar', '1234567890123456') +3A76B0 3A76B0 EFF92304268E NULL +SET block_encryption_mode='aes-256-ofb'; +select HEX(AES_ENCRYPT(a, 'key', '1234567890123456')), HEX(AES_ENCRYPT(b, 'key', '1234567890123456')), HEX(AES_ENCRYPT(c, 'key', '1234567890123456')), HEX(AES_ENCRYPT(d, 'key', '1234567890123456')), HEX(AES_ENCRYPT(e, 'key', '1234567890123456')), HEX(AES_ENCRYPT(f, 'key', '1234567890123456')), HEX(AES_ENCRYPT(g, 'key', '1234567890123456')), HEX(AES_ENCRYPT(h, 'key', '1234567890123456')), HEX(AES_ENCRYPT(i, 'key', '1234567890123456')) from t; +HEX(AES_ENCRYPT(a, 'key', '1234567890123456')) HEX(AES_ENCRYPT(b, 'key', '1234567890123456')) HEX(AES_ENCRYPT(c, 'key', '1234567890123456')) HEX(AES_ENCRYPT(d, 'key', '1234567890123456')) HEX(AES_ENCRYPT(e, 'key', '1234567890123456')) HEX(AES_ENCRYPT(f, 'key', '1234567890123456')) HEX(AES_ENCRYPT(g, 'key', '1234567890123456')) HEX(AES_ENCRYPT(h, 'key', '1234567890123456')) HEX(AES_ENCRYPT(i, 'key', '1234567890123456')) +16 16 16D103 16CF01CBC95D33E2ED721CBD930262415A69AD 15CD0ACCD55732FE 2E 11CE02FCE46D02CFDD433C8CA138527060599C35 10C7 5096549E +select HEX(AES_ENCRYPT('123', 'foobar', '1234567890123456')), HEX(AES_ENCRYPT(123, 'foobar', '1234567890123456')), HEX(AES_ENCRYPT('', 'foobar', '1234567890123456')), HEX(AES_ENCRYPT('你好', 'foobar', '1234567890123456')), AES_ENCRYPT(NULL, 'foobar', '1234567890123456'); +HEX(AES_ENCRYPT('123', 'foobar', '1234567890123456')) HEX(AES_ENCRYPT(123, 'foobar', '1234567890123456')) HEX(AES_ENCRYPT('', 'foobar', '1234567890123456')) HEX(AES_ENCRYPT('你好', 'foobar', '1234567890123456')) AES_ENCRYPT(NULL, 'foobar', '1234567890123456') +E842C5 E842C5 3DCD5646767D NULL +SET block_encryption_mode='aes-128-ecb'; +select AES_DECRYPT(AES_ENCRYPT('foo', 'bar'), 'bar'); +AES_DECRYPT(AES_ENCRYPT('foo', 'bar'), 'bar') +foo +select AES_DECRYPT(UNHEX('45ABDD5C4802EFA6771A94C43F805208'), 'foobar'), AES_DECRYPT(UNHEX('791F1AEB6A6B796E6352BF381895CA0E'), 'foobar'), AES_DECRYPT(UNHEX('D0147E2EB856186F146D9F6DE33F9546'), 'foobar'), AES_DECRYPT(NULL, 'foobar'), AES_DECRYPT('SOME_THING_STRANGE', 'foobar'); +AES_DECRYPT(UNHEX('45ABDD5C4802EFA6771A94C43F805208'), 'foobar') AES_DECRYPT(UNHEX('791F1AEB6A6B796E6352BF381895CA0E'), 'foobar') AES_DECRYPT(UNHEX('D0147E2EB856186F146D9F6DE33F9546'), 'foobar') AES_DECRYPT(NULL, 'foobar') AES_DECRYPT('SOME_THING_STRANGE', 'foobar') +123 你好 NULL NULL +SET block_encryption_mode='aes-128-cbc'; +select AES_DECRYPT(AES_ENCRYPT('foo', 'bar', '1234567890123456'), 'bar', '1234567890123456'); +AES_DECRYPT(AES_ENCRYPT('foo', 'bar', '1234567890123456'), 'bar', '1234567890123456') +foo +select AES_DECRYPT(UNHEX('80D5646F07B4654B05A02D9085759770'), 'foobar', '1234567890123456'), AES_DECRYPT(UNHEX('B3C14BA15030D2D7E99376DBE011E752'), 'foobar', '1234567890123456'), AES_DECRYPT(UNHEX('0CD2936EE4FEC7A8CDF6208438B2BC05'), 'foobar', '1234567890123456'), AES_DECRYPT(NULL, 'foobar', '1234567890123456'), AES_DECRYPT('SOME_THING_STRANGE', 'foobar', '1234567890123456'); +AES_DECRYPT(UNHEX('80D5646F07B4654B05A02D9085759770'), 'foobar', '1234567890123456') AES_DECRYPT(UNHEX('B3C14BA15030D2D7E99376DBE011E752'), 'foobar', '1234567890123456') AES_DECRYPT(UNHEX('0CD2936EE4FEC7A8CDF6208438B2BC05'), 'foobar', '1234567890123456') AES_DECRYPT(NULL, 'foobar', '1234567890123456') AES_DECRYPT('SOME_THING_STRANGE', 'foobar', '1234567890123456') +123 你好 NULL NULL +SET block_encryption_mode='aes-128-ofb'; +select AES_DECRYPT(AES_ENCRYPT('foo', 'bar', '1234567890123456'), 'bar', '1234567890123456'); +AES_DECRYPT(AES_ENCRYPT('foo', 'bar', '1234567890123456'), 'bar', '1234567890123456') +foo +select AES_DECRYPT(UNHEX('48E38A'), 'foobar', '1234567890123456'), AES_DECRYPT(UNHEX(''), 'foobar', '1234567890123456'), AES_DECRYPT(UNHEX('9D6C199101C3'), 'foobar', '1234567890123456'), AES_DECRYPT(NULL, 'foobar', '1234567890123456'), HEX(AES_DECRYPT('SOME_THING_STRANGE', 'foobar', '1234567890123456')); +AES_DECRYPT(UNHEX('48E38A'), 'foobar', '1234567890123456') AES_DECRYPT(UNHEX(''), 'foobar', '1234567890123456') AES_DECRYPT(UNHEX('9D6C199101C3'), 'foobar', '1234567890123456') AES_DECRYPT(NULL, 'foobar', '1234567890123456') HEX(AES_DECRYPT('SOME_THING_STRANGE', 'foobar', '1234567890123456')) +123 你好 NULL 2A9EF431FB2ACB022D7F2E7C71EEC48C7D2B +SET block_encryption_mode='aes-192-ofb'; +select AES_DECRYPT(AES_ENCRYPT('foo', 'bar', '1234567890123456'), 'bar', '1234567890123456'); +AES_DECRYPT(AES_ENCRYPT('foo', 'bar', '1234567890123456'), 'bar', '1234567890123456') +foo +select AES_DECRYPT(UNHEX('3A76B0'), 'foobar', '1234567890123456'), AES_DECRYPT(UNHEX(''), 'foobar', '1234567890123456'), AES_DECRYPT(UNHEX('EFF92304268E'), 'foobar', '1234567890123456'), AES_DECRYPT(NULL, 'foobar', '1234567890123456'), HEX(AES_DECRYPT('SOME_THING_STRANGE', 'foobar', '1234567890123456')); +AES_DECRYPT(UNHEX('3A76B0'), 'foobar', '1234567890123456') AES_DECRYPT(UNHEX(''), 'foobar', '1234567890123456') AES_DECRYPT(UNHEX('EFF92304268E'), 'foobar', '1234567890123456') AES_DECRYPT(NULL, 'foobar', '1234567890123456') HEX(AES_DECRYPT('SOME_THING_STRANGE', 'foobar', '1234567890123456')) +123 你好 NULL 580BCEA4DC67CF33FF2C7C570D36ECC89437 +SET block_encryption_mode='aes-256-ofb'; +select AES_DECRYPT(AES_ENCRYPT('foo', 'bar', '1234567890123456'), 'bar', '1234567890123456'); +AES_DECRYPT(AES_ENCRYPT('foo', 'bar', '1234567890123456'), 'bar', '1234567890123456') +foo +select AES_DECRYPT(UNHEX('E842C5'), 'foobar', '1234567890123456'), AES_DECRYPT(UNHEX(''), 'foobar', '1234567890123456'), AES_DECRYPT(UNHEX('3DCD5646767D'), 'foobar', '1234567890123456'), AES_DECRYPT(NULL, 'foobar', '1234567890123456'), HEX(AES_DECRYPT('SOME_THING_STRANGE', 'foobar', '1234567890123456')); +AES_DECRYPT(UNHEX('E842C5'), 'foobar', '1234567890123456') AES_DECRYPT(UNHEX(''), 'foobar', '1234567890123456') AES_DECRYPT(UNHEX('3DCD5646767D'), 'foobar', '1234567890123456') AES_DECRYPT(NULL, 'foobar', '1234567890123456') HEX(AES_DECRYPT('SOME_THING_STRANGE', 'foobar', '1234567890123456')) +123 你好 NULL 8A3FBBE68C9465834584430E3AEEBB04B1F5 +DROP TABLE IF EXISTS t1; +CREATE TABLE t1(a VARCHAR(1000)); +INSERT INTO t1 VALUES('12345'), ('23456'); +SELECT HEX(COMPRESS(a)) FROM t1; +HEX(COMPRESS(a)) +05000000789C323432363105040000FFFF02F80100 +05000000789C323236313503040000FFFF03070105 +DROP TABLE IF EXISTS t2; +CREATE TABLE t2(a VARCHAR(1000), b VARBINARY(1000)); +INSERT INTO t2 (a, b) SELECT a, COMPRESS(a) from t1; +SELECT a, HEX(b) FROM t2; +a HEX(b) +12345 05000000789C323432363105040000FFFF02F80100 +23456 05000000789C323236313503040000FFFF03070105 +SELECT UNCOMPRESS(COMPRESS('123')); +UNCOMPRESS(COMPRESS('123')) +123 +SELECT UNCOMPRESS(UNHEX('03000000789C3334320600012D0097')); +UNCOMPRESS(UNHEX('03000000789C3334320600012D0097')) +123 +SELECT UNCOMPRESS(UNHEX('03000000789C32343206040000FFFF012D0097')); +UNCOMPRESS(UNHEX('03000000789C32343206040000FFFF012D0097')) +123 +INSERT INTO t2 VALUES ('12345', UNHEX('05000000789C3334323631050002F80100')); +SELECT UNCOMPRESS(a), UNCOMPRESS(b) FROM t2; +UNCOMPRESS(a) UNCOMPRESS(b) +NULL 12345 +NULL 23456 +NULL 12345 +SELECT UNCOMPRESSED_LENGTH(COMPRESS('123')); +UNCOMPRESSED_LENGTH(COMPRESS('123')) +3 +SELECT UNCOMPRESSED_LENGTH(UNHEX('03000000789C3334320600012D0097')); +UNCOMPRESSED_LENGTH(UNHEX('03000000789C3334320600012D0097')) +3 +SELECT UNCOMPRESSED_LENGTH(UNHEX('03000000789C32343206040000FFFF012D0097')); +UNCOMPRESSED_LENGTH(UNHEX('03000000789C32343206040000FFFF012D0097')) +3 +SELECT UNCOMPRESSED_LENGTH(''); +UNCOMPRESSED_LENGTH('') +0 +SELECT UNCOMPRESSED_LENGTH(UNHEX('0100')); +UNCOMPRESSED_LENGTH(UNHEX('0100')) +0 +SELECT UNCOMPRESSED_LENGTH(a), UNCOMPRESSED_LENGTH(b) FROM t2; +UNCOMPRESSED_LENGTH(a) UNCOMPRESSED_LENGTH(b) +875770417 5 +892613426 5 +875770417 5 +SELECT RANDOM_BYTES(0); +Error 1690 (22003): length value is out of range in 'random_bytes' +SELECT RANDOM_BYTES(-5); +Error 1690 (22003): length value is out of range in 'random_bytes' +SELECT RANDOM_BYTES(1025); +Error 1690 (22003): length value is out of range in 'random_bytes' +SELECT RANDOM_BYTES(4000); +Error 1690 (22003): length value is out of range in 'random_bytes' +SELECT length(RANDOM_BYTES('1')); +length(RANDOM_BYTES('1')) +1 +SELECT length(RANDOM_BYTES(1024)); +length(RANDOM_BYTES(1024)) +1024 +SELECT RANDOM_BYTES(NULL); +RANDOM_BYTES(NULL) +NULL +SET GLOBAL validate_password.dictionary='password'; +SET GLOBAL validate_password.enable = 1; +SELECT validate_password_strength('root'); +validate_password_strength('root') +0 +SELECT validate_password_strength('toor'); +validate_password_strength('toor') +0 +SELECT validate_password_strength('ROOT'); +validate_password_strength('ROOT') +25 +SELECT validate_password_strength('TOOR'); +validate_password_strength('TOOR') +25 +SELECT validate_password_strength('fooHoHo%1'); +validate_password_strength('fooHoHo%1') +100 +SELECT validate_password_strength('pass'); +validate_password_strength('pass') +25 +SELECT validate_password_strength('password'); +validate_password_strength('password') +50 +SELECT validate_password_strength('password0000'); +validate_password_strength('password0000') +50 +SELECT validate_password_strength('password1A#'); +validate_password_strength('password1A#') +75 +SELECT validate_password_strength('PA12wrd!#'); +validate_password_strength('PA12wrd!#') +100 +SELECT VALIDATE_PASSWORD_STRENGTH(REPEAT("aA1#", 26)); +VALIDATE_PASSWORD_STRENGTH(REPEAT("aA1#", 26)) +100 +SELECT validate_password_strength(null); +validate_password_strength(null) +NULL +SELECT validate_password_strength('null'); +validate_password_strength('null') +25 +SELECT VALIDATE_PASSWORD_STRENGTH( 0x6E616E646F73617135234552 ); +VALIDATE_PASSWORD_STRENGTH( 0x6E616E646F73617135234552 ) +100 +SELECT VALIDATE_PASSWORD_STRENGTH(CAST(0xd2 AS BINARY(10))); +VALIDATE_PASSWORD_STRENGTH(CAST(0xd2 AS BINARY(10))) +50 +SET GLOBAL validate_password.dictionary=default; +SET GLOBAL validate_password.enable = default; +SET block_encryption_mode=default; +select uuid() REGEXP '[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}', +uuid() REGEXP '[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}', +uuid() REGEXP '[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}', +uuid() REGEXP '[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}', +uuid() REGEXP '[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}'; +uuid() REGEXP '[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}' uuid() REGEXP '[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}' uuid() REGEXP '[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}' uuid() REGEXP '[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}' uuid() REGEXP '[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}' +1 1 1 1 1 +select sleep(1); +sleep(1) +0 +select sleep(0); +sleep(0) +0 +select sleep('a'); +sleep('a') +0 +show warnings; +Level Code Message +Warning 1292 Truncated incorrect DOUBLE value: 'a' +select sleep(-1); +Error 1210 (HY000): Incorrect arguments to sleep +SELECT INET_ATON('10.0.5.9'); +INET_ATON('10.0.5.9') +167773449 +SELECT INET_NTOA(167773449); +INET_NTOA(167773449) +10.0.5.9 +SELECT HEX(INET6_ATON('fdfe::5a55:caff:fefa:9089')); +HEX(INET6_ATON('fdfe::5a55:caff:fefa:9089')) +FDFE0000000000005A55CAFFFEFA9089 +SELECT HEX(INET6_ATON('10.0.5.9')); +HEX(INET6_ATON('10.0.5.9')) +0A000509 +SELECT INET6_NTOA(INET6_ATON('fdfe::5a55:caff:fefa:9089')); +INET6_NTOA(INET6_ATON('fdfe::5a55:caff:fefa:9089')) +fdfe::5a55:caff:fefa:9089 +SELECT INET6_NTOA(INET6_ATON('10.0.5.9')); +INET6_NTOA(INET6_ATON('10.0.5.9')) +10.0.5.9 +SELECT INET6_NTOA(UNHEX('FDFE0000000000005A55CAFFFEFA9089')); +INET6_NTOA(UNHEX('FDFE0000000000005A55CAFFFEFA9089')) +fdfe::5a55:caff:fefa:9089 +SELECT INET6_NTOA(UNHEX('0A000509')); +INET6_NTOA(UNHEX('0A000509')) +10.0.5.9 +SELECT IS_IPV4('10.0.5.9'), IS_IPV4('10.0.5.256'); +IS_IPV4('10.0.5.9') IS_IPV4('10.0.5.256') +1 0 +SELECT IS_IPV4_COMPAT(INET6_ATON('::10.0.5.9')); +IS_IPV4_COMPAT(INET6_ATON('::10.0.5.9')) +1 +SELECT IS_IPV4_COMPAT(INET6_ATON('::ffff:10.0.5.9')); +IS_IPV4_COMPAT(INET6_ATON('::ffff:10.0.5.9')) +0 +SELECT +IS_IPV4_COMPAT(INET6_ATON('::192.168.0.1')), +IS_IPV4_COMPAT(INET6_ATON('::c0a8:0001')), +IS_IPV4_COMPAT(INET6_ATON('::c0a8:1')); +IS_IPV4_COMPAT(INET6_ATON('::192.168.0.1')) IS_IPV4_COMPAT(INET6_ATON('::c0a8:0001')) IS_IPV4_COMPAT(INET6_ATON('::c0a8:1')) +1 1 1 +SELECT IS_IPV4_MAPPED(INET6_ATON('::10.0.5.9')); +IS_IPV4_MAPPED(INET6_ATON('::10.0.5.9')) +0 +SELECT IS_IPV4_MAPPED(INET6_ATON('::ffff:10.0.5.9')); +IS_IPV4_MAPPED(INET6_ATON('::ffff:10.0.5.9')) +1 +SELECT +IS_IPV4_MAPPED(INET6_ATON('::ffff:192.168.0.1')), +IS_IPV4_MAPPED(INET6_ATON('::ffff:c0a8:0001')), +IS_IPV4_MAPPED(INET6_ATON('::ffff:c0a8:1')); +IS_IPV4_MAPPED(INET6_ATON('::ffff:192.168.0.1')) IS_IPV4_MAPPED(INET6_ATON('::ffff:c0a8:0001')) IS_IPV4_MAPPED(INET6_ATON('::ffff:c0a8:1')) +1 1 1 +SELECT IS_IPV6('10.0.5.9'), IS_IPV6('::1'); +IS_IPV6('10.0.5.9') IS_IPV6('::1') +0 1 +drop table if exists t1; +create table t1( +a int, +b int not null, +c int not null default 0, +d int default 0, +unique key(b,c), +unique key(b,d) +); +insert into t1 (a,b) values(1,10),(1,20),(2,30),(2,40); +select any_value(a), sum(b) from t1; +any_value(a) sum(b) +1 100 +select a,any_value(b),sum(c) from t1 group by a order by a; +a any_value(b) sum(c) +1 10 0 +2 30 0 +SELECT GET_LOCK('test_lock1', 10); +GET_LOCK('test_lock1', 10) +1 +SELECT GET_LOCK('test_lock2', 10); +GET_LOCK('test_lock2', 10) +1 +SELECT IS_USED_LOCK('test_lock1') = CONNECTION_ID(); +IS_USED_LOCK('test_lock1') = CONNECTION_ID() +1 +SELECT IS_USED_LOCK('foobar'); +IS_USED_LOCK('foobar') +NULL +SELECT IS_FREE_LOCK('test_lock1'); +IS_FREE_LOCK('test_lock1') +0 +SELECT IS_FREE_LOCK('foobar'); +IS_FREE_LOCK('foobar') +1 +SELECT RELEASE_LOCK('test_lock2'); +RELEASE_LOCK('test_lock2') +1 +SELECT RELEASE_LOCK('test_lock1'); +RELEASE_LOCK('test_lock1') +1 +SELECT RELEASE_LOCK('test_lock3'); +RELEASE_LOCK('test_lock3') +0 +SELECT RELEASE_ALL_LOCKS(); +RELEASE_ALL_LOCKS() +0 diff --git a/tests/integrationtest/r/expression/issues.result b/tests/integrationtest/r/expression/issues.result index 97bdfa45c5732..cdcb894fcfa4a 100644 --- a/tests/integrationtest/r/expression/issues.result +++ b/tests/integrationtest/r/expression/issues.result @@ -2811,3 +2811,25 @@ select 1 as c0 from (t0 as ref_88) where (subq_0.c4) >= (subq_0.c4) ); c4 23.0000 +drop table if exists poi_clearing_time_topic; +CREATE TABLE poi_clearing_time_topic (effective_date datetime DEFAULT NULL , clearing_time int(11) DEFAULT NULL); +insert into poi_clearing_time_topic values ('2023:08:25', 1); +SELECT GROUP_CONCAT(effective_date order by stlmnt_hour DESC) FROM ( SELECT (COALESCE(pct.clearing_time, 0)/3600000) AS stlmnt_hour ,COALESCE(pct.effective_date, '1970-01-01 08:00:00') AS effective_date FROM poi_clearing_time_topic pct ORDER BY pct.effective_date DESC ) a; +GROUP_CONCAT(effective_date order by stlmnt_hour DESC) +2023-08-25 00:00:00 +SELECT @@information_schema_stats_expiry; +@@information_schema_stats_expiry +86400 +/*!80000 SET SESSION information_schema_stats_expiry=0 */; +SELECT @@information_schema_stats_expiry; +@@information_schema_stats_expiry +0 +SELECT @@GLOBAL.information_schema_stats_expiry; +@@GLOBAL.information_schema_stats_expiry +86400 +/*!80000 SET GLOBAL information_schema_stats_expiry=0 */; +SELECT @@GLOBAL.information_schema_stats_expiry; +@@GLOBAL.information_schema_stats_expiry +0 +set @@SESSION.information_schema_stats_expiry=default; +set @@GLOBAL.information_schema_stats_expiry=default; diff --git a/tests/integrationtest/r/expression/misc.result b/tests/integrationtest/r/expression/misc.result index 9775284eb4507..32e7659cf53d9 100644 --- a/tests/integrationtest/r/expression/misc.result +++ b/tests/integrationtest/r/expression/misc.result @@ -972,3 +972,38 @@ insert into t2 values (0, 'c', null), (1, null, 0.1), (3, 'b', 0.01), (2, 'q', 0 select * from t2 where t2.i2=((select count(1) from t1 where t1.i1=t2.i2)); i2 c2 f2 1 NULL 0.1 +select tidb_decode_plan(''); +tidb_decode_plan('') + +select tidb_decode_plan('7APIMAk1XzEzCTAJMQlmdW5jczpjb3VudCgxKQoxCTE3XzE0CTAJMAlpbm5lciBqb2luLCBpAQyQOlRhYmxlUmVhZGVyXzIxLCBlcXVhbDpbZXEoQ29sdW1uIzEsIA0KCDkpIBkXADIVFywxMCldCjIJMzFfMTgFZXhkYXRhOlNlbGVjdGlvbl8xNwozCTFfMTcJMQkwCWx0HVlATlVMTCksIG5vdChpc251bGwVHAApUhcAUDIpKQo0CTEwXzE2CTEJMTAwMDAJdAHB2Dp0MSwgcmFuZ2U6Wy1pbmYsK2luZl0sIGtlZXAgb3JkZXI6ZmFsc2UsIHN0YXRzOnBzZXVkbwoFtgAyAZcEMAk6tgAEMjAFtgQyMDq2AAg5LCBmtgAAMFa3AAA5FbcAOT63AAAyzrcA'); +tidb_decode_plan('7APIMAk1XzEzCTAJMQlmdW5jczpjb3VudCgxKQoxCTE3XzE0CTAJMAlpbm5lciBqb2luLCBpAQyQOlRhYmxlUmVhZGVyXzIxLCBlcXVhbDpbZXEoQ29sdW1uIzEsIA0KCDkpIBkXADIVFywxMCldCjIJMzFfMTgFZXhkYXRhOlNlbGVjdGlvbl8xNwozCTFfMTcJMQkwCWx0HVlATlVMTCksIG5vdChpc251bGwVHAApUh + id task estRows operator info + StreamAgg_13 root 1 funcs:count(1) + └─HashJoin_14 root 0 inner join, inner:TableReader_21, equal:[eq(Column#1, Column#9) eq(Column#2, Column#10)] + ├─TableReader_18 root 0 data:Selection_17 + │ └─Selection_17 cop 0 lt(Column#1, NULL), not(isnull(Column#1)), not(isnull(Column#2)) + │ └─TableScan_16 cop 10000 table:t1, range:[-inf,+inf], keep order:false, stats:pseudo + └─TableReader_21 root 0 data:Selection_20 + └─Selection_20 cop 0 lt(Column#9, NULL), not(isnull(Column#10)), not(isnull(Column#9)) + └─TableScan_19 cop 10000 table:t2, range:[-inf,+inf], keep order:false, stats:pseudo +select tidb_decode_plan('rwPwcTAJNV8xNAkwCTEJZnVuY3M6bWF4KHRlc3QudC5hKS0+Q29sdW1uIzQJMQl0aW1lOjIyMy45MzXCtXMsIGxvb3BzOjIJMTI4IEJ5dGVzCU4vQQoxCTE2XzE4CTAJMQlvZmZzZXQ6MCwgY291bnQ6MQkxCQlHFDE4LjQyMjJHAAhOL0EBBCAKMgkzMl8yOAkBlEBpbmRleDpMaW1pdF8yNwkxCQ0+DDYuODUdPSwxLCBycGMgbnVtOiANDAUpGDE1MC44MjQFKjhwcm9jIGtleXM6MAkxOTgdsgAzAbIAMgFearIAFDU3LjM5NgVKAGwN+BGxIDQJMTNfMjYJMQGgHGFibGU6dCwgCbqwaWR4KGEpLCByYW5nZTooMCwraW5mXSwga2VlcCBvcmRlcjp0cnVlLCBkZXNjAT8kaW1lOjU2LjY2MR1rJDEJTi9BCU4vQQo='); +tidb_decode_plan('rwPwcTAJNV8xNAkwCTEJZnVuY3M6bWF4KHRlc3QudC5hKS0+Q29sdW1uIzQJMQl0aW1lOjIyMy45MzXCtXMsIGxvb3BzOjIJMTI4IEJ5dGVzCU4vQQoxCTE2XzE4CTAJMQlvZmZzZXQ6MCwgY291bnQ6MQkxCQlHFDE4LjQyMjJHAAhOL0EBBCAKMgkzMl8yOAkBlEBpbmRleDpMaW1pdF8yNwkxCQ0+DDYuODUdPSwxLC + id task estRows operator info actRows execution info memory disk + StreamAgg_14 root 1 funcs:max(test.t.a)->Column#4 1 time:223.935µs, loops:2 128 Bytes N/A + └─Limit_18 root 1 offset:0, count:1 1 time:218.422µs, loops:2 N/A N/A + └─IndexReader_28 root 1 index:Limit_27 1 time:216.85µs, loops:1, rpc num: 1, rpc time:150.824µs, proc keys:0 198 Bytes N/A + └─Limit_27 cop 1 offset:0, count:1 1 time:57.396µs, loops:2 N/A N/A + └─IndexScan_26 cop 1 table:t, index:idx(a), range:(0,+inf], keep order:true, desc 1 time:56.661µs, loops:1 N/A N/A +select tidb_decode_plan(query), time from information_schema.slow_query order by time desc limit 1; +select tidb_decode_plan('xxx'); +tidb_decode_plan('xxx') +xxx +set @p = now(); +set @@tidb_enable_vectorized_expression = false; +select length(@p); +length(@p) +19 +set @@tidb_enable_vectorized_expression = true; +select length(@p); +length(@p) +19 diff --git a/tests/integrationtest/r/expression/plan_cache.result b/tests/integrationtest/r/expression/plan_cache.result index 3b6d1332c804a..ce7153fb4e81e 100644 --- a/tests/integrationtest/r/expression/plan_cache.result +++ b/tests/integrationtest/r/expression/plan_cache.result @@ -61,3 +61,93 @@ a 1 2 set sql_select_limit=default; +set tidb_enable_prepared_plan_cache=ON; +drop table if exists t; +create table t(a int); +prepare stmt from 'select * from t where a = ?'; +set @a = 1; +execute stmt using @a; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +0 +execute stmt using @a; +a +select @@last_plan_from_cache; +@@last_plan_from_cache +1 +set tidb_enable_prepared_plan_cache=default; +set tidb_enable_prepared_plan_cache=ON; +drop table if exists t; +create table t(a int auto_increment primary key); +prepare stmt from 'select row_count()'; +insert into t values(); +execute stmt; +row_count() +1 +insert into t values(),(),(); +execute stmt; +row_count() +3 +set tidb_enable_prepared_plan_cache=default; +set tidb_enable_prepared_plan_cache=ON; +drop table if exists t1; +create table t1 (a varchar(40)); +insert into t1 values ('C1'),('R1'); +prepare stmt1 from 'select a from t1 where a rlike ?'; +set @a='^C.*'; +execute stmt1 using @a; +a +C1 +set @a='^R.*'; +execute stmt1 using @a; +a +R1 +set tidb_enable_prepared_plan_cache=default; +set tidb_enable_prepared_plan_cache=ON; +drop table if exists t; +create table t(col_int int); +insert into t values(null); +prepare stmt from 'SELECT ((col_int is true) = ?) AS res FROM t'; +set @p0='0.8'; +execute stmt using @p0; +res +0 +set @p0='0'; +execute stmt using @p0; +res +1 +prepare stmt from 'SELECT UCASE(?) < col_int from t;'; +set @a1 = 'xayh7vrWVNqZtzlJmdJQUwAHnkI8Ec'; +execute stmt using @a1; +UCASE(?) < col_int +NULL +delete from t; +insert into t values(1); +prepare stmt from 'SELECT col_int < ? FROM t'; +set @p0='-184467440737095516167.1'; +execute stmt using @p0; +col_int < ? +0 +set tidb_enable_prepared_plan_cache=default; +set tidb_enable_prepared_plan_cache=ON; +drop table if exists t; +create table t(col_double double); +insert into t values (1); +set tidb_enable_vectorized_expression=false; +insert into mysql.expr_pushdown_blacklist values('cast', 'tikv,tiflash,tidb', 'for test'); +admin reload expr_pushdown_blacklist; + +prepare stmt from 'SELECT * FROM (SELECT col_double AS c0 FROM t) t WHERE (ABS((REPEAT(?, ?) OR 5617780767323292672)) < LN(EXP(c0)) + (? ^ ?))'; +set @a1 = 'JuvkBX7ykVux20zQlkwDK2DFelgn7'; +set @a2 = 1; +set @a3 = -112990.35179796701; +set @a4 = 87997.92704840179; +execute stmt using @a1, @a2, @a3, @a4; +c0 +1 +set tidb_enable_vectorized_expression=default; +delete from mysql.expr_pushdown_blacklist where name = 'cast' and store_type = 'tikv,tiflash,tidb' and reason = 'for test'; +admin reload expr_pushdown_blacklist; + +set tidb_enable_prepared_plan_cache=default; diff --git a/tests/integrationtest/r/session/nontransactional.result b/tests/integrationtest/r/session/nontransactional.result new file mode 100644 index 0000000000000..075bff6531fd0 --- /dev/null +++ b/tests/integrationtest/r/session/nontransactional.result @@ -0,0 +1,2220 @@ +drop table if exists t; +create table t(id int, v int); +insert into t values (1, 1); +batch limit 1 insert into t select * from t; +number of jobs job status +1 all succeeded +select * from t; +id v +1 1 +1 1 +drop table t; +create table t(id int, v int, key(id)); +create table t2(id int, v int, key(id)); +insert into t values (1, 1), (2, 2), (3, 3); +insert into t2 values (1, 1), (2, 2), (4, 4); +batch on session__nontransactional.t.id limit 1 update t join t2 on t.id=t2.id set t2.id = t2.id+1; +number of jobs job status +3 all succeeded +select * from t2; +id v +4 1 +4 2 +4 4 +drop table if exists t, t2, t3; +create table t(id int, v1 int, v2 int, unique key (id)); +create table t2(id int, v int, key (id)); +create table t3(id int, v int, key (id)); +create database session__nontransactional2; +use session__nontransactional2; +create table t(id int, v1 int, v2 int, unique key (id)); +create table t2(id int, v int, key (id)); +create table t3(id int, v int, key (id)); +insert into t values (1, 1, 1), (2, 2, 2); +use session__nontransactional; +batch on id limit 1 insert into t select * from session__nontransactional2.t; +number of jobs job status +2 all succeeded +select * from t; +id v1 v2 +1 1 1 +2 2 2 +drop database session__nontransactional2; +drop table if exists t, t2; +create table t(id int, v int, unique key(id)); +create table t2(id int, v int, unique key(id)); +insert into t values (1, 1), (2, 2), (3, 3); +insert into t2 values (1, 1), (2, 2), (4, 4); +batch on id limit 1 update t set id=id+1; +Error 1105 (HY000): Non-transactional DML, shard column cannot be updated +batch on id limit 1 insert into t select * from t on duplicate key update t.id=t.id+10; +Error 1105 (HY000): Non-transactional DML, shard column cannot be updated +batch on id limit 1 update t as t1 set t1.id=t1.id+1; +Error 1105 (HY000): Non-transactional DML, shard column cannot be updated +batch on id limit 1 insert into t select * from t as t1 on duplicate key update t1.id=t1.id+10; +Error 1105 (HY000): Non-transactional DML, shard column cannot be updated +batch on session__nontransactional.t.id limit 1 update t join t2 on t.id=t2.id set t.id=t.id+1; +Error 1105 (HY000): Non-transactional DML, shard column cannot be updated +batch on session__nontransactional.tt.id limit 1 update t as tt join t2 as tt2 on tt.id=tt2.id set tt.id=tt.id+10; +Error 1105 (HY000): Non-transactional DML, shard column cannot be updated +drop table if exists t, t2, t3; +create table t(id int, v1 int, v2 int, unique key (id)); +create table t2(id int, v int, key (id)); +create table t3(id int, v int, key (id)); +insert into t values (1, 1, 1), (2, 2, 2), (3, 3, 3); +insert into t2 values (1, 1), (2, 20), (4, 40); +insert into t3 values (2, 21), (4, 41), (5, 50); +update t as t1 set v1 = session__nontransactional.t1.id + 1; +select * from t; +id v1 v2 +1 2 1 +2 3 2 +3 4 3 +batch on session__nontransactional.tt2.id limit 1 replace into t select tt2.id, tt2.v, t3.v from t2 as tt2 join t3 on tt2.id=t3.id; +number of jobs job status +3 all succeeded +select * from t order by id; +id v1 v2 +1 2 1 +2 20 21 +3 4 3 +4 40 41 +drop table if exists t, t2, t3; +create table t(id int, v1 int, v2 int, unique key (id)); +create table t2(id int, v int, key i1(id)); +create table t3(id int, v int, key i1(id)); +insert into t2 values (1, 2), (2, 3), (3, 4); +insert into t3 values (1, 4), (2, 5), (4, 6); +batch on session__nontransactional.t2.id limit 1 insert into t select t2.id, t2.v, t3.v from t2 join t3 on t2.id=t3.id; +number of jobs job status +3 all succeeded +select * from t; +id v1 v2 +1 2 4 +2 3 5 +batch on id limit 1 insert into t select t2.id, t2.v, t3.v from t2 join t3 on t2.id=t3.id; +Error 1105 (HY000): Non-transactional DML, shard column must be fully specified (i.e. `BATCH ON dbname.tablename.colname`) when multiple tables are involved +batch on session__nontransactional.t1.id limit 1 insert into t select t2.id, t2.v, t3.v from t2 join t3 on t2.id=t3.id; +Error 1105 (HY000): Non-transactional DML, shard column session__nontransactional.t1.id is not in the tables involved in the join +batch on session__nontransactional.t2.id limit 1 update t2 join t3 on t2.id=t3.id set t2.v=t2.v*100, t3.v=t3.v*200; +number of jobs job status +3 all succeeded +select * from t2; +id v +1 200 +2 300 +3 4 +select * from t3; +id v +1 800 +2 1000 +4 6 +batch limit 1 delete t2 from t2 join t3 on t2.id=t3.id; +number of jobs job status +3 all succeeded +select * from t2; +id v +3 4 +insert into t2 values (1, 11), (2, 22); +batch limit 1 replace into t select t2.id, t2.v, t3.v from t2 join t3 on t2.id=t3.id; +number of jobs job status +3 all succeeded +select * from t; +id v1 v2 +1 11 800 +2 22 1000 +drop table if exists t, t1, t2; +create table t(a set('e0', 'e1', 'e2'), b int, primary key(a) clustered, key(b)); +create table t1(a set('e0', 'e1', 'e2'), b int, primary key(a) clustered, key(b)); +insert into t values ('e2,e0', 3); +batch limit 1 insert into t1 select * from t where a = 'e0,e2'; +Error 1105 (HY000): Failed to restore the DML statement, probably because of unsupported type of the shard column +select count(*) from t1; +count(*) +0 +batch limit 1 insert into t1 select * from t where a = 'e0,e2' on duplicate key update t1.b=t.b; +Error 1105 (HY000): Failed to restore the DML statement, probably because of unsupported type of the shard column +select count(*) from t1; +count(*) +0 +batch limit 1 delete from t where a = 'e0,e2'; +Error 1105 (HY000): Failed to restore the DML statement, probably because of unsupported type of the shard column +select count(*) from t; +count(*) +1 +create table t2(a enum('e0', 'e1', 'e2'), b int, key(a)); +insert into t2 values ('e0', 1); +batch on a limit 1 insert into t1 select * from t2; +Error 1105 (HY000): Failed to restore the DML statement, probably because of unsupported type of the shard column +select count(*) from t1; +count(*) +0 +batch on a limit 1 insert into t1 select * from t2 on duplicate key update t1.b=t2.b; +Error 1105 (HY000): Failed to restore the DML statement, probably because of unsupported type of the shard column +select count(*) from t1; +count(*) +0 +batch on a limit 1 delete from t2; +Error 1105 (HY000): Failed to restore the DML statement, probably because of unsupported type of the shard column +select count(*) from t2; +count(*) +1 +drop table if exists session__nontransactional.t, session__nontransactional.s, session__nontransactional.t2; +create table session__nontransactional.t(a int, b int, key(a)); +create table session__nontransactional.s(a int, b int, unique key(a)); +create table session__nontransactional.t2(a int, b int, key(a)); +insert into session__nontransactional.t values (0, 0); +insert into session__nontransactional.t values (1, 2); +insert into session__nontransactional.t values (2, 4); +insert into session__nontransactional.t values (3, 6); +insert into session__nontransactional.t values (4, 8); +batch on session__nontransactional.t1.a limit 5 delete t1.* from session__nontransactional.t as t1; +number of jobs job status +1 all succeeded +select count(*) from session__nontransactional.t; +count(*) +0 +insert into session__nontransactional.t values (0, 0); +insert into session__nontransactional.t values (1, 2); +insert into session__nontransactional.t values (2, 4); +insert into session__nontransactional.t values (3, 6); +insert into session__nontransactional.t values (4, 8); +batch on a limit 5 delete t1.* from session__nontransactional.t as t1; +number of jobs job status +1 all succeeded +select count(*) from session__nontransactional.t; +count(*) +0 +insert into session__nontransactional.t values (0, 0); +insert into session__nontransactional.t values (1, 2); +insert into session__nontransactional.t values (2, 4); +insert into session__nontransactional.t values (3, 6); +insert into session__nontransactional.t values (4, 8); +batch on _tidb_rowid limit 5 delete from session__nontransactional.t as t1; +number of jobs job status +1 all succeeded +select count(*) from session__nontransactional.t; +count(*) +0 +insert into session__nontransactional.t values (0, 0); +insert into session__nontransactional.t values (1, 2); +insert into session__nontransactional.t values (2, 4); +insert into session__nontransactional.t values (3, 6); +insert into session__nontransactional.t values (4, 8); +batch on t1._tidb_rowid limit 5 delete from session__nontransactional.t as t1; +number of jobs job status +1 all succeeded +select count(*) from session__nontransactional.t; +count(*) +0 +insert into session__nontransactional.t values (0, 0); +insert into session__nontransactional.t values (1, 2); +insert into session__nontransactional.t values (2, 4); +insert into session__nontransactional.t values (3, 6); +insert into session__nontransactional.t values (4, 8); +batch on session__nontransactional.t1._tidb_rowid limit 5 delete from session__nontransactional.t as t1; +number of jobs job status +1 all succeeded +select count(*) from session__nontransactional.t; +count(*) +0 +insert into session__nontransactional.t values (0, 0); +insert into session__nontransactional.t values (1, 2); +insert into session__nontransactional.t values (2, 4); +insert into session__nontransactional.t values (3, 6); +insert into session__nontransactional.t values (4, 8); +batch limit 5 delete from session__nontransactional.t as t1; +number of jobs job status +1 all succeeded +select count(*) from session__nontransactional.t; +count(*) +0 +insert into session__nontransactional.t values (0, 0); +insert into session__nontransactional.t values (1, 2); +insert into session__nontransactional.t values (2, 4); +insert into session__nontransactional.t values (3, 6); +insert into session__nontransactional.t values (4, 8); +batch on session__nontransactional.t1.a limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1; +number of jobs job status +1 all succeeded +select * from session__nontransactional.s order by a; +a b +0 0 +1 2 +2 4 +3 6 +4 8 +update session__nontransactional.s set b=a; +batch on session__nontransactional.t1.a limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1 on duplicate key update s.b=t1.b; +number of jobs job status +1 all succeeded +select * from session__nontransactional.s order by a; +a b +0 0 +1 2 +2 4 +3 6 +4 8 +truncate session__nontransactional.s; +batch on a limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1; +number of jobs job status +1 all succeeded +select * from session__nontransactional.s order by a; +a b +0 0 +1 2 +2 4 +3 6 +4 8 +update session__nontransactional.s set b=a; +batch on a limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1 on duplicate key update s.b=t1.b; +number of jobs job status +1 all succeeded +select * from session__nontransactional.s order by a; +a b +0 0 +1 2 +2 4 +3 6 +4 8 +truncate session__nontransactional.s; +batch on _tidb_rowid limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1; +number of jobs job status +1 all succeeded +select * from session__nontransactional.s order by a; +a b +0 0 +1 2 +2 4 +3 6 +4 8 +update session__nontransactional.s set b=a; +batch on _tidb_rowid limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1 on duplicate key update s.b=t1.b; +number of jobs job status +1 all succeeded +select * from session__nontransactional.s order by a; +a b +0 0 +1 2 +2 4 +3 6 +4 8 +truncate session__nontransactional.s; +batch on t1._tidb_rowid limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1; +number of jobs job status +1 all succeeded +select * from session__nontransactional.s order by a; +a b +0 0 +1 2 +2 4 +3 6 +4 8 +update session__nontransactional.s set b=a; +batch on t1._tidb_rowid limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1 on duplicate key update s.b=t1.b; +number of jobs job status +1 all succeeded +select * from session__nontransactional.s order by a; +a b +0 0 +1 2 +2 4 +3 6 +4 8 +truncate session__nontransactional.s; +batch on session__nontransactional.t1._tidb_rowid limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1; +number of jobs job status +1 all succeeded +select * from session__nontransactional.s order by a; +a b +0 0 +1 2 +2 4 +3 6 +4 8 +update session__nontransactional.s set b=a; +batch on session__nontransactional.t1._tidb_rowid limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1 on duplicate key update s.b=t1.b; +number of jobs job status +1 all succeeded +select * from session__nontransactional.s order by a; +a b +0 0 +1 2 +2 4 +3 6 +4 8 +truncate session__nontransactional.s; +batch limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1; +number of jobs job status +1 all succeeded +select * from session__nontransactional.s order by a; +a b +0 0 +1 2 +2 4 +3 6 +4 8 +update session__nontransactional.s set b=a; +batch limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1 on duplicate key update s.b=t1.b; +number of jobs job status +1 all succeeded +select * from session__nontransactional.s order by a; +a b +0 0 +1 2 +2 4 +3 6 +4 8 +truncate session__nontransactional.s; +batch on session__nontransactional.t.a limit 5 delete t1.* from session__nontransactional.t as t1; +Error 1054 (42S22): Unknown column 'session__nontransactional.t.a' in 'where clause' +select count(*) from session__nontransactional.t; +count(*) +5 +batch on t.a limit 5 delete t1.* from session__nontransactional.t as t1; +Error 1054 (42S22): Unknown column 't.a' in 'where clause' +select count(*) from session__nontransactional.t; +count(*) +5 +batch on t._tidb_rowid limit 5 delete from session__nontransactional.t as t1; +Error 1054 (42S22): Unknown column 't._tidb_rowid' in 'where clause' +select count(*) from session__nontransactional.t; +count(*) +5 +batch on session__nontransactional.t._tidb_rowid limit 5 delete from session__nontransactional.t as t1; +Error 1054 (42S22): Unknown column 'session__nontransactional.t._tidb_rowid' in 'where clause' +select count(*) from session__nontransactional.t; +count(*) +5 +batch on session__nontransactional.t.a limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1; +Error 1054 (42S22): Unknown column 'session__nontransactional.t.a' in 'where clause' +select count(*) from session__nontransactional.s; +count(*) +0 +batch on t.a limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1; +Error 1054 (42S22): Unknown column 't.a' in 'where clause' +select count(*) from session__nontransactional.s; +count(*) +0 +batch on t._tidb_rowid limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1; +Error 1054 (42S22): Unknown column 't._tidb_rowid' in 'where clause' +select count(*) from session__nontransactional.s; +count(*) +0 +batch on session__nontransactional.t._tidb_rowid limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1; +Error 1054 (42S22): Unknown column 'session__nontransactional.t._tidb_rowid' in 'where clause' +select count(*) from session__nontransactional.s; +count(*) +0 +drop table if exists t, t1, t2; +create table t(a int, b int, key(a)); +create table t1(a int, b int, key(a)); +create table t2(a int, b int, key(a)); +insert into t values (0, 0); +insert into t values (1, 2); +insert into t values (2, 4); +insert into t values (3, 6); +insert into t values (4, 8); +insert into t values (5, 10); +insert into t values (6, 12); +insert into t values (7, 14); +insert into t values (8, 16); +insert into t values (9, 18); +insert into t values (10, 20); +insert into t values (11, 22); +insert into t values (12, 24); +insert into t values (13, 26); +insert into t values (14, 28); +insert into t values (15, 30); +insert into t values (16, 32); +insert into t values (17, 34); +insert into t values (18, 36); +insert into t values (19, 38); +insert into t values (20, 40); +insert into t values (21, 42); +insert into t values (22, 44); +insert into t values (23, 46); +insert into t values (24, 48); +insert into t values (25, 50); +insert into t values (26, 52); +insert into t values (27, 54); +insert into t values (28, 56); +insert into t values (29, 58); +insert into t values (30, 60); +insert into t values (31, 62); +insert into t values (32, 64); +insert into t values (33, 66); +insert into t values (34, 68); +insert into t values (35, 70); +insert into t values (36, 72); +insert into t values (37, 74); +insert into t values (38, 76); +insert into t values (39, 78); +insert into t values (40, 80); +insert into t values (41, 82); +insert into t values (42, 84); +insert into t values (43, 86); +insert into t values (44, 88); +insert into t values (45, 90); +insert into t values (46, 92); +insert into t values (47, 94); +insert into t values (48, 96); +insert into t values (49, 98); +insert into t values (50, 100); +insert into t values (51, 102); +insert into t values (52, 104); +insert into t values (53, 106); +insert into t values (54, 108); +insert into t values (55, 110); +insert into t values (56, 112); +insert into t values (57, 114); +insert into t values (58, 116); +insert into t values (59, 118); +insert into t values (60, 120); +insert into t values (61, 122); +insert into t values (62, 124); +insert into t values (63, 126); +insert into t values (64, 128); +insert into t values (65, 130); +insert into t values (66, 132); +insert into t values (67, 134); +insert into t values (68, 136); +insert into t values (69, 138); +insert into t values (70, 140); +insert into t values (71, 142); +insert into t values (72, 144); +insert into t values (73, 146); +insert into t values (74, 148); +insert into t values (75, 150); +insert into t values (76, 152); +insert into t values (77, 154); +insert into t values (78, 156); +insert into t values (79, 158); +insert into t values (80, 160); +insert into t values (81, 162); +insert into t values (82, 164); +insert into t values (83, 166); +insert into t values (84, 168); +insert into t values (85, 170); +insert into t values (86, 172); +insert into t values (87, 174); +insert into t values (88, 176); +insert into t values (89, 178); +insert into t values (90, 180); +insert into t values (91, 182); +insert into t values (92, 184); +insert into t values (93, 186); +insert into t values (94, 188); +insert into t values (95, 190); +insert into t values (96, 192); +insert into t values (97, 194); +insert into t values (98, 196); +insert into t values (99, 198); +insert into t1 values (1, 1); +batch limit 1 insert into t2 select t.a, t1.b from t, t1 where t.a = t1.a; +Error 1054 (42S22): Unknown column 't1.a' in 'where clause' +select count(*) from t2; +count(*) +0 +batch limit 1 insert into t2 select t.a, t1.b from t, t1 where t.a = t1.a on duplicate key update t2.b=t.b; +Error 1054 (42S22): Unknown column 't1.a' in 'where clause' +select count(*) from t2; +count(*) +0 +batch limit 1 delete t, t1 from t, t1 where t.a = t1.a; +Error 1054 (42S22): Unknown column 't1.a' in 'where clause' +select count(*) from t; +count(*) +100 +select count(*) from t1; +count(*) +1 +drop table if exists t, t1; +create table t(a int, b int, key(a)); +create table t1(a int, b int, key(a)); +insert into t values ('0', 0); +insert into t values ('1', 2); +insert into t values ('2', 4); +insert into t values ('3', 6); +insert into t values ('4', 8); +insert into t values ('5', 10); +insert into t values ('6', 12); +insert into t values ('7', 14); +insert into t values ('8', 16); +insert into t values ('9', 18); +batch on a limit 10 dry run insert into t1 select /*+ USE_INDEX(t) */ * from t; +split statement examples +INSERT INTO `session__nontransactional`.`t1` SELECT /*+ USE_INDEX(`t` )*/ * FROM `session__nontransactional`.`t` WHERE `a` BETWEEN 0 AND 9 +batch on a limit 10 dry run insert into t1 select /*+ USE_INDEX(t) */ * from t on duplicate key update t1.b=t.b; +split statement examples +INSERT INTO `session__nontransactional`.`t1` SELECT /*+ USE_INDEX(`t` )*/ * FROM `session__nontransactional`.`t` WHERE `a` BETWEEN 0 AND 9 ON DUPLICATE KEY UPDATE `t1`.`b`=`t`.`b` +batch on a limit 10 dry run delete /*+ USE_INDEX(t) */ from t; +split statement examples +DELETE /*+ USE_INDEX(`t` )*/ FROM `session__nontransactional`.`t` WHERE `a` BETWEEN 0 AND 9 +set @@tidb_max_chunk_size=35; +set @@tidb_read_staleness=-100; +drop table if exists t, t1; +create table t(a int, b int, key(a)); +create table t1(a int, b int, unique key(a)); +insert into t values (0, 0); +insert into t values (1, 2); +insert into t values (2, 4); +insert into t values (3, 6); +insert into t values (4, 8); +insert into t values (5, 10); +insert into t values (6, 12); +insert into t values (7, 14); +insert into t values (8, 16); +insert into t values (9, 18); +insert into t values (10, 20); +insert into t values (11, 22); +insert into t values (12, 24); +insert into t values (13, 26); +insert into t values (14, 28); +insert into t values (15, 30); +insert into t values (16, 32); +insert into t values (17, 34); +insert into t values (18, 36); +insert into t values (19, 38); +insert into t values (20, 40); +insert into t values (21, 42); +insert into t values (22, 44); +insert into t values (23, 46); +insert into t values (24, 48); +insert into t values (25, 50); +insert into t values (26, 52); +insert into t values (27, 54); +insert into t values (28, 56); +insert into t values (29, 58); +insert into t values (30, 60); +insert into t values (31, 62); +insert into t values (32, 64); +insert into t values (33, 66); +insert into t values (34, 68); +insert into t values (35, 70); +insert into t values (36, 72); +insert into t values (37, 74); +insert into t values (38, 76); +insert into t values (39, 78); +insert into t values (40, 80); +insert into t values (41, 82); +insert into t values (42, 84); +insert into t values (43, 86); +insert into t values (44, 88); +insert into t values (45, 90); +insert into t values (46, 92); +insert into t values (47, 94); +insert into t values (48, 96); +insert into t values (49, 98); +insert into t values (50, 100); +insert into t values (51, 102); +insert into t values (52, 104); +insert into t values (53, 106); +insert into t values (54, 108); +insert into t values (55, 110); +insert into t values (56, 112); +insert into t values (57, 114); +insert into t values (58, 116); +insert into t values (59, 118); +insert into t values (60, 120); +insert into t values (61, 122); +insert into t values (62, 124); +insert into t values (63, 126); +insert into t values (64, 128); +insert into t values (65, 130); +insert into t values (66, 132); +insert into t values (67, 134); +insert into t values (68, 136); +insert into t values (69, 138); +insert into t values (70, 140); +insert into t values (71, 142); +insert into t values (72, 144); +insert into t values (73, 146); +insert into t values (74, 148); +insert into t values (75, 150); +insert into t values (76, 152); +insert into t values (77, 154); +insert into t values (78, 156); +insert into t values (79, 158); +insert into t values (80, 160); +insert into t values (81, 162); +insert into t values (82, 164); +insert into t values (83, 166); +insert into t values (84, 168); +insert into t values (85, 170); +insert into t values (86, 172); +insert into t values (87, 174); +insert into t values (88, 176); +insert into t values (89, 178); +insert into t values (90, 180); +insert into t values (91, 182); +insert into t values (92, 184); +insert into t values (93, 186); +insert into t values (94, 188); +insert into t values (95, 190); +insert into t values (96, 192); +insert into t values (97, 194); +insert into t values (98, 196); +insert into t values (99, 198); +batch on a limit 10 insert into t1 select * from t; +number of jobs job status +10 all succeeded +select * from t1 order by a; +a b +0 0 +1 2 +2 4 +3 6 +4 8 +5 10 +6 12 +7 14 +8 16 +9 18 +10 20 +11 22 +12 24 +13 26 +14 28 +15 30 +16 32 +17 34 +18 36 +19 38 +20 40 +21 42 +22 44 +23 46 +24 48 +25 50 +26 52 +27 54 +28 56 +29 58 +30 60 +31 62 +32 64 +33 66 +34 68 +35 70 +36 72 +37 74 +38 76 +39 78 +40 80 +41 82 +42 84 +43 86 +44 88 +45 90 +46 92 +47 94 +48 96 +49 98 +50 100 +51 102 +52 104 +53 106 +54 108 +55 110 +56 112 +57 114 +58 116 +59 118 +60 120 +61 122 +62 124 +63 126 +64 128 +65 130 +66 132 +67 134 +68 136 +69 138 +70 140 +71 142 +72 144 +73 146 +74 148 +75 150 +76 152 +77 154 +78 156 +79 158 +80 160 +81 162 +82 164 +83 166 +84 168 +85 170 +86 172 +87 174 +88 176 +89 178 +90 180 +91 182 +92 184 +93 186 +94 188 +95 190 +96 192 +97 194 +98 196 +99 198 +update t1 set b=a; +batch on a limit 10 insert into t1 select * from t on duplicate key update t1.b=t.b; +number of jobs job status +10 all succeeded +batch on a limit 10 delete from t; +number of jobs job status +10 all succeeded +set @@tidb_read_staleness=0; +select * from t; +a b +select * from t1 order by a; +a b +0 0 +1 2 +2 4 +3 6 +4 8 +5 10 +6 12 +7 14 +8 16 +9 18 +10 20 +11 22 +12 24 +13 26 +14 28 +15 30 +16 32 +17 34 +18 36 +19 38 +20 40 +21 42 +22 44 +23 46 +24 48 +25 50 +26 52 +27 54 +28 56 +29 58 +30 60 +31 62 +32 64 +33 66 +34 68 +35 70 +36 72 +37 74 +38 76 +39 78 +40 80 +41 82 +42 84 +43 86 +44 88 +45 90 +46 92 +47 94 +48 96 +49 98 +50 100 +51 102 +52 104 +53 106 +54 108 +55 110 +56 112 +57 114 +58 116 +59 118 +60 120 +61 122 +62 124 +63 126 +64 128 +65 130 +66 132 +67 134 +68 136 +69 138 +70 140 +71 142 +72 144 +73 146 +74 148 +75 150 +76 152 +77 154 +78 156 +79 158 +80 160 +81 162 +82 164 +83 166 +84 168 +85 170 +86 172 +87 174 +88 176 +89 178 +90 180 +91 182 +92 184 +93 186 +94 188 +95 190 +96 192 +97 194 +98 196 +99 198 +set @@tidb_max_chunk_size=default; +set @@tidb_read_staleness=default; +set @@tidb_max_chunk_size=35; +set @@sql_select_limit=3; +drop table if exists t, t1; +create table t(a int, b int, key(a)); +create table t1(a int, b int, unique key(a)); +insert into t values (0, 0); +insert into t values (1, 2); +insert into t values (2, 4); +insert into t values (3, 6); +insert into t values (4, 8); +insert into t values (5, 10); +insert into t values (6, 12); +insert into t values (7, 14); +insert into t values (8, 16); +insert into t values (9, 18); +insert into t values (10, 20); +insert into t values (11, 22); +insert into t values (12, 24); +insert into t values (13, 26); +insert into t values (14, 28); +insert into t values (15, 30); +insert into t values (16, 32); +insert into t values (17, 34); +insert into t values (18, 36); +insert into t values (19, 38); +insert into t values (20, 40); +insert into t values (21, 42); +insert into t values (22, 44); +insert into t values (23, 46); +insert into t values (24, 48); +insert into t values (25, 50); +insert into t values (26, 52); +insert into t values (27, 54); +insert into t values (28, 56); +insert into t values (29, 58); +insert into t values (30, 60); +insert into t values (31, 62); +insert into t values (32, 64); +insert into t values (33, 66); +insert into t values (34, 68); +insert into t values (35, 70); +insert into t values (36, 72); +insert into t values (37, 74); +insert into t values (38, 76); +insert into t values (39, 78); +insert into t values (40, 80); +insert into t values (41, 82); +insert into t values (42, 84); +insert into t values (43, 86); +insert into t values (44, 88); +insert into t values (45, 90); +insert into t values (46, 92); +insert into t values (47, 94); +insert into t values (48, 96); +insert into t values (49, 98); +insert into t values (50, 100); +insert into t values (51, 102); +insert into t values (52, 104); +insert into t values (53, 106); +insert into t values (54, 108); +insert into t values (55, 110); +insert into t values (56, 112); +insert into t values (57, 114); +insert into t values (58, 116); +insert into t values (59, 118); +insert into t values (60, 120); +insert into t values (61, 122); +insert into t values (62, 124); +insert into t values (63, 126); +insert into t values (64, 128); +insert into t values (65, 130); +insert into t values (66, 132); +insert into t values (67, 134); +insert into t values (68, 136); +insert into t values (69, 138); +insert into t values (70, 140); +insert into t values (71, 142); +insert into t values (72, 144); +insert into t values (73, 146); +insert into t values (74, 148); +insert into t values (75, 150); +insert into t values (76, 152); +insert into t values (77, 154); +insert into t values (78, 156); +insert into t values (79, 158); +insert into t values (80, 160); +insert into t values (81, 162); +insert into t values (82, 164); +insert into t values (83, 166); +insert into t values (84, 168); +insert into t values (85, 170); +insert into t values (86, 172); +insert into t values (87, 174); +insert into t values (88, 176); +insert into t values (89, 178); +insert into t values (90, 180); +insert into t values (91, 182); +insert into t values (92, 184); +insert into t values (93, 186); +insert into t values (94, 188); +insert into t values (95, 190); +insert into t values (96, 192); +insert into t values (97, 194); +insert into t values (98, 196); +insert into t values (99, 198); +batch on a limit 10 insert into t1 select * from t; +number of jobs job status +10 all succeeded +select count(*) from t; +count(*) +100 +select count(*) from t1; +count(*) +100 +(select * from t1 order by a) except (select * from t order by a); +a b +(select * from t order by a) except (select * from t1 order by a); +a b +update t1 set b=a; +batch on a limit 10 insert into t1 select * from t on duplicate key update t1.b=t.b; +number of jobs job status +10 all succeeded +select count(*) from t; +count(*) +100 +select count(*) from t1; +count(*) +100 +(select * from t1 order by a) except (select * from t order by a); +a b +(select * from t order by a) except (select * from t1 order by a); +a b +batch on a limit 10 delete from t; +number of jobs job status +10 all succeeded +select * from t; +a b +set @@tidb_max_chunk_size=default; +set @@sql_select_limit=default; +set @@tidb_max_chunk_size=35; +drop table if exists t, t1; +create table t(a int, b int); +create table t1(a int, b int); +insert into t values (0, 0); +insert into t values (1, 2); +insert into t values (2, 4); +insert into t values (3, 6); +insert into t values (4, 8); +insert into t values (5, 10); +insert into t values (6, 12); +insert into t values (7, 14); +insert into t values (8, 16); +insert into t values (9, 18); +insert into t values (10, 20); +insert into t values (11, 22); +insert into t values (12, 24); +insert into t values (13, 26); +insert into t values (14, 28); +insert into t values (15, 30); +insert into t values (16, 32); +insert into t values (17, 34); +insert into t values (18, 36); +insert into t values (19, 38); +insert into t values (20, 40); +insert into t values (21, 42); +insert into t values (22, 44); +insert into t values (23, 46); +insert into t values (24, 48); +insert into t values (25, 50); +insert into t values (26, 52); +insert into t values (27, 54); +insert into t values (28, 56); +insert into t values (29, 58); +insert into t values (30, 60); +insert into t values (31, 62); +insert into t values (32, 64); +insert into t values (33, 66); +insert into t values (34, 68); +insert into t values (35, 70); +insert into t values (36, 72); +insert into t values (37, 74); +insert into t values (38, 76); +insert into t values (39, 78); +insert into t values (40, 80); +insert into t values (41, 82); +insert into t values (42, 84); +insert into t values (43, 86); +insert into t values (44, 88); +insert into t values (45, 90); +insert into t values (46, 92); +insert into t values (47, 94); +insert into t values (48, 96); +insert into t values (49, 98); +insert into t values (50, 100); +insert into t values (51, 102); +insert into t values (52, 104); +insert into t values (53, 106); +insert into t values (54, 108); +insert into t values (55, 110); +insert into t values (56, 112); +insert into t values (57, 114); +insert into t values (58, 116); +insert into t values (59, 118); +insert into t values (60, 120); +insert into t values (61, 122); +insert into t values (62, 124); +insert into t values (63, 126); +insert into t values (64, 128); +insert into t values (65, 130); +insert into t values (66, 132); +insert into t values (67, 134); +insert into t values (68, 136); +insert into t values (69, 138); +insert into t values (70, 140); +insert into t values (71, 142); +insert into t values (72, 144); +insert into t values (73, 146); +insert into t values (74, 148); +insert into t values (75, 150); +insert into t values (76, 152); +insert into t values (77, 154); +insert into t values (78, 156); +insert into t values (79, 158); +insert into t values (80, 160); +insert into t values (81, 162); +insert into t values (82, 164); +insert into t values (83, 166); +insert into t values (84, 168); +insert into t values (85, 170); +insert into t values (86, 172); +insert into t values (87, 174); +insert into t values (88, 176); +insert into t values (89, 178); +insert into t values (90, 180); +insert into t values (91, 182); +insert into t values (92, 184); +insert into t values (93, 186); +insert into t values (94, 188); +insert into t values (95, 190); +insert into t values (96, 192); +insert into t values (97, 194); +insert into t values (98, 196); +insert into t values (99, 198); +batch on a limit 10 insert into t1 select * from t; +Error 1105 (HY000): Non-transactional DML, shard column a is not indexed +batch on a limit 10 insert into t1 select * from t on duplicate key update t1.b=t.b; +Error 1105 (HY000): Non-transactional DML, shard column a is not indexed +batch on a limit 10 delete from t; +Error 1105 (HY000): Non-transactional DML, shard column a is not indexed +CREATE UNIQUE INDEX c1 ON t (a) INVISIBLE; +CREATE UNIQUE INDEX c1 ON t1 (a) INVISIBLE; +batch on a limit 10 insert into t1 select * from t; +Error 1105 (HY000): Non-transactional DML, shard column a is not indexed +batch on a limit 10 insert into t1 select * from t on duplicate key update t1.b=t.b; +Error 1105 (HY000): Non-transactional DML, shard column a is not indexed +batch on a limit 10 delete from t; +Error 1105 (HY000): Non-transactional DML, shard column a is not indexed +CREATE UNIQUE INDEX c2 ON t (a); +CREATE UNIQUE INDEX c2 ON t1 (a); +batch on a limit 10 insert into t1 select * from t; +number of jobs job status +10 all succeeded +select count(t1.a) = count(t.a) from t, t1; +count(t1.a) = count(t.a) +1 +(select * from t1 order by a) except (select * from t order by a); +a b +(select * from t order by a) except (select * from t1 order by a); +a b +update t1 set b=a; +batch on a limit 10 insert into t1 select * from t on duplicate key update t1.b=t.b; +number of jobs job status +10 all succeeded +select count(*) from t; +count(*) +100 +select count(*) from t1; +count(*) +100 +(select * from t1 order by a) except (select * from t order by a); +a b +(select * from t order by a) except (select * from t1 order by a); +a b +batch on a limit 10 delete from t; +number of jobs job status +10 all succeeded +select count(*) from t; +count(*) +0 +set @@tidb_max_chunk_size=default; +set @@tidb_max_chunk_size=35; +drop table if exists t, t1; +create table t(a int, b int); +create table t1(a int, b int); +insert into t values ('0', 0); +insert into t values ('1', 2); +insert into t values ('2', 4); +insert into t values ('3', 6); +insert into t values ('4', 8); +insert into t values ('5', 10); +insert into t values ('6', 12); +insert into t values ('7', 14); +insert into t values ('8', 16); +insert into t values ('9', 18); +batch limit 3 insert into t1 select * from t; +number of jobs job status +4 all succeeded +batch limit 3 insert into t1 select * from t on duplicate key update t1.a=t.a, t1.b=t.b; +number of jobs job status +4 all succeeded +batch limit 3 delete from t; +number of jobs job status +4 all succeeded +drop table if exists t, t1; +create table t(a int, b int, primary key(a) clustered); +create table t1(a int, b int, primary key(a) clustered); +insert into t values ('0', 0); +insert into t values ('1', 2); +insert into t values ('2', 4); +insert into t values ('3', 6); +insert into t values ('4', 8); +insert into t values ('5', 10); +insert into t values ('6', 12); +insert into t values ('7', 14); +insert into t values ('8', 16); +insert into t values ('9', 18); +batch limit 3 insert into t1 select * from t; +number of jobs job status +4 all succeeded +batch limit 3 insert into t1 select * from t on duplicate key update t1.a=t.a, t1.b=t.b; +number of jobs job status +4 all succeeded +batch limit 3 delete from t; +number of jobs job status +4 all succeeded +drop table if exists t, t1; +create table t(a int, b int, primary key(a) nonclustered); +create table t1(a int, b int, primary key(a) nonclustered); +insert into t values ('0', 0); +insert into t values ('1', 2); +insert into t values ('2', 4); +insert into t values ('3', 6); +insert into t values ('4', 8); +insert into t values ('5', 10); +insert into t values ('6', 12); +insert into t values ('7', 14); +insert into t values ('8', 16); +insert into t values ('9', 18); +batch limit 3 insert into t1 select * from t; +number of jobs job status +4 all succeeded +batch limit 3 insert into t1 select * from t on duplicate key update t1.a=t.a, t1.b=t.b; +number of jobs job status +4 all succeeded +batch limit 3 delete from t; +number of jobs job status +4 all succeeded +drop table if exists t, t1; +create table t(a int, b int, primary key(a, b) nonclustered); +create table t1(a int, b int, primary key(a, b) nonclustered); +insert into t values ('0', 0); +insert into t values ('1', 2); +insert into t values ('2', 4); +insert into t values ('3', 6); +insert into t values ('4', 8); +insert into t values ('5', 10); +insert into t values ('6', 12); +insert into t values ('7', 14); +insert into t values ('8', 16); +insert into t values ('9', 18); +batch limit 3 insert into t1 select * from t; +number of jobs job status +4 all succeeded +batch limit 3 insert into t1 select * from t on duplicate key update t1.a=t.a, t1.b=t.b; +number of jobs job status +4 all succeeded +batch limit 3 delete from t; +number of jobs job status +4 all succeeded +drop table if exists t, t1; +create table t(a varchar(30), b int, primary key(a) clustered); +create table t1(a varchar(30), b int, primary key(a) clustered); +insert into t values ('0', 0); +insert into t values ('1', 2); +insert into t values ('2', 4); +insert into t values ('3', 6); +insert into t values ('4', 8); +insert into t values ('5', 10); +insert into t values ('6', 12); +insert into t values ('7', 14); +insert into t values ('8', 16); +insert into t values ('9', 18); +batch limit 3 insert into t1 select * from t; +number of jobs job status +4 all succeeded +batch limit 3 insert into t1 select * from t on duplicate key update t1.a=t.a, t1.b=t.b; +number of jobs job status +4 all succeeded +batch limit 3 delete from t; +number of jobs job status +4 all succeeded +drop table if exists t, t1; +create table t(a varchar(30), b int, primary key(a, b) nonclustered); +create table t1(a varchar(30), b int, primary key(a, b) nonclustered); +insert into t values ('0', 0); +insert into t values ('1', 2); +insert into t values ('2', 4); +insert into t values ('3', 6); +insert into t values ('4', 8); +insert into t values ('5', 10); +insert into t values ('6', 12); +insert into t values ('7', 14); +insert into t values ('8', 16); +insert into t values ('9', 18); +batch limit 3 insert into t1 select * from t; +number of jobs job status +4 all succeeded +batch limit 3 insert into t1 select * from t on duplicate key update t1.a=t.a, t1.b=t.b; +number of jobs job status +4 all succeeded +batch limit 3 delete from t; +number of jobs job status +4 all succeeded +drop table if exists t, t1; +create table t(a int, b int, primary key(a, b) clustered); +create table t1(a int, b int, primary key(a, b) clustered); +insert into t values ('0', 0); +insert into t values ('1', 2); +insert into t values ('2', 4); +insert into t values ('3', 6); +insert into t values ('4', 8); +insert into t values ('5', 10); +insert into t values ('6', 12); +insert into t values ('7', 14); +insert into t values ('8', 16); +insert into t values ('9', 18); +batch limit 3 insert into t1 select * from t; +Error 1105 (HY000): Non-transactional DML, the clustered index contains multiple columns. Please specify a shard column +batch limit 3 insert into t1 select * from t on duplicate key update t1.a=t.a, t1.b=t.b; +Error 1105 (HY000): Non-transactional DML, the clustered index contains multiple columns. Please specify a shard column +batch limit 3 delete from t; +Error 1105 (HY000): Non-transactional DML, the clustered index contains multiple columns. Please specify a shard column +drop table if exists t, t1; +create table t(a varchar(30), b int, primary key(a, b) clustered); +create table t1(a varchar(30), b int, primary key(a, b) clustered); +insert into t values ('0', 0); +insert into t values ('1', 2); +insert into t values ('2', 4); +insert into t values ('3', 6); +insert into t values ('4', 8); +insert into t values ('5', 10); +insert into t values ('6', 12); +insert into t values ('7', 14); +insert into t values ('8', 16); +insert into t values ('9', 18); +batch limit 3 insert into t1 select * from t; +Error 1105 (HY000): Non-transactional DML, the clustered index contains multiple columns. Please specify a shard column +batch limit 3 insert into t1 select * from t on duplicate key update t1.a=t.a, t1.b=t.b; +Error 1105 (HY000): Non-transactional DML, the clustered index contains multiple columns. Please specify a shard column +batch limit 3 delete from t; +Error 1105 (HY000): Non-transactional DML, the clustered index contains multiple columns. Please specify a shard column +set @@tidb_max_chunk_size=35; +drop table if exists t, t1; +create table t(a int, b int, c double as (sqrt(a * a + b * b)), key(c)); +create table t1(a int, b int, c double as (sqrt(a * a + b * b)), unique key(c)); +insert into t values (0, 0, default); +insert into t values (1, 2, default); +insert into t values (2, 4, default); +insert into t values (3, 6, default); +insert into t values (4, 8, default); +insert into t values (5, 10, default); +insert into t values (6, 12, default); +insert into t values (7, 14, default); +insert into t values (8, 16, default); +insert into t values (9, 18, default); +insert into t values (10, 20, default); +insert into t values (11, 22, default); +insert into t values (12, 24, default); +insert into t values (13, 26, default); +insert into t values (14, 28, default); +insert into t values (15, 30, default); +insert into t values (16, 32, default); +insert into t values (17, 34, default); +insert into t values (18, 36, default); +insert into t values (19, 38, default); +insert into t values (20, 40, default); +insert into t values (21, 42, default); +insert into t values (22, 44, default); +insert into t values (23, 46, default); +insert into t values (24, 48, default); +insert into t values (25, 50, default); +insert into t values (26, 52, default); +insert into t values (27, 54, default); +insert into t values (28, 56, default); +insert into t values (29, 58, default); +insert into t values (30, 60, default); +insert into t values (31, 62, default); +insert into t values (32, 64, default); +insert into t values (33, 66, default); +insert into t values (34, 68, default); +insert into t values (35, 70, default); +insert into t values (36, 72, default); +insert into t values (37, 74, default); +insert into t values (38, 76, default); +insert into t values (39, 78, default); +insert into t values (40, 80, default); +insert into t values (41, 82, default); +insert into t values (42, 84, default); +insert into t values (43, 86, default); +insert into t values (44, 88, default); +insert into t values (45, 90, default); +insert into t values (46, 92, default); +insert into t values (47, 94, default); +insert into t values (48, 96, default); +insert into t values (49, 98, default); +insert into t values (50, 100, default); +insert into t values (51, 102, default); +insert into t values (52, 104, default); +insert into t values (53, 106, default); +insert into t values (54, 108, default); +insert into t values (55, 110, default); +insert into t values (56, 112, default); +insert into t values (57, 114, default); +insert into t values (58, 116, default); +insert into t values (59, 118, default); +insert into t values (60, 120, default); +insert into t values (61, 122, default); +insert into t values (62, 124, default); +insert into t values (63, 126, default); +insert into t values (64, 128, default); +insert into t values (65, 130, default); +insert into t values (66, 132, default); +insert into t values (67, 134, default); +insert into t values (68, 136, default); +insert into t values (69, 138, default); +insert into t values (70, 140, default); +insert into t values (71, 142, default); +insert into t values (72, 144, default); +insert into t values (73, 146, default); +insert into t values (74, 148, default); +insert into t values (75, 150, default); +insert into t values (76, 152, default); +insert into t values (77, 154, default); +insert into t values (78, 156, default); +insert into t values (79, 158, default); +insert into t values (80, 160, default); +insert into t values (81, 162, default); +insert into t values (82, 164, default); +insert into t values (83, 166, default); +insert into t values (84, 168, default); +insert into t values (85, 170, default); +insert into t values (86, 172, default); +insert into t values (87, 174, default); +insert into t values (88, 176, default); +insert into t values (89, 178, default); +insert into t values (90, 180, default); +insert into t values (91, 182, default); +insert into t values (92, 184, default); +insert into t values (93, 186, default); +insert into t values (94, 188, default); +insert into t values (95, 190, default); +insert into t values (96, 192, default); +insert into t values (97, 194, default); +insert into t values (98, 196, default); +insert into t values (99, 198, default); +batch on c limit 10 insert into t1(a, b) select a, b from t; +number of jobs job status +10 all succeeded +select count(*) from t; +count(*) +100 +select count(*) from t1; +count(*) +100 +(select * from t1 order by a) except (select * from t order by a); +a b c +(select * from t order by a) except (select * from t1 order by a); +a b c +update t1 set a=b, b=a; +select count(*) from t; +count(*) +100 +select count(*) from t1; +count(*) +100 +(select b, a from t1 order by a) except (select a, b from t order by a); +b a +(select b, a from t order by a) except (select a, b from t1 order by a); +b a +batch on c limit 10 insert into t1(a, b) select a, b from t on duplicate key update t1.a=t.a, t1.b=t.b; +number of jobs job status +10 all succeeded +select count(*) from t; +count(*) +100 +select count(*) from t1; +count(*) +100 +(select * from t1 order by a) except (select * from t order by a); +a b c +(select * from t order by a) except (select * from t1 order by a); +a b c +batch on c limit 10 delete from t; +number of jobs job status +10 all succeeded +select count(*) from t; +count(*) +0 +set @@tidb_max_chunk_size=default; +set @@tidb_max_chunk_size=1024; +drop table if exists t, t1; +create table t(a int, b int, key(a)); +create table t1(a int, b int, unique key(a)); +insert into t values ('0', 0); +insert into t values (null, null); +insert into t values ('1', 2); +insert into t values (null, null); +insert into t values ('2', 4); +insert into t values (null, null); +insert into t values ('3', 6); +insert into t values (null, null); +insert into t values ('4', 8); +insert into t values (null, null); +insert into t values ('5', 10); +insert into t values (null, null); +insert into t values ('6', 12); +insert into t values (null, null); +insert into t values ('7', 14); +insert into t values (null, null); +insert into t values ('8', 16); +insert into t values (null, null); +insert into t values ('9', 18); +insert into t values (null, null); +batch on a limit 1000 dry run delete from t; +split statement examples +DELETE FROM `session__nontransactional`.`t` WHERE ((`a` <= 9) OR `a` IS NULL) +batch on a limit 1000 dry run insert into t1 select * from t; +split statement examples +INSERT INTO `session__nontransactional`.`t1` SELECT * FROM `session__nontransactional`.`t` WHERE ((`a` <= 9) OR `a` IS NULL) +batch on a limit 1000 dry run insert into t1 select * from t on duplicate key update t1.b=t.b; +split statement examples +INSERT INTO `session__nontransactional`.`t1` SELECT * FROM `session__nontransactional`.`t` WHERE ((`a` <= 9) OR `a` IS NULL) ON DUPLICATE KEY UPDATE `t1`.`b`=`t`.`b` +batch on a limit 1000 insert into t1 select * from t; +number of jobs job status +1 all succeeded +select count(*) from t; +count(*) +20 +select count(*) from t1; +count(*) +20 +(select * from t1 order by a) except (select * from t order by a); +a b +(select * from t order by a) except (select * from t1 order by a); +a b +update t1 set b = a; +batch on a limit 1000 insert into t1 select * from t on duplicate key update t1.b=t.b; +number of jobs job status +1 all succeeded +select count(*) from t where a is not null; +count(*) +10 +select count(*) from t1 where a is not null; +count(*) +10 +(select * from t1 where a is not null order by a) except (select * from t where a is not null order by a); +a b +(select * from t where a is not null order by a) except (select * from t1 where a is not null order by a); +a b +batch on a limit 1000 delete from t; +number of jobs job status +1 all succeeded +select count(*) from t; +count(*) +0 +set @@tidb_max_chunk_size=default; +set @@tidb_max_chunk_size=35; +drop table if exists t, t1; +create table t(a int, b int, key(a)); +create table t1(a int, b int, key(a)); +insert into t values ('0', 0); +insert into t values (null, null); +insert into t values ('1', 2); +insert into t values (null, null); +insert into t values ('2', 4); +insert into t values (null, null); +insert into t values ('3', 6); +insert into t values (null, null); +insert into t values ('4', 8); +insert into t values (null, null); +insert into t values ('5', 10); +insert into t values (null, null); +insert into t values ('6', 12); +insert into t values (null, null); +insert into t values ('7', 14); +insert into t values (null, null); +insert into t values ('8', 16); +insert into t values (null, null); +insert into t values ('9', 18); +insert into t values (null, null); +insert into t values ('10', 20); +insert into t values (null, null); +insert into t values ('11', 22); +insert into t values (null, null); +insert into t values ('12', 24); +insert into t values (null, null); +insert into t values ('13', 26); +insert into t values (null, null); +insert into t values ('14', 28); +insert into t values (null, null); +insert into t values ('15', 30); +insert into t values (null, null); +insert into t values ('16', 32); +insert into t values (null, null); +insert into t values ('17', 34); +insert into t values (null, null); +insert into t values ('18', 36); +insert into t values (null, null); +insert into t values ('19', 38); +insert into t values (null, null); +insert into t values ('20', 40); +insert into t values (null, null); +insert into t values ('21', 42); +insert into t values (null, null); +insert into t values ('22', 44); +insert into t values (null, null); +insert into t values ('23', 46); +insert into t values (null, null); +insert into t values ('24', 48); +insert into t values (null, null); +insert into t values ('25', 50); +insert into t values (null, null); +insert into t values ('26', 52); +insert into t values (null, null); +insert into t values ('27', 54); +insert into t values (null, null); +insert into t values ('28', 56); +insert into t values (null, null); +insert into t values ('29', 58); +insert into t values (null, null); +insert into t values ('30', 60); +insert into t values (null, null); +insert into t values ('31', 62); +insert into t values (null, null); +insert into t values ('32', 64); +insert into t values (null, null); +insert into t values ('33', 66); +insert into t values (null, null); +insert into t values ('34', 68); +insert into t values (null, null); +insert into t values ('35', 70); +insert into t values (null, null); +insert into t values ('36', 72); +insert into t values (null, null); +insert into t values ('37', 74); +insert into t values (null, null); +insert into t values ('38', 76); +insert into t values (null, null); +insert into t values ('39', 78); +insert into t values (null, null); +insert into t values ('40', 80); +insert into t values (null, null); +insert into t values ('41', 82); +insert into t values (null, null); +insert into t values ('42', 84); +insert into t values (null, null); +insert into t values ('43', 86); +insert into t values (null, null); +insert into t values ('44', 88); +insert into t values (null, null); +insert into t values ('45', 90); +insert into t values (null, null); +insert into t values ('46', 92); +insert into t values (null, null); +insert into t values ('47', 94); +insert into t values (null, null); +insert into t values ('48', 96); +insert into t values (null, null); +insert into t values ('49', 98); +insert into t values (null, null); +insert into t values ('50', 100); +insert into t values (null, null); +insert into t values ('51', 102); +insert into t values (null, null); +insert into t values ('52', 104); +insert into t values (null, null); +insert into t values ('53', 106); +insert into t values (null, null); +insert into t values ('54', 108); +insert into t values (null, null); +insert into t values ('55', 110); +insert into t values (null, null); +insert into t values ('56', 112); +insert into t values (null, null); +insert into t values ('57', 114); +insert into t values (null, null); +insert into t values ('58', 116); +insert into t values (null, null); +insert into t values ('59', 118); +insert into t values (null, null); +insert into t values ('60', 120); +insert into t values (null, null); +insert into t values ('61', 122); +insert into t values (null, null); +insert into t values ('62', 124); +insert into t values (null, null); +insert into t values ('63', 126); +insert into t values (null, null); +insert into t values ('64', 128); +insert into t values (null, null); +insert into t values ('65', 130); +insert into t values (null, null); +insert into t values ('66', 132); +insert into t values (null, null); +insert into t values ('67', 134); +insert into t values (null, null); +insert into t values ('68', 136); +insert into t values (null, null); +insert into t values ('69', 138); +insert into t values (null, null); +insert into t values ('70', 140); +insert into t values (null, null); +insert into t values ('71', 142); +insert into t values (null, null); +insert into t values ('72', 144); +insert into t values (null, null); +insert into t values ('73', 146); +insert into t values (null, null); +insert into t values ('74', 148); +insert into t values (null, null); +insert into t values ('75', 150); +insert into t values (null, null); +insert into t values ('76', 152); +insert into t values (null, null); +insert into t values ('77', 154); +insert into t values (null, null); +insert into t values ('78', 156); +insert into t values (null, null); +insert into t values ('79', 158); +insert into t values (null, null); +insert into t values ('80', 160); +insert into t values (null, null); +insert into t values ('81', 162); +insert into t values (null, null); +insert into t values ('82', 164); +insert into t values (null, null); +insert into t values ('83', 166); +insert into t values (null, null); +insert into t values ('84', 168); +insert into t values (null, null); +insert into t values ('85', 170); +insert into t values (null, null); +insert into t values ('86', 172); +insert into t values (null, null); +insert into t values ('87', 174); +insert into t values (null, null); +insert into t values ('88', 176); +insert into t values (null, null); +insert into t values ('89', 178); +insert into t values (null, null); +insert into t values ('90', 180); +insert into t values (null, null); +insert into t values ('91', 182); +insert into t values (null, null); +insert into t values ('92', 184); +insert into t values (null, null); +insert into t values ('93', 186); +insert into t values (null, null); +insert into t values ('94', 188); +insert into t values (null, null); +insert into t values ('95', 190); +insert into t values (null, null); +insert into t values ('96', 192); +insert into t values (null, null); +insert into t values ('97', 194); +insert into t values (null, null); +insert into t values ('98', 196); +insert into t values (null, null); +insert into t values ('99', 198); +insert into t values (null, null); +batch on a limit 3 delete from t; +number of jobs job status +35 all succeeded +select count(*) from t; +count(*) +0 +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +batch on a limit 3 insert into t1 select * from t; +number of jobs job status +1 all succeeded +select count(*) from t; +count(*) +100 +select count(*) from t1; +count(*) +100 +(select * from t1 order by a) except (select * from t order by a); +a b +(select * from t order by a) except (select * from t1 order by a); +a b +batch on a limit 3 insert into t1 select * from t on duplicate key update t1.b=t.b; +number of jobs job status +1 all succeeded +select count(*) from t1; +count(*) +200 +batch on a limit 3 delete from t; +number of jobs job status +1 all succeeded +select count(*) from t; +count(*) +0 +set @@tidb_max_chunk_size=default; +set @@tidb_max_chunk_size=35; +drop table if exists t, t1; +create table t(a int, b int); +create table t1(a int, b int, unique key(a)); +insert into t values ('0', 0); +insert into t values ('1', 2); +insert into t values ('2', 4); +insert into t values ('3', 6); +insert into t values ('4', 8); +insert into t values ('5', 10); +insert into t values ('6', 12); +insert into t values ('7', 14); +insert into t values ('8', 16); +insert into t values ('9', 18); +insert into t values ('10', 20); +insert into t values ('11', 22); +insert into t values ('12', 24); +insert into t values ('13', 26); +insert into t values ('14', 28); +insert into t values ('15', 30); +insert into t values ('16', 32); +insert into t values ('17', 34); +insert into t values ('18', 36); +insert into t values ('19', 38); +insert into t values ('20', 40); +insert into t values ('21', 42); +insert into t values ('22', 44); +insert into t values ('23', 46); +insert into t values ('24', 48); +insert into t values ('25', 50); +insert into t values ('26', 52); +insert into t values ('27', 54); +insert into t values ('28', 56); +insert into t values ('29', 58); +insert into t values ('30', 60); +insert into t values ('31', 62); +insert into t values ('32', 64); +insert into t values ('33', 66); +insert into t values ('34', 68); +insert into t values ('35', 70); +insert into t values ('36', 72); +insert into t values ('37', 74); +insert into t values ('38', 76); +insert into t values ('39', 78); +insert into t values ('40', 80); +insert into t values ('41', 82); +insert into t values ('42', 84); +insert into t values ('43', 86); +insert into t values ('44', 88); +insert into t values ('45', 90); +insert into t values ('46', 92); +insert into t values ('47', 94); +insert into t values ('48', 96); +insert into t values ('49', 98); +insert into t values ('50', 100); +insert into t values ('51', 102); +insert into t values ('52', 104); +insert into t values ('53', 106); +insert into t values ('54', 108); +insert into t values ('55', 110); +insert into t values ('56', 112); +insert into t values ('57', 114); +insert into t values ('58', 116); +insert into t values ('59', 118); +insert into t values ('60', 120); +insert into t values ('61', 122); +insert into t values ('62', 124); +insert into t values ('63', 126); +insert into t values ('64', 128); +insert into t values ('65', 130); +insert into t values ('66', 132); +insert into t values ('67', 134); +insert into t values ('68', 136); +insert into t values ('69', 138); +insert into t values ('70', 140); +insert into t values ('71', 142); +insert into t values ('72', 144); +insert into t values ('73', 146); +insert into t values ('74', 148); +insert into t values ('75', 150); +insert into t values ('76', 152); +insert into t values ('77', 154); +insert into t values ('78', 156); +insert into t values ('79', 158); +insert into t values ('80', 160); +insert into t values ('81', 162); +insert into t values ('82', 164); +insert into t values ('83', 166); +insert into t values ('84', 168); +insert into t values ('85', 170); +insert into t values ('86', 172); +insert into t values ('87', 174); +insert into t values ('88', 176); +insert into t values ('89', 178); +insert into t values ('90', 180); +insert into t values ('91', 182); +insert into t values ('92', 184); +insert into t values ('93', 186); +insert into t values ('94', 188); +insert into t values ('95', 190); +insert into t values ('96', 192); +insert into t values ('97', 194); +insert into t values ('98', 196); +insert into t values ('99', 198); +batch limit 3 dry run delete from t; +split statement examples +DELETE FROM `session__nontransactional`.`t` WHERE `session__nontransactional`.`t`.`_tidb_rowid` BETWEEN 1 AND 3 +DELETE FROM `session__nontransactional`.`t` WHERE `session__nontransactional`.`t`.`_tidb_rowid` BETWEEN 100 AND 100 +batch limit 3 dry run update t set b = 42; +split statement examples +UPDATE `session__nontransactional`.`t` SET `b`=42 WHERE `session__nontransactional`.`t`.`_tidb_rowid` BETWEEN 1 AND 3 +UPDATE `session__nontransactional`.`t` SET `b`=42 WHERE `session__nontransactional`.`t`.`_tidb_rowid` BETWEEN 100 AND 100 +batch limit 3 dry run insert into t1 select * from t; +split statement examples +INSERT INTO `session__nontransactional`.`t1` SELECT * FROM `session__nontransactional`.`t` WHERE `session__nontransactional`.`t`.`_tidb_rowid` BETWEEN 1 AND 3 +INSERT INTO `session__nontransactional`.`t1` SELECT * FROM `session__nontransactional`.`t` WHERE `session__nontransactional`.`t`.`_tidb_rowid` BETWEEN 100 AND 100 +batch limit 3 dry run insert into t1 select * from t on duplicate key update t1.b=t.b; +split statement examples +INSERT INTO `session__nontransactional`.`t1` SELECT * FROM `session__nontransactional`.`t` WHERE `session__nontransactional`.`t`.`_tidb_rowid` BETWEEN 1 AND 3 ON DUPLICATE KEY UPDATE `t1`.`b`=`t`.`b` +INSERT INTO `session__nontransactional`.`t1` SELECT * FROM `session__nontransactional`.`t` WHERE `session__nontransactional`.`t`.`_tidb_rowid` BETWEEN 100 AND 100 ON DUPLICATE KEY UPDATE `t1`.`b`=`t`.`b` +batch on _tidb_rowid limit 3 dry run delete from t; +split statement examples +DELETE FROM `session__nontransactional`.`t` WHERE `_tidb_rowid` BETWEEN 1 AND 3 +DELETE FROM `session__nontransactional`.`t` WHERE `_tidb_rowid` BETWEEN 100 AND 100 +batch on t._tidb_rowid limit 3 dry run delete from t; +split statement examples +DELETE FROM `session__nontransactional`.`t` WHERE `t`.`_tidb_rowid` BETWEEN 1 AND 3 +DELETE FROM `session__nontransactional`.`t` WHERE `t`.`_tidb_rowid` BETWEEN 100 AND 100 +batch on _tidb_rowid limit 3 dry run update t set b = 42; +split statement examples +UPDATE `session__nontransactional`.`t` SET `b`=42 WHERE `_tidb_rowid` BETWEEN 1 AND 3 +UPDATE `session__nontransactional`.`t` SET `b`=42 WHERE `_tidb_rowid` BETWEEN 100 AND 100 +batch on t._tidb_rowid limit 3 dry run update t set b = 42; +split statement examples +UPDATE `session__nontransactional`.`t` SET `b`=42 WHERE `t`.`_tidb_rowid` BETWEEN 1 AND 3 +UPDATE `session__nontransactional`.`t` SET `b`=42 WHERE `t`.`_tidb_rowid` BETWEEN 100 AND 100 +batch on _tidb_rowid limit 3 dry run insert into t1 select * from t; +split statement examples +INSERT INTO `session__nontransactional`.`t1` SELECT * FROM `session__nontransactional`.`t` WHERE `_tidb_rowid` BETWEEN 1 AND 3 +INSERT INTO `session__nontransactional`.`t1` SELECT * FROM `session__nontransactional`.`t` WHERE `_tidb_rowid` BETWEEN 100 AND 100 +batch on t._tidb_rowid limit 3 dry run insert into t1 select * from t; +split statement examples +INSERT INTO `session__nontransactional`.`t1` SELECT * FROM `session__nontransactional`.`t` WHERE `t`.`_tidb_rowid` BETWEEN 1 AND 3 +INSERT INTO `session__nontransactional`.`t1` SELECT * FROM `session__nontransactional`.`t` WHERE `t`.`_tidb_rowid` BETWEEN 100 AND 100 +batch on _tidb_rowid limit 3 dry run insert into t1 select * from t on duplicate key update t1.b=t.b; +split statement examples +INSERT INTO `session__nontransactional`.`t1` SELECT * FROM `session__nontransactional`.`t` WHERE `_tidb_rowid` BETWEEN 1 AND 3 ON DUPLICATE KEY UPDATE `t1`.`b`=`t`.`b` +INSERT INTO `session__nontransactional`.`t1` SELECT * FROM `session__nontransactional`.`t` WHERE `_tidb_rowid` BETWEEN 100 AND 100 ON DUPLICATE KEY UPDATE `t1`.`b`=`t`.`b` +batch on t._tidb_rowid limit 3 dry run insert into t1 select * from t on duplicate key update t1.b=t.b; +split statement examples +INSERT INTO `session__nontransactional`.`t1` SELECT * FROM `session__nontransactional`.`t` WHERE `t`.`_tidb_rowid` BETWEEN 1 AND 3 ON DUPLICATE KEY UPDATE `t1`.`b`=`t`.`b` +INSERT INTO `session__nontransactional`.`t1` SELECT * FROM `session__nontransactional`.`t` WHERE `t`.`_tidb_rowid` BETWEEN 100 AND 100 ON DUPLICATE KEY UPDATE `t1`.`b`=`t`.`b` +batch on _tidb_rowid limit 3 insert into t1 select * from t; +number of jobs job status +34 all succeeded +select count(*) from t; +count(*) +100 +select count(*) from t1; +count(*) +100 +(select * from t1 order by a) except (select * from t order by a); +a b +(select * from t order by a) except (select * from t1 order by a); +a b +update t1 set b = 0; +batch on _tidb_rowid limit 3 insert into t1 select * from t on duplicate key update t1.b=t.b; +number of jobs job status +34 all succeeded +select count(*) from t; +count(*) +100 +select count(*) from t1; +count(*) +100 +(select * from t1 order by a) except (select * from t order by a); +a b +(select * from t order by a) except (select * from t1 order by a); +a b +batch on _tidb_rowid limit 3 update t set b = 42; +number of jobs job status +34 all succeeded +select sum(b) from t; +sum(b) +4200 +batch on _tidb_rowid limit 3 delete from t; +number of jobs job status +34 all succeeded +select count(*) from t; +count(*) +0 +set @@tidb_max_chunk_size=default; +set @@tidb_max_chunk_size=35; +drop table if exists t, t1; +create table t(a int, b int, primary key(a, b) clustered); +create table t1(a int, b int, primary key(a, b) clustered); +insert into t values ('0', 0); +insert into t values ('1', 2); +insert into t values ('2', 4); +insert into t values ('3', 6); +insert into t values ('4', 8); +insert into t values ('5', 10); +insert into t values ('6', 12); +insert into t values ('7', 14); +insert into t values ('8', 16); +insert into t values ('9', 18); +insert into t values ('10', 20); +insert into t values ('11', 22); +insert into t values ('12', 24); +insert into t values ('13', 26); +insert into t values ('14', 28); +insert into t values ('15', 30); +insert into t values ('16', 32); +insert into t values ('17', 34); +insert into t values ('18', 36); +insert into t values ('19', 38); +insert into t values ('20', 40); +insert into t values ('21', 42); +insert into t values ('22', 44); +insert into t values ('23', 46); +insert into t values ('24', 48); +insert into t values ('25', 50); +insert into t values ('26', 52); +insert into t values ('27', 54); +insert into t values ('28', 56); +insert into t values ('29', 58); +insert into t values ('30', 60); +insert into t values ('31', 62); +insert into t values ('32', 64); +insert into t values ('33', 66); +insert into t values ('34', 68); +insert into t values ('35', 70); +insert into t values ('36', 72); +insert into t values ('37', 74); +insert into t values ('38', 76); +insert into t values ('39', 78); +insert into t values ('40', 80); +insert into t values ('41', 82); +insert into t values ('42', 84); +insert into t values ('43', 86); +insert into t values ('44', 88); +insert into t values ('45', 90); +insert into t values ('46', 92); +insert into t values ('47', 94); +insert into t values ('48', 96); +insert into t values ('49', 98); +insert into t values ('50', 100); +insert into t values ('51', 102); +insert into t values ('52', 104); +insert into t values ('53', 106); +insert into t values ('54', 108); +insert into t values ('55', 110); +insert into t values ('56', 112); +insert into t values ('57', 114); +insert into t values ('58', 116); +insert into t values ('59', 118); +insert into t values ('60', 120); +insert into t values ('61', 122); +insert into t values ('62', 124); +insert into t values ('63', 126); +insert into t values ('64', 128); +insert into t values ('65', 130); +insert into t values ('66', 132); +insert into t values ('67', 134); +insert into t values ('68', 136); +insert into t values ('69', 138); +insert into t values ('70', 140); +insert into t values ('71', 142); +insert into t values ('72', 144); +insert into t values ('73', 146); +insert into t values ('74', 148); +insert into t values ('75', 150); +insert into t values ('76', 152); +insert into t values ('77', 154); +insert into t values ('78', 156); +insert into t values ('79', 158); +insert into t values ('80', 160); +insert into t values ('81', 162); +insert into t values ('82', 164); +insert into t values ('83', 166); +insert into t values ('84', 168); +insert into t values ('85', 170); +insert into t values ('86', 172); +insert into t values ('87', 174); +insert into t values ('88', 176); +insert into t values ('89', 178); +insert into t values ('90', 180); +insert into t values ('91', 182); +insert into t values ('92', 184); +insert into t values ('93', 186); +insert into t values ('94', 188); +insert into t values ('95', 190); +insert into t values ('96', 192); +insert into t values ('97', 194); +insert into t values ('98', 196); +insert into t values ('99', 198); +batch on a limit 3 dry run insert into t1 select * from t; +split statement examples +INSERT INTO `session__nontransactional`.`t1` SELECT * FROM `session__nontransactional`.`t` WHERE `a` BETWEEN 0 AND 2 +INSERT INTO `session__nontransactional`.`t1` SELECT * FROM `session__nontransactional`.`t` WHERE `a` BETWEEN 99 AND 99 +batch on a limit 3 dry run insert into t1 select * from t on duplicate key update t1.b=t.b; +split statement examples +INSERT INTO `session__nontransactional`.`t1` SELECT * FROM `session__nontransactional`.`t` WHERE `a` BETWEEN 0 AND 2 ON DUPLICATE KEY UPDATE `t1`.`b`=`t`.`b` +INSERT INTO `session__nontransactional`.`t1` SELECT * FROM `session__nontransactional`.`t` WHERE `a` BETWEEN 99 AND 99 ON DUPLICATE KEY UPDATE `t1`.`b`=`t`.`b` +batch on a limit 3 dry run delete from t; +split statement examples +DELETE FROM `session__nontransactional`.`t` WHERE `a` BETWEEN 0 AND 2 +DELETE FROM `session__nontransactional`.`t` WHERE `a` BETWEEN 99 AND 99 +batch on a limit 3 dry run update t set b = b + 42; +split statement examples +UPDATE `session__nontransactional`.`t` SET `b`=(`b` + 42) WHERE `a` BETWEEN 0 AND 2 +UPDATE `session__nontransactional`.`t` SET `b`=(`b` + 42) WHERE `a` BETWEEN 99 AND 99 +batch on a limit 3 dry run query insert into t1 select * from t; +query statement +SELECT `a` FROM `session__nontransactional`.`t` WHERE TRUE ORDER BY IF(ISNULL(`a`),0,1),`a` +batch on a limit 3 dry run query insert into t1 select * from t on duplicate key update t1.b=t.b; +query statement +SELECT `a` FROM `session__nontransactional`.`t` WHERE TRUE ORDER BY IF(ISNULL(`a`),0,1),`a` +batch on a limit 3 dry run query delete from t; +query statement +SELECT `a` FROM `session__nontransactional`.`t` WHERE TRUE ORDER BY IF(ISNULL(`a`),0,1),`a` +batch on a limit 3 dry run query update t set b = b + 42; +query statement +SELECT `a` FROM `session__nontransactional`.`t` WHERE TRUE ORDER BY IF(ISNULL(`a`),0,1),`a` +select count(*) from t; +count(*) +100 +select sum(b) from t; +sum(b) +9900 +set @@tidb_max_chunk_size=default; diff --git a/tests/integrationtest/t/expression/builtin.test b/tests/integrationtest/t/expression/builtin.test index 4b6abbcb0c217..7cf6ffddb3536 100644 --- a/tests/integrationtest/t/expression/builtin.test +++ b/tests/integrationtest/t/expression/builtin.test @@ -1373,3 +1373,184 @@ select translate(str, 'AAa', '') from t; select translate(str, '', 'Zzz') from t; select translate(i, '0123456', 'abcdefg') from t; set tidb_enable_vectorized_expression=default; + +# TestEncryptionBuiltin +drop table if exists t; +create table t(a char(41), b char(41), c char(41)); +insert into t values(NULL, '', 'abc'); +select password(a) from t; +select password(b) from t; +select password(c) from t; +drop table if exists t; +create table t(a char(10), b int, c double, d datetime, e time, f bit(4), g binary(20), h blob(10), i text(30)); +insert into t values('2', 2, 2.3, "2017-01-01 12:01:01", "12:01:01", 0b1010, "512", "48", "tidb"); +select md5(a), md5(b), md5(c), md5(d), md5(e), md5(f), md5(g), md5(h), md5(i) from t; +select md5('123'), md5(123), md5(''), md5('你好'), md5(NULL), md5('👍'); +drop table if exists t; +create table t(a char(10), b int, c double, d datetime, e time, f bit(4), g binary(20), h blob(10), i text(30)); +insert into t values('2', 2, 2.3, "2017-01-01 12:01:01", "12:01:01", 0b1010, "512", "48", "tidb"); +select sha1(a), sha1(b), sha1(c), sha1(d), sha1(e), sha1(f), sha1(g), sha1(h), sha1(i) from t; +select sha1('123'), sha1(123), sha1(''), sha1('你好'), sha1(NULL); +drop table if exists t; +create table t(a char(10), b int, c double, d datetime, e time, f bit(4), g binary(20), h blob(10), i text(30)); +insert into t values('2', 2, 2.3, "2017-01-01 12:01:01", "12:01:01", 0b1010, "512", "48", "tidb"); +select sha(a), sha(b), sha(c), sha(d), sha(e), sha(f), sha(g), sha(h), sha(i) from t; +select sha('123'), sha(123), sha(''), sha('你好'), sha(NULL); +drop table if exists t; +create table t(a char(10), b int, c double, d datetime, e time, f bit(4), g binary(20), h blob(10), i text(30)); +insert into t values('2', 2, 2.3, "2017-01-01 12:01:01", "12:01:01", 0b1010, "512", "48", "tidb"); +select sha2(a, 224), sha2(b, 0), sha2(c, 512), sha2(d, 256), sha2(e, 384), sha2(f, 0), sha2(g, 512), sha2(h, 256), sha2(i, 224) from t; +select sha2('123', 512), sha2(123, 512), sha2('', 512), sha2('你好', 224), sha2(NULL, 256), sha2('foo', 123); +drop table if exists t; +create table t(a char(10), b int, c double, d datetime, e time, f bit(4), g binary(20), h blob(10), i text(30)); +insert into t values('2', 2, 2.3, "2017-01-01 12:01:01", "12:01:01", 0b1010, "512", "48", "tidb"); +select sm3(a), sm3(b), sm3(c), sm3(d), sm3(e), sm3(f), sm3(g), sm3(h), sm3(i) from t; +select sm3('123'), sm3(123), sm3(''), sm3('你好'), sm3(NULL); +drop table if exists t; +create table t(a char(10), b int, c double, d datetime, e time, f bit(4), g binary(20), h blob(10), i text(30)); +insert into t values('2', 2, 2.3, "2017-01-01 12:01:01", "12:01:01", 0b1010, "512", "48", "tidb"); +select sm3(a), sm3(b), sm3(c), sm3(d), sm3(e), sm3(f), sm3(g), sm3(h), sm3(i) from t; +select sm3('123'), sm3(123), sm3(''), sm3('你好'), sm3(NULL); +drop table if exists t; +create table t(a char(10), b int, c double, d datetime, e time, f bit(4), g binary(20), h blob(10), i text(30)); +insert into t values('2', 2, 2.3, "2017-01-01 12:01:01", "12:01:01", 0b1010, "512", "48", "tidb"); +SET block_encryption_mode='aes-128-ecb'; +select HEX(AES_ENCRYPT(a, 'key')), HEX(AES_ENCRYPT(b, 'key')), HEX(AES_ENCRYPT(c, 'key')), HEX(AES_ENCRYPT(d, 'key')), HEX(AES_ENCRYPT(e, 'key')), HEX(AES_ENCRYPT(f, 'key')), HEX(AES_ENCRYPT(g, 'key')), HEX(AES_ENCRYPT(h, 'key')), HEX(AES_ENCRYPT(i, 'key')) from t; +select HEX(AES_ENCRYPT('123', 'foobar')), HEX(AES_ENCRYPT(123, 'foobar')), HEX(AES_ENCRYPT('', 'foobar')), HEX(AES_ENCRYPT('你好', 'foobar')), AES_ENCRYPT(NULL, 'foobar'); +select HEX(AES_ENCRYPT(a, 'key', 'iv')), HEX(AES_ENCRYPT(b, 'key', 'iv')) from t; +show warnings; +SET block_encryption_mode='aes-128-cbc'; +select HEX(AES_ENCRYPT(a, 'key', '1234567890123456')), HEX(AES_ENCRYPT(b, 'key', '1234567890123456')), HEX(AES_ENCRYPT(c, 'key', '1234567890123456')), HEX(AES_ENCRYPT(d, 'key', '1234567890123456')), HEX(AES_ENCRYPT(e, 'key', '1234567890123456')), HEX(AES_ENCRYPT(f, 'key', '1234567890123456')), HEX(AES_ENCRYPT(g, 'key', '1234567890123456')), HEX(AES_ENCRYPT(h, 'key', '1234567890123456')), HEX(AES_ENCRYPT(i, 'key', '1234567890123456')) from t; +select HEX(AES_ENCRYPT('123', 'foobar', '1234567890123456')), HEX(AES_ENCRYPT(123, 'foobar', '1234567890123456')), HEX(AES_ENCRYPT('', 'foobar', '1234567890123456')), HEX(AES_ENCRYPT('你好', 'foobar', '1234567890123456')), AES_ENCRYPT(NULL, 'foobar', '1234567890123456'); +SET block_encryption_mode='aes-128-ofb'; +select HEX(AES_ENCRYPT(a, 'key', '1234567890123456')), HEX(AES_ENCRYPT(b, 'key', '1234567890123456')), HEX(AES_ENCRYPT(c, 'key', '1234567890123456')), HEX(AES_ENCRYPT(d, 'key', '1234567890123456')), HEX(AES_ENCRYPT(e, 'key', '1234567890123456')), HEX(AES_ENCRYPT(f, 'key', '1234567890123456')), HEX(AES_ENCRYPT(g, 'key', '1234567890123456')), HEX(AES_ENCRYPT(h, 'key', '1234567890123456')), HEX(AES_ENCRYPT(i, 'key', '1234567890123456')) from t; +select HEX(AES_ENCRYPT('123', 'foobar', '1234567890123456')), HEX(AES_ENCRYPT(123, 'foobar', '1234567890123456')), HEX(AES_ENCRYPT('', 'foobar', '1234567890123456')), HEX(AES_ENCRYPT('你好', 'foobar', '1234567890123456')), AES_ENCRYPT(NULL, 'foobar', '1234567890123456'); +SET block_encryption_mode='aes-192-ofb'; +select HEX(AES_ENCRYPT(a, 'key', '1234567890123456')), HEX(AES_ENCRYPT(b, 'key', '1234567890123456')), HEX(AES_ENCRYPT(c, 'key', '1234567890123456')), HEX(AES_ENCRYPT(d, 'key', '1234567890123456')), HEX(AES_ENCRYPT(e, 'key', '1234567890123456')), HEX(AES_ENCRYPT(f, 'key', '1234567890123456')), HEX(AES_ENCRYPT(g, 'key', '1234567890123456')), HEX(AES_ENCRYPT(h, 'key', '1234567890123456')), HEX(AES_ENCRYPT(i, 'key', '1234567890123456')) from t; +select HEX(AES_ENCRYPT('123', 'foobar', '1234567890123456')), HEX(AES_ENCRYPT(123, 'foobar', '1234567890123456')), HEX(AES_ENCRYPT('', 'foobar', '1234567890123456')), HEX(AES_ENCRYPT('你好', 'foobar', '1234567890123456')), AES_ENCRYPT(NULL, 'foobar', '1234567890123456'); +SET block_encryption_mode='aes-256-ofb'; +select HEX(AES_ENCRYPT(a, 'key', '1234567890123456')), HEX(AES_ENCRYPT(b, 'key', '1234567890123456')), HEX(AES_ENCRYPT(c, 'key', '1234567890123456')), HEX(AES_ENCRYPT(d, 'key', '1234567890123456')), HEX(AES_ENCRYPT(e, 'key', '1234567890123456')), HEX(AES_ENCRYPT(f, 'key', '1234567890123456')), HEX(AES_ENCRYPT(g, 'key', '1234567890123456')), HEX(AES_ENCRYPT(h, 'key', '1234567890123456')), HEX(AES_ENCRYPT(i, 'key', '1234567890123456')) from t; +select HEX(AES_ENCRYPT('123', 'foobar', '1234567890123456')), HEX(AES_ENCRYPT(123, 'foobar', '1234567890123456')), HEX(AES_ENCRYPT('', 'foobar', '1234567890123456')), HEX(AES_ENCRYPT('你好', 'foobar', '1234567890123456')), AES_ENCRYPT(NULL, 'foobar', '1234567890123456'); +SET block_encryption_mode='aes-128-ecb'; +select AES_DECRYPT(AES_ENCRYPT('foo', 'bar'), 'bar'); +select AES_DECRYPT(UNHEX('45ABDD5C4802EFA6771A94C43F805208'), 'foobar'), AES_DECRYPT(UNHEX('791F1AEB6A6B796E6352BF381895CA0E'), 'foobar'), AES_DECRYPT(UNHEX('D0147E2EB856186F146D9F6DE33F9546'), 'foobar'), AES_DECRYPT(NULL, 'foobar'), AES_DECRYPT('SOME_THING_STRANGE', 'foobar'); +SET block_encryption_mode='aes-128-cbc'; +select AES_DECRYPT(AES_ENCRYPT('foo', 'bar', '1234567890123456'), 'bar', '1234567890123456'); +select AES_DECRYPT(UNHEX('80D5646F07B4654B05A02D9085759770'), 'foobar', '1234567890123456'), AES_DECRYPT(UNHEX('B3C14BA15030D2D7E99376DBE011E752'), 'foobar', '1234567890123456'), AES_DECRYPT(UNHEX('0CD2936EE4FEC7A8CDF6208438B2BC05'), 'foobar', '1234567890123456'), AES_DECRYPT(NULL, 'foobar', '1234567890123456'), AES_DECRYPT('SOME_THING_STRANGE', 'foobar', '1234567890123456'); +SET block_encryption_mode='aes-128-ofb'; +select AES_DECRYPT(AES_ENCRYPT('foo', 'bar', '1234567890123456'), 'bar', '1234567890123456'); +select AES_DECRYPT(UNHEX('48E38A'), 'foobar', '1234567890123456'), AES_DECRYPT(UNHEX(''), 'foobar', '1234567890123456'), AES_DECRYPT(UNHEX('9D6C199101C3'), 'foobar', '1234567890123456'), AES_DECRYPT(NULL, 'foobar', '1234567890123456'), HEX(AES_DECRYPT('SOME_THING_STRANGE', 'foobar', '1234567890123456')); +SET block_encryption_mode='aes-192-ofb'; +select AES_DECRYPT(AES_ENCRYPT('foo', 'bar', '1234567890123456'), 'bar', '1234567890123456'); +select AES_DECRYPT(UNHEX('3A76B0'), 'foobar', '1234567890123456'), AES_DECRYPT(UNHEX(''), 'foobar', '1234567890123456'), AES_DECRYPT(UNHEX('EFF92304268E'), 'foobar', '1234567890123456'), AES_DECRYPT(NULL, 'foobar', '1234567890123456'), HEX(AES_DECRYPT('SOME_THING_STRANGE', 'foobar', '1234567890123456')); +SET block_encryption_mode='aes-256-ofb'; +select AES_DECRYPT(AES_ENCRYPT('foo', 'bar', '1234567890123456'), 'bar', '1234567890123456'); +select AES_DECRYPT(UNHEX('E842C5'), 'foobar', '1234567890123456'), AES_DECRYPT(UNHEX(''), 'foobar', '1234567890123456'), AES_DECRYPT(UNHEX('3DCD5646767D'), 'foobar', '1234567890123456'), AES_DECRYPT(NULL, 'foobar', '1234567890123456'), HEX(AES_DECRYPT('SOME_THING_STRANGE', 'foobar', '1234567890123456')); +DROP TABLE IF EXISTS t1; +CREATE TABLE t1(a VARCHAR(1000)); +INSERT INTO t1 VALUES('12345'), ('23456'); +SELECT HEX(COMPRESS(a)) FROM t1; +DROP TABLE IF EXISTS t2; +CREATE TABLE t2(a VARCHAR(1000), b VARBINARY(1000)); +INSERT INTO t2 (a, b) SELECT a, COMPRESS(a) from t1; +SELECT a, HEX(b) FROM t2; +SELECT UNCOMPRESS(COMPRESS('123')); +SELECT UNCOMPRESS(UNHEX('03000000789C3334320600012D0097')); +SELECT UNCOMPRESS(UNHEX('03000000789C32343206040000FFFF012D0097')); +INSERT INTO t2 VALUES ('12345', UNHEX('05000000789C3334323631050002F80100')); +SELECT UNCOMPRESS(a), UNCOMPRESS(b) FROM t2; +SELECT UNCOMPRESSED_LENGTH(COMPRESS('123')); +SELECT UNCOMPRESSED_LENGTH(UNHEX('03000000789C3334320600012D0097')); +SELECT UNCOMPRESSED_LENGTH(UNHEX('03000000789C32343206040000FFFF012D0097')); +SELECT UNCOMPRESSED_LENGTH(''); +SELECT UNCOMPRESSED_LENGTH(UNHEX('0100')); +SELECT UNCOMPRESSED_LENGTH(a), UNCOMPRESSED_LENGTH(b) FROM t2; +-- error 1690 +SELECT RANDOM_BYTES(0); +-- error 1690 +SELECT RANDOM_BYTES(-5); +-- error 1690 +SELECT RANDOM_BYTES(1025); +-- error 1690 +SELECT RANDOM_BYTES(4000); +SELECT length(RANDOM_BYTES('1')); +SELECT length(RANDOM_BYTES(1024)); +SELECT RANDOM_BYTES(NULL); +SET GLOBAL validate_password.dictionary='password'; +SET GLOBAL validate_password.enable = 1; +SELECT validate_password_strength('root'); +SELECT validate_password_strength('toor'); +SELECT validate_password_strength('ROOT'); +SELECT validate_password_strength('TOOR'); +SELECT validate_password_strength('fooHoHo%1'); +SELECT validate_password_strength('pass'); +SELECT validate_password_strength('password'); +SELECT validate_password_strength('password0000'); +SELECT validate_password_strength('password1A#'); +SELECT validate_password_strength('PA12wrd!#'); +SELECT VALIDATE_PASSWORD_STRENGTH(REPEAT("aA1#", 26)); +SELECT validate_password_strength(null); +SELECT validate_password_strength('null'); +SELECT VALIDATE_PASSWORD_STRENGTH( 0x6E616E646F73617135234552 ); +SELECT VALIDATE_PASSWORD_STRENGTH(CAST(0xd2 AS BINARY(10))); +SET GLOBAL validate_password.dictionary=default; +SET GLOBAL validate_password.enable = default; +SET block_encryption_mode=default; + +# TestMiscellaneousBuiltin +select uuid() REGEXP '[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}', + uuid() REGEXP '[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}', + uuid() REGEXP '[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}', + uuid() REGEXP '[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}', + uuid() REGEXP '[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}'; +select sleep(1); +select sleep(0); +select sleep('a'); +show warnings; +-- error 1510 +select sleep(-1); +SELECT INET_ATON('10.0.5.9'); +SELECT INET_NTOA(167773449); +SELECT HEX(INET6_ATON('fdfe::5a55:caff:fefa:9089')); +SELECT HEX(INET6_ATON('10.0.5.9')); +SELECT INET6_NTOA(INET6_ATON('fdfe::5a55:caff:fefa:9089')); +SELECT INET6_NTOA(INET6_ATON('10.0.5.9')); +SELECT INET6_NTOA(UNHEX('FDFE0000000000005A55CAFFFEFA9089')); +SELECT INET6_NTOA(UNHEX('0A000509')); +SELECT IS_IPV4('10.0.5.9'), IS_IPV4('10.0.5.256'); +SELECT IS_IPV4_COMPAT(INET6_ATON('::10.0.5.9')); +SELECT IS_IPV4_COMPAT(INET6_ATON('::ffff:10.0.5.9')); +SELECT + IS_IPV4_COMPAT(INET6_ATON('::192.168.0.1')), + IS_IPV4_COMPAT(INET6_ATON('::c0a8:0001')), + IS_IPV4_COMPAT(INET6_ATON('::c0a8:1')); +SELECT IS_IPV4_MAPPED(INET6_ATON('::10.0.5.9')); +SELECT IS_IPV4_MAPPED(INET6_ATON('::ffff:10.0.5.9')); +SELECT + IS_IPV4_MAPPED(INET6_ATON('::ffff:192.168.0.1')), + IS_IPV4_MAPPED(INET6_ATON('::ffff:c0a8:0001')), + IS_IPV4_MAPPED(INET6_ATON('::ffff:c0a8:1')); +SELECT IS_IPV6('10.0.5.9'), IS_IPV6('::1'); +drop table if exists t1; +create table t1( + a int, + b int not null, + c int not null default 0, + d int default 0, + unique key(b,c), + unique key(b,d) +); +insert into t1 (a,b) values(1,10),(1,20),(2,30),(2,40); +select any_value(a), sum(b) from t1; +select a,any_value(b),sum(c) from t1 group by a order by a; +SELECT GET_LOCK('test_lock1', 10); +SELECT GET_LOCK('test_lock2', 10); +SELECT IS_USED_LOCK('test_lock1') = CONNECTION_ID(); +SELECT IS_USED_LOCK('foobar'); +SELECT IS_FREE_LOCK('test_lock1'); +SELECT IS_FREE_LOCK('foobar'); +SELECT RELEASE_LOCK('test_lock2'); +SELECT RELEASE_LOCK('test_lock1'); +SELECT RELEASE_LOCK('test_lock3'); +SELECT RELEASE_ALL_LOCKS(); + diff --git a/tests/integrationtest/t/expression/issues.test b/tests/integrationtest/t/expression/issues.test index e17313f0668b4..9ba84bb1a498f 100644 --- a/tests/integrationtest/t/expression/issues.test +++ b/tests/integrationtest/t/expression/issues.test @@ -1899,3 +1899,20 @@ select * from (select (92 / 4) as c4) as subq_0 where exists ( union all select 1 as c0 from (t0 as ref_88) where (subq_0.c4) >= (subq_0.c4) ); + +# TestIssue41986 +drop table if exists poi_clearing_time_topic; +CREATE TABLE poi_clearing_time_topic (effective_date datetime DEFAULT NULL , clearing_time int(11) DEFAULT NULL); +insert into poi_clearing_time_topic values ('2023:08:25', 1); +# shouldn't report they can't find column error and return the right result. +SELECT GROUP_CONCAT(effective_date order by stlmnt_hour DESC) FROM ( SELECT (COALESCE(pct.clearing_time, 0)/3600000) AS stlmnt_hour ,COALESCE(pct.effective_date, '1970-01-01 08:00:00') AS effective_date FROM poi_clearing_time_topic pct ORDER BY pct.effective_date DESC ) a; + +# TestIssue10804 +SELECT @@information_schema_stats_expiry; +/*!80000 SET SESSION information_schema_stats_expiry=0 */; +SELECT @@information_schema_stats_expiry; +SELECT @@GLOBAL.information_schema_stats_expiry; +/*!80000 SET GLOBAL information_schema_stats_expiry=0 */; +SELECT @@GLOBAL.information_schema_stats_expiry; +set @@SESSION.information_schema_stats_expiry=default; +set @@GLOBAL.information_schema_stats_expiry=default; diff --git a/tests/integrationtest/t/expression/misc.test b/tests/integrationtest/t/expression/misc.test index f3f34dff76db5..7250a10405402 100644 --- a/tests/integrationtest/t/expression/misc.test +++ b/tests/integrationtest/t/expression/misc.test @@ -565,3 +565,19 @@ insert into t1 values (2, 'a'), (1, 'b'), (3, 'c'), (0, null); create table t2 (i2 integer, c2 char, f2 float); insert into t2 values (0, 'c', null), (1, null, 0.1), (3, 'b', 0.01), (2, 'q', 0.12), (null, 'a', -0.1), (null, null, null); select * from t2 where t2.i2=((select count(1) from t1 where t1.i1=t2.i2)); + +# TestTiDBDecodePlanFunc +select tidb_decode_plan(''); +select tidb_decode_plan('7APIMAk1XzEzCTAJMQlmdW5jczpjb3VudCgxKQoxCTE3XzE0CTAJMAlpbm5lciBqb2luLCBpAQyQOlRhYmxlUmVhZGVyXzIxLCBlcXVhbDpbZXEoQ29sdW1uIzEsIA0KCDkpIBkXADIVFywxMCldCjIJMzFfMTgFZXhkYXRhOlNlbGVjdGlvbl8xNwozCTFfMTcJMQkwCWx0HVlATlVMTCksIG5vdChpc251bGwVHAApUhcAUDIpKQo0CTEwXzE2CTEJMTAwMDAJdAHB2Dp0MSwgcmFuZ2U6Wy1pbmYsK2luZl0sIGtlZXAgb3JkZXI6ZmFsc2UsIHN0YXRzOnBzZXVkbwoFtgAyAZcEMAk6tgAEMjAFtgQyMDq2AAg5LCBmtgAAMFa3AAA5FbcAOT63AAAyzrcA'); +select tidb_decode_plan('rwPwcTAJNV8xNAkwCTEJZnVuY3M6bWF4KHRlc3QudC5hKS0+Q29sdW1uIzQJMQl0aW1lOjIyMy45MzXCtXMsIGxvb3BzOjIJMTI4IEJ5dGVzCU4vQQoxCTE2XzE4CTAJMQlvZmZzZXQ6MCwgY291bnQ6MQkxCQlHFDE4LjQyMjJHAAhOL0EBBCAKMgkzMl8yOAkBlEBpbmRleDpMaW1pdF8yNwkxCQ0+DDYuODUdPSwxLCBycGMgbnVtOiANDAUpGDE1MC44MjQFKjhwcm9jIGtleXM6MAkxOTgdsgAzAbIAMgFearIAFDU3LjM5NgVKAGwN+BGxIDQJMTNfMjYJMQGgHGFibGU6dCwgCbqwaWR4KGEpLCByYW5nZTooMCwraW5mXSwga2VlcCBvcmRlcjp0cnVlLCBkZXNjAT8kaW1lOjU2LjY2MR1rJDEJTi9BCU4vQQo='); +--disable_result_log +select tidb_decode_plan(query), time from information_schema.slow_query order by time desc limit 1; +--enable_result_log +select tidb_decode_plan('xxx'); + +# TestDatetimeUserVariable +set @p = now(); +set @@tidb_enable_vectorized_expression = false; +select length(@p); +set @@tidb_enable_vectorized_expression = true; +select length(@p); diff --git a/tests/integrationtest/t/expression/plan_cache.test b/tests/integrationtest/t/expression/plan_cache.test index 232c614760196..2d211d1187cf7 100644 --- a/tests/integrationtest/t/expression/plan_cache.test +++ b/tests/integrationtest/t/expression/plan_cache.test @@ -38,3 +38,77 @@ execute stmt; set @@session.sql_select_limit = 2; execute stmt; set sql_select_limit=default; + +# TestPreparePlanCache +set tidb_enable_prepared_plan_cache=ON; +drop table if exists t; +create table t(a int); +prepare stmt from 'select * from t where a = ?'; +set @a = 1; +execute stmt using @a; +select @@last_plan_from_cache; +execute stmt using @a; +select @@last_plan_from_cache; +set tidb_enable_prepared_plan_cache=default; + +# TestRowCountPlanCache +set tidb_enable_prepared_plan_cache=ON; +drop table if exists t; +create table t(a int auto_increment primary key); +prepare stmt from 'select row_count()'; +insert into t values(); +execute stmt; +insert into t values(),(),(); +execute stmt; +set tidb_enable_prepared_plan_cache=default; + +# TestCacheRegexpr +set tidb_enable_prepared_plan_cache=ON; +drop table if exists t1; +create table t1 (a varchar(40)); +insert into t1 values ('C1'),('R1'); +prepare stmt1 from 'select a from t1 where a rlike ?'; +set @a='^C.*'; +execute stmt1 using @a; +set @a='^R.*'; +execute stmt1 using @a; +set tidb_enable_prepared_plan_cache=default; + +# TestCacheRefineArgs +set tidb_enable_prepared_plan_cache=ON; +drop table if exists t; +create table t(col_int int); +insert into t values(null); +prepare stmt from 'SELECT ((col_int is true) = ?) AS res FROM t'; +set @p0='0.8'; +execute stmt using @p0; +set @p0='0'; +execute stmt using @p0; +prepare stmt from 'SELECT UCASE(?) < col_int from t;'; +set @a1 = 'xayh7vrWVNqZtzlJmdJQUwAHnkI8Ec'; +execute stmt using @a1; +delete from t; +insert into t values(1); +prepare stmt from 'SELECT col_int < ? FROM t'; +set @p0='-184467440737095516167.1'; +execute stmt using @p0; +set tidb_enable_prepared_plan_cache=default; + +# TestCacheConstEval +set tidb_enable_prepared_plan_cache=ON; +drop table if exists t; +create table t(col_double double); +insert into t values (1); +set tidb_enable_vectorized_expression=false; +insert into mysql.expr_pushdown_blacklist values('cast', 'tikv,tiflash,tidb', 'for test'); +admin reload expr_pushdown_blacklist; +prepare stmt from 'SELECT * FROM (SELECT col_double AS c0 FROM t) t WHERE (ABS((REPEAT(?, ?) OR 5617780767323292672)) < LN(EXP(c0)) + (? ^ ?))'; +set @a1 = 'JuvkBX7ykVux20zQlkwDK2DFelgn7'; +set @a2 = 1; +set @a3 = -112990.35179796701; +set @a4 = 87997.92704840179; +execute stmt using @a1, @a2, @a3, @a4; +set tidb_enable_vectorized_expression=default; +delete from mysql.expr_pushdown_blacklist where name = 'cast' and store_type = 'tikv,tiflash,tidb' and reason = 'for test'; +admin reload expr_pushdown_blacklist; +set tidb_enable_prepared_plan_cache=default; diff --git a/tests/integrationtest/t/session/nontransactional.test b/tests/integrationtest/t/session/nontransactional.test new file mode 100644 index 0000000000000..eb2fd11bb6da4 --- /dev/null +++ b/tests/integrationtest/t/session/nontransactional.test @@ -0,0 +1,1635 @@ +# TestAnomalousNontransactionalDML +drop table if exists t; +create table t(id int, v int); +insert into t values (1, 1); +batch limit 1 insert into t select * from t; +select * from t; +drop table t; +create table t(id int, v int, key(id)); +create table t2(id int, v int, key(id)); +insert into t values (1, 1), (2, 2), (3, 3); +insert into t2 values (1, 1), (2, 2), (4, 4); +batch on session__nontransactional.t.id limit 1 update t join t2 on t.id=t2.id set t2.id = t2.id+1; +select * from t2; + +# TestNameAmbiguity +drop table if exists t, t2, t3; +create table t(id int, v1 int, v2 int, unique key (id)); +create table t2(id int, v int, key (id)); +create table t3(id int, v int, key (id)); +create database session__nontransactional2; +use session__nontransactional2; +create table t(id int, v1 int, v2 int, unique key (id)); +create table t2(id int, v int, key (id)); +create table t3(id int, v int, key (id)); +insert into t values (1, 1, 1), (2, 2, 2); +use session__nontransactional; +batch on id limit 1 insert into t select * from session__nontransactional2.t; +select * from t; +drop database session__nontransactional2; + +# TestUpdatingShardColumn +drop table if exists t, t2; +create table t(id int, v int, unique key(id)); +create table t2(id int, v int, unique key(id)); +insert into t values (1, 1), (2, 2), (3, 3); +insert into t2 values (1, 1), (2, 2), (4, 4); +-- error 1105 +batch on id limit 1 update t set id=id+1; +-- error 1105 +batch on id limit 1 insert into t select * from t on duplicate key update t.id=t.id+10; +-- error 1105 +batch on id limit 1 update t as t1 set t1.id=t1.id+1; +-- error 1105 +batch on id limit 1 insert into t select * from t as t1 on duplicate key update t1.id=t1.id+10; +-- error 1105 +batch on session__nontransactional.t.id limit 1 update t join t2 on t.id=t2.id set t.id=t.id+1; +-- error 1105 +batch on session__nontransactional.tt.id limit 1 update t as tt join t2 as tt2 on tt.id=tt2.id set tt.id=tt.id+10; + +# TestAlias +drop table if exists t, t2, t3; +create table t(id int, v1 int, v2 int, unique key (id)); +create table t2(id int, v int, key (id)); +create table t3(id int, v int, key (id)); +insert into t values (1, 1, 1), (2, 2, 2), (3, 3, 3); +insert into t2 values (1, 1), (2, 20), (4, 40); +insert into t3 values (2, 21), (4, 41), (5, 50); +update t as t1 set v1 = session__nontransactional.t1.id + 1; +select * from t; +batch on session__nontransactional.tt2.id limit 1 replace into t select tt2.id, tt2.v, t3.v from t2 as tt2 join t3 on tt2.id=t3.id; +select * from t order by id; + +# TestNonTransactionalWithJoin +# insert +# BATCH ON t2.id LIMIT 10000 insert into t1 select id, name from t2 inner join t3 on t2.id = t3.id; +# insert into t1 select id, name from t2 inner join t3 on t2.id = t3.id where t2.id between 1 and 10000 +# +# replace +# BATCH ON t1.id LIMIT 10000 replace into t3 +# select * from t1 left join t2 on t1.id = t2.id; +# +# update +# BATCH ON t1.id LIMIT 10000 update t1 join t2 on t1.a=t2.a set t1.a=t1.a*1000; +# update t1 join t2 on t1.a=t2.a set t1.a=t1.a*1000 where t1.id between 1 and 10000; +# +# delete +# BATCH ON pa.id LIMIT 10000 DELETE pa +# FROM pets_activities pa JOIN pets p ON pa.id = p.pet_id +# WHERE p.order > :order AND p.pet_id = :pet_id +# delete pa +# from pets_activities pa join pets p on pa.id = p.pet_id +# WHERE p.order > :order AND p.pet_id = :pet_id and pa.id between 1 and 10000; +drop table if exists t, t2, t3; +create table t(id int, v1 int, v2 int, unique key (id)); +create table t2(id int, v int, key i1(id)); +create table t3(id int, v int, key i1(id)); +insert into t2 values (1, 2), (2, 3), (3, 4); +insert into t3 values (1, 4), (2, 5), (4, 6); +batch on session__nontransactional.t2.id limit 1 insert into t select t2.id, t2.v, t3.v from t2 join t3 on t2.id=t3.id; +select * from t; +-- error 1105 +batch on id limit 1 insert into t select t2.id, t2.v, t3.v from t2 join t3 on t2.id=t3.id; +-- error 1105 +batch on session__nontransactional.t1.id limit 1 insert into t select t2.id, t2.v, t3.v from t2 join t3 on t2.id=t3.id; +batch on session__nontransactional.t2.id limit 1 update t2 join t3 on t2.id=t3.id set t2.v=t2.v*100, t3.v=t3.v*200; +select * from t2; +select * from t3; +batch limit 1 delete t2 from t2 join t3 on t2.id=t3.id; +select * from t2; +insert into t2 values (1, 11), (2, 22); +batch limit 1 replace into t select t2.id, t2.v, t3.v from t2 join t3 on t2.id=t3.id; +select * from t; + +# TestNonTransactionalWithShardOnUnsupportedTypes +# When some day the test fail because such types are supported, we can update related docs and consider remove the test case. +drop table if exists t, t1, t2; +create table t(a set('e0', 'e1', 'e2'), b int, primary key(a) clustered, key(b)); +create table t1(a set('e0', 'e1', 'e2'), b int, primary key(a) clustered, key(b)); +insert into t values ('e2,e0', 3); +-- error 1105 +batch limit 1 insert into t1 select * from t where a = 'e0,e2'; +select count(*) from t1; +-- error 1105 +batch limit 1 insert into t1 select * from t where a = 'e0,e2' on duplicate key update t1.b=t.b; +select count(*) from t1; +-- error 1105 +batch limit 1 delete from t where a = 'e0,e2'; +select count(*) from t; +create table t2(a enum('e0', 'e1', 'e2'), b int, key(a)); +insert into t2 values ('e0', 1); +-- error 1105 +batch on a limit 1 insert into t1 select * from t2; +select count(*) from t1; +-- error 1105 +batch on a limit 1 insert into t1 select * from t2 on duplicate key update t1.b=t2.b; +select count(*) from t1; +-- error 1105 +batch on a limit 1 delete from t2; +select count(*) from t2; + +# TestNonTransactionalWithAlias +drop table if exists session__nontransactional.t, session__nontransactional.s, session__nontransactional.t2; +create table session__nontransactional.t(a int, b int, key(a)); +create table session__nontransactional.s(a int, b int, unique key(a)); +create table session__nontransactional.t2(a int, b int, key(a)); +insert into session__nontransactional.t values (0, 0); +insert into session__nontransactional.t values (1, 2); +insert into session__nontransactional.t values (2, 4); +insert into session__nontransactional.t values (3, 6); +insert into session__nontransactional.t values (4, 8); +batch on session__nontransactional.t1.a limit 5 delete t1.* from session__nontransactional.t as t1; +select count(*) from session__nontransactional.t; +insert into session__nontransactional.t values (0, 0); +insert into session__nontransactional.t values (1, 2); +insert into session__nontransactional.t values (2, 4); +insert into session__nontransactional.t values (3, 6); +insert into session__nontransactional.t values (4, 8); +batch on a limit 5 delete t1.* from session__nontransactional.t as t1; +select count(*) from session__nontransactional.t; +insert into session__nontransactional.t values (0, 0); +insert into session__nontransactional.t values (1, 2); +insert into session__nontransactional.t values (2, 4); +insert into session__nontransactional.t values (3, 6); +insert into session__nontransactional.t values (4, 8); +batch on _tidb_rowid limit 5 delete from session__nontransactional.t as t1; +select count(*) from session__nontransactional.t; +insert into session__nontransactional.t values (0, 0); +insert into session__nontransactional.t values (1, 2); +insert into session__nontransactional.t values (2, 4); +insert into session__nontransactional.t values (3, 6); +insert into session__nontransactional.t values (4, 8); +batch on t1._tidb_rowid limit 5 delete from session__nontransactional.t as t1; +select count(*) from session__nontransactional.t; +insert into session__nontransactional.t values (0, 0); +insert into session__nontransactional.t values (1, 2); +insert into session__nontransactional.t values (2, 4); +insert into session__nontransactional.t values (3, 6); +insert into session__nontransactional.t values (4, 8); +batch on session__nontransactional.t1._tidb_rowid limit 5 delete from session__nontransactional.t as t1; +select count(*) from session__nontransactional.t; +insert into session__nontransactional.t values (0, 0); +insert into session__nontransactional.t values (1, 2); +insert into session__nontransactional.t values (2, 4); +insert into session__nontransactional.t values (3, 6); +insert into session__nontransactional.t values (4, 8); +batch limit 5 delete from session__nontransactional.t as t1; +select count(*) from session__nontransactional.t; +insert into session__nontransactional.t values (0, 0); +insert into session__nontransactional.t values (1, 2); +insert into session__nontransactional.t values (2, 4); +insert into session__nontransactional.t values (3, 6); +insert into session__nontransactional.t values (4, 8); +batch on session__nontransactional.t1.a limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1; +select * from session__nontransactional.s order by a; +update session__nontransactional.s set b=a; +batch on session__nontransactional.t1.a limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1 on duplicate key update s.b=t1.b; +select * from session__nontransactional.s order by a; +truncate session__nontransactional.s; +batch on a limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1; +select * from session__nontransactional.s order by a; +update session__nontransactional.s set b=a; +batch on a limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1 on duplicate key update s.b=t1.b; +select * from session__nontransactional.s order by a; +truncate session__nontransactional.s; +batch on _tidb_rowid limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1; +select * from session__nontransactional.s order by a; +update session__nontransactional.s set b=a; +batch on _tidb_rowid limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1 on duplicate key update s.b=t1.b; +select * from session__nontransactional.s order by a; +truncate session__nontransactional.s; +batch on t1._tidb_rowid limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1; +select * from session__nontransactional.s order by a; +update session__nontransactional.s set b=a; +batch on t1._tidb_rowid limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1 on duplicate key update s.b=t1.b; +select * from session__nontransactional.s order by a; +truncate session__nontransactional.s; +batch on session__nontransactional.t1._tidb_rowid limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1; +select * from session__nontransactional.s order by a; +update session__nontransactional.s set b=a; +batch on session__nontransactional.t1._tidb_rowid limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1 on duplicate key update s.b=t1.b; +select * from session__nontransactional.s order by a; +truncate session__nontransactional.s; +batch limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1; +select * from session__nontransactional.s order by a; +update session__nontransactional.s set b=a; +batch limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1 on duplicate key update s.b=t1.b; +select * from session__nontransactional.s order by a; +truncate session__nontransactional.s; +-- error 1054 +batch on session__nontransactional.t.a limit 5 delete t1.* from session__nontransactional.t as t1; +select count(*) from session__nontransactional.t; +-- error 1054 +batch on t.a limit 5 delete t1.* from session__nontransactional.t as t1; +select count(*) from session__nontransactional.t; +-- error 1054 +batch on t._tidb_rowid limit 5 delete from session__nontransactional.t as t1; +select count(*) from session__nontransactional.t; +-- error 1054 +batch on session__nontransactional.t._tidb_rowid limit 5 delete from session__nontransactional.t as t1; +select count(*) from session__nontransactional.t; +-- error 1054 +batch on session__nontransactional.t.a limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1; +select count(*) from session__nontransactional.s; +-- error 1054 +batch on t.a limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1; +select count(*) from session__nontransactional.s; +-- error 1054 +batch on t._tidb_rowid limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1; +select count(*) from session__nontransactional.s; +-- error 1054 +batch on session__nontransactional.t._tidb_rowid limit 5 insert into session__nontransactional.s select t1.* from session__nontransactional.t as t1; +select count(*) from session__nontransactional.s; + +# TestNonTransactionalWithMultiTables +drop table if exists t, t1, t2; +create table t(a int, b int, key(a)); +create table t1(a int, b int, key(a)); +create table t2(a int, b int, key(a)); +insert into t values (0, 0); +insert into t values (1, 2); +insert into t values (2, 4); +insert into t values (3, 6); +insert into t values (4, 8); +insert into t values (5, 10); +insert into t values (6, 12); +insert into t values (7, 14); +insert into t values (8, 16); +insert into t values (9, 18); +insert into t values (10, 20); +insert into t values (11, 22); +insert into t values (12, 24); +insert into t values (13, 26); +insert into t values (14, 28); +insert into t values (15, 30); +insert into t values (16, 32); +insert into t values (17, 34); +insert into t values (18, 36); +insert into t values (19, 38); +insert into t values (20, 40); +insert into t values (21, 42); +insert into t values (22, 44); +insert into t values (23, 46); +insert into t values (24, 48); +insert into t values (25, 50); +insert into t values (26, 52); +insert into t values (27, 54); +insert into t values (28, 56); +insert into t values (29, 58); +insert into t values (30, 60); +insert into t values (31, 62); +insert into t values (32, 64); +insert into t values (33, 66); +insert into t values (34, 68); +insert into t values (35, 70); +insert into t values (36, 72); +insert into t values (37, 74); +insert into t values (38, 76); +insert into t values (39, 78); +insert into t values (40, 80); +insert into t values (41, 82); +insert into t values (42, 84); +insert into t values (43, 86); +insert into t values (44, 88); +insert into t values (45, 90); +insert into t values (46, 92); +insert into t values (47, 94); +insert into t values (48, 96); +insert into t values (49, 98); +insert into t values (50, 100); +insert into t values (51, 102); +insert into t values (52, 104); +insert into t values (53, 106); +insert into t values (54, 108); +insert into t values (55, 110); +insert into t values (56, 112); +insert into t values (57, 114); +insert into t values (58, 116); +insert into t values (59, 118); +insert into t values (60, 120); +insert into t values (61, 122); +insert into t values (62, 124); +insert into t values (63, 126); +insert into t values (64, 128); +insert into t values (65, 130); +insert into t values (66, 132); +insert into t values (67, 134); +insert into t values (68, 136); +insert into t values (69, 138); +insert into t values (70, 140); +insert into t values (71, 142); +insert into t values (72, 144); +insert into t values (73, 146); +insert into t values (74, 148); +insert into t values (75, 150); +insert into t values (76, 152); +insert into t values (77, 154); +insert into t values (78, 156); +insert into t values (79, 158); +insert into t values (80, 160); +insert into t values (81, 162); +insert into t values (82, 164); +insert into t values (83, 166); +insert into t values (84, 168); +insert into t values (85, 170); +insert into t values (86, 172); +insert into t values (87, 174); +insert into t values (88, 176); +insert into t values (89, 178); +insert into t values (90, 180); +insert into t values (91, 182); +insert into t values (92, 184); +insert into t values (93, 186); +insert into t values (94, 188); +insert into t values (95, 190); +insert into t values (96, 192); +insert into t values (97, 194); +insert into t values (98, 196); +insert into t values (99, 198); +insert into t1 values (1, 1); +-- error 1054 +batch limit 1 insert into t2 select t.a, t1.b from t, t1 where t.a = t1.a; +select count(*) from t2; +-- error 1054 +batch limit 1 insert into t2 select t.a, t1.b from t, t1 where t.a = t1.a on duplicate key update t2.b=t.b; +select count(*) from t2; +-- error 1054 +batch limit 1 delete t, t1 from t, t1 where t.a = t1.a; +select count(*) from t; +select count(*) from t1; + +# TestNonTransactionalWithOptimizerHints +drop table if exists t, t1; +create table t(a int, b int, key(a)); +create table t1(a int, b int, key(a)); +insert into t values ('0', 0); +insert into t values ('1', 2); +insert into t values ('2', 4); +insert into t values ('3', 6); +insert into t values ('4', 8); +insert into t values ('5', 10); +insert into t values ('6', 12); +insert into t values ('7', 14); +insert into t values ('8', 16); +insert into t values ('9', 18); +batch on a limit 10 dry run insert into t1 select /*+ USE_INDEX(t) */ * from t; +batch on a limit 10 dry run insert into t1 select /*+ USE_INDEX(t) */ * from t on duplicate key update t1.b=t.b; +batch on a limit 10 dry run delete /*+ USE_INDEX(t) */ from t; + +# TestNonTransactionalWithReadStaleness +set @@tidb_max_chunk_size=35; +set @@tidb_read_staleness=-100; +drop table if exists t, t1; +create table t(a int, b int, key(a)); +create table t1(a int, b int, unique key(a)); +insert into t values (0, 0); +insert into t values (1, 2); +insert into t values (2, 4); +insert into t values (3, 6); +insert into t values (4, 8); +insert into t values (5, 10); +insert into t values (6, 12); +insert into t values (7, 14); +insert into t values (8, 16); +insert into t values (9, 18); +insert into t values (10, 20); +insert into t values (11, 22); +insert into t values (12, 24); +insert into t values (13, 26); +insert into t values (14, 28); +insert into t values (15, 30); +insert into t values (16, 32); +insert into t values (17, 34); +insert into t values (18, 36); +insert into t values (19, 38); +insert into t values (20, 40); +insert into t values (21, 42); +insert into t values (22, 44); +insert into t values (23, 46); +insert into t values (24, 48); +insert into t values (25, 50); +insert into t values (26, 52); +insert into t values (27, 54); +insert into t values (28, 56); +insert into t values (29, 58); +insert into t values (30, 60); +insert into t values (31, 62); +insert into t values (32, 64); +insert into t values (33, 66); +insert into t values (34, 68); +insert into t values (35, 70); +insert into t values (36, 72); +insert into t values (37, 74); +insert into t values (38, 76); +insert into t values (39, 78); +insert into t values (40, 80); +insert into t values (41, 82); +insert into t values (42, 84); +insert into t values (43, 86); +insert into t values (44, 88); +insert into t values (45, 90); +insert into t values (46, 92); +insert into t values (47, 94); +insert into t values (48, 96); +insert into t values (49, 98); +insert into t values (50, 100); +insert into t values (51, 102); +insert into t values (52, 104); +insert into t values (53, 106); +insert into t values (54, 108); +insert into t values (55, 110); +insert into t values (56, 112); +insert into t values (57, 114); +insert into t values (58, 116); +insert into t values (59, 118); +insert into t values (60, 120); +insert into t values (61, 122); +insert into t values (62, 124); +insert into t values (63, 126); +insert into t values (64, 128); +insert into t values (65, 130); +insert into t values (66, 132); +insert into t values (67, 134); +insert into t values (68, 136); +insert into t values (69, 138); +insert into t values (70, 140); +insert into t values (71, 142); +insert into t values (72, 144); +insert into t values (73, 146); +insert into t values (74, 148); +insert into t values (75, 150); +insert into t values (76, 152); +insert into t values (77, 154); +insert into t values (78, 156); +insert into t values (79, 158); +insert into t values (80, 160); +insert into t values (81, 162); +insert into t values (82, 164); +insert into t values (83, 166); +insert into t values (84, 168); +insert into t values (85, 170); +insert into t values (86, 172); +insert into t values (87, 174); +insert into t values (88, 176); +insert into t values (89, 178); +insert into t values (90, 180); +insert into t values (91, 182); +insert into t values (92, 184); +insert into t values (93, 186); +insert into t values (94, 188); +insert into t values (95, 190); +insert into t values (96, 192); +insert into t values (97, 194); +insert into t values (98, 196); +insert into t values (99, 198); +batch on a limit 10 insert into t1 select * from t; +connect (conn1, localhost, root,, session__nontransactional); +connection conn1; +select * from t1 order by a; +update t1 set b=a; +disconnect conn1; +batch on a limit 10 insert into t1 select * from t on duplicate key update t1.b=t.b; +batch on a limit 10 delete from t; +set @@tidb_read_staleness=0; +select * from t; +select * from t1 order by a; +set @@tidb_max_chunk_size=default; +set @@tidb_read_staleness=default; + +# TestNonTransactionalWithIgnoreSelectLimit +set @@tidb_max_chunk_size=35; +set @@sql_select_limit=3; +drop table if exists t, t1; +create table t(a int, b int, key(a)); +create table t1(a int, b int, unique key(a)); +insert into t values (0, 0); +insert into t values (1, 2); +insert into t values (2, 4); +insert into t values (3, 6); +insert into t values (4, 8); +insert into t values (5, 10); +insert into t values (6, 12); +insert into t values (7, 14); +insert into t values (8, 16); +insert into t values (9, 18); +insert into t values (10, 20); +insert into t values (11, 22); +insert into t values (12, 24); +insert into t values (13, 26); +insert into t values (14, 28); +insert into t values (15, 30); +insert into t values (16, 32); +insert into t values (17, 34); +insert into t values (18, 36); +insert into t values (19, 38); +insert into t values (20, 40); +insert into t values (21, 42); +insert into t values (22, 44); +insert into t values (23, 46); +insert into t values (24, 48); +insert into t values (25, 50); +insert into t values (26, 52); +insert into t values (27, 54); +insert into t values (28, 56); +insert into t values (29, 58); +insert into t values (30, 60); +insert into t values (31, 62); +insert into t values (32, 64); +insert into t values (33, 66); +insert into t values (34, 68); +insert into t values (35, 70); +insert into t values (36, 72); +insert into t values (37, 74); +insert into t values (38, 76); +insert into t values (39, 78); +insert into t values (40, 80); +insert into t values (41, 82); +insert into t values (42, 84); +insert into t values (43, 86); +insert into t values (44, 88); +insert into t values (45, 90); +insert into t values (46, 92); +insert into t values (47, 94); +insert into t values (48, 96); +insert into t values (49, 98); +insert into t values (50, 100); +insert into t values (51, 102); +insert into t values (52, 104); +insert into t values (53, 106); +insert into t values (54, 108); +insert into t values (55, 110); +insert into t values (56, 112); +insert into t values (57, 114); +insert into t values (58, 116); +insert into t values (59, 118); +insert into t values (60, 120); +insert into t values (61, 122); +insert into t values (62, 124); +insert into t values (63, 126); +insert into t values (64, 128); +insert into t values (65, 130); +insert into t values (66, 132); +insert into t values (67, 134); +insert into t values (68, 136); +insert into t values (69, 138); +insert into t values (70, 140); +insert into t values (71, 142); +insert into t values (72, 144); +insert into t values (73, 146); +insert into t values (74, 148); +insert into t values (75, 150); +insert into t values (76, 152); +insert into t values (77, 154); +insert into t values (78, 156); +insert into t values (79, 158); +insert into t values (80, 160); +insert into t values (81, 162); +insert into t values (82, 164); +insert into t values (83, 166); +insert into t values (84, 168); +insert into t values (85, 170); +insert into t values (86, 172); +insert into t values (87, 174); +insert into t values (88, 176); +insert into t values (89, 178); +insert into t values (90, 180); +insert into t values (91, 182); +insert into t values (92, 184); +insert into t values (93, 186); +insert into t values (94, 188); +insert into t values (95, 190); +insert into t values (96, 192); +insert into t values (97, 194); +insert into t values (98, 196); +insert into t values (99, 198); +batch on a limit 10 insert into t1 select * from t; +connect (conn1, localhost, root,, session__nontransactional); +connection conn1; +select count(*) from t; +select count(*) from t1; +(select * from t1 order by a) except (select * from t order by a); +(select * from t order by a) except (select * from t1 order by a); +connection default; +update t1 set b=a; +batch on a limit 10 insert into t1 select * from t on duplicate key update t1.b=t.b; +connection conn1; +select count(*) from t; +select count(*) from t1; +(select * from t1 order by a) except (select * from t order by a); +(select * from t order by a) except (select * from t1 order by a); +connection default; +batch on a limit 10 delete from t; +connection conn1; +select * from t; +disconnect conn1; +set @@tidb_max_chunk_size=default; +set @@sql_select_limit=default; + +# TestNonTransactionalWithInvisibleIndex +set @@tidb_max_chunk_size=35; +drop table if exists t, t1; +create table t(a int, b int); +create table t1(a int, b int); +insert into t values (0, 0); +insert into t values (1, 2); +insert into t values (2, 4); +insert into t values (3, 6); +insert into t values (4, 8); +insert into t values (5, 10); +insert into t values (6, 12); +insert into t values (7, 14); +insert into t values (8, 16); +insert into t values (9, 18); +insert into t values (10, 20); +insert into t values (11, 22); +insert into t values (12, 24); +insert into t values (13, 26); +insert into t values (14, 28); +insert into t values (15, 30); +insert into t values (16, 32); +insert into t values (17, 34); +insert into t values (18, 36); +insert into t values (19, 38); +insert into t values (20, 40); +insert into t values (21, 42); +insert into t values (22, 44); +insert into t values (23, 46); +insert into t values (24, 48); +insert into t values (25, 50); +insert into t values (26, 52); +insert into t values (27, 54); +insert into t values (28, 56); +insert into t values (29, 58); +insert into t values (30, 60); +insert into t values (31, 62); +insert into t values (32, 64); +insert into t values (33, 66); +insert into t values (34, 68); +insert into t values (35, 70); +insert into t values (36, 72); +insert into t values (37, 74); +insert into t values (38, 76); +insert into t values (39, 78); +insert into t values (40, 80); +insert into t values (41, 82); +insert into t values (42, 84); +insert into t values (43, 86); +insert into t values (44, 88); +insert into t values (45, 90); +insert into t values (46, 92); +insert into t values (47, 94); +insert into t values (48, 96); +insert into t values (49, 98); +insert into t values (50, 100); +insert into t values (51, 102); +insert into t values (52, 104); +insert into t values (53, 106); +insert into t values (54, 108); +insert into t values (55, 110); +insert into t values (56, 112); +insert into t values (57, 114); +insert into t values (58, 116); +insert into t values (59, 118); +insert into t values (60, 120); +insert into t values (61, 122); +insert into t values (62, 124); +insert into t values (63, 126); +insert into t values (64, 128); +insert into t values (65, 130); +insert into t values (66, 132); +insert into t values (67, 134); +insert into t values (68, 136); +insert into t values (69, 138); +insert into t values (70, 140); +insert into t values (71, 142); +insert into t values (72, 144); +insert into t values (73, 146); +insert into t values (74, 148); +insert into t values (75, 150); +insert into t values (76, 152); +insert into t values (77, 154); +insert into t values (78, 156); +insert into t values (79, 158); +insert into t values (80, 160); +insert into t values (81, 162); +insert into t values (82, 164); +insert into t values (83, 166); +insert into t values (84, 168); +insert into t values (85, 170); +insert into t values (86, 172); +insert into t values (87, 174); +insert into t values (88, 176); +insert into t values (89, 178); +insert into t values (90, 180); +insert into t values (91, 182); +insert into t values (92, 184); +insert into t values (93, 186); +insert into t values (94, 188); +insert into t values (95, 190); +insert into t values (96, 192); +insert into t values (97, 194); +insert into t values (98, 196); +insert into t values (99, 198); +-- error 1105 +batch on a limit 10 insert into t1 select * from t; +-- error 1105 +batch on a limit 10 insert into t1 select * from t on duplicate key update t1.b=t.b; +-- error 1105 +batch on a limit 10 delete from t; +CREATE UNIQUE INDEX c1 ON t (a) INVISIBLE; +CREATE UNIQUE INDEX c1 ON t1 (a) INVISIBLE; +-- error 1105 +batch on a limit 10 insert into t1 select * from t; +-- error 1105 +batch on a limit 10 insert into t1 select * from t on duplicate key update t1.b=t.b; +-- error 1105 +batch on a limit 10 delete from t; +CREATE UNIQUE INDEX c2 ON t (a); +CREATE UNIQUE INDEX c2 ON t1 (a); +batch on a limit 10 insert into t1 select * from t; +select count(t1.a) = count(t.a) from t, t1; +(select * from t1 order by a) except (select * from t order by a); +(select * from t order by a) except (select * from t1 order by a); +update t1 set b=a; +batch on a limit 10 insert into t1 select * from t on duplicate key update t1.b=t.b; +select count(*) from t; +select count(*) from t1; +(select * from t1 order by a) except (select * from t order by a); +(select * from t order by a) except (select * from t1 order by a); +batch on a limit 10 delete from t; +select count(*) from t; +set @@tidb_max_chunk_size=default; + +# TestNonTransactionalWithAutoDetectShardColumn +set @@tidb_max_chunk_size=35; +drop table if exists t, t1; +create table t(a int, b int); +create table t1(a int, b int); +insert into t values ('0', 0); +insert into t values ('1', 2); +insert into t values ('2', 4); +insert into t values ('3', 6); +insert into t values ('4', 8); +insert into t values ('5', 10); +insert into t values ('6', 12); +insert into t values ('7', 14); +insert into t values ('8', 16); +insert into t values ('9', 18); +batch limit 3 insert into t1 select * from t; +batch limit 3 insert into t1 select * from t on duplicate key update t1.a=t.a, t1.b=t.b; +batch limit 3 delete from t; +drop table if exists t, t1; +create table t(a int, b int, primary key(a) clustered); +create table t1(a int, b int, primary key(a) clustered); +insert into t values ('0', 0); +insert into t values ('1', 2); +insert into t values ('2', 4); +insert into t values ('3', 6); +insert into t values ('4', 8); +insert into t values ('5', 10); +insert into t values ('6', 12); +insert into t values ('7', 14); +insert into t values ('8', 16); +insert into t values ('9', 18); +batch limit 3 insert into t1 select * from t; +batch limit 3 insert into t1 select * from t on duplicate key update t1.a=t.a, t1.b=t.b; +batch limit 3 delete from t; +drop table if exists t, t1; +create table t(a int, b int, primary key(a) nonclustered); +create table t1(a int, b int, primary key(a) nonclustered); +insert into t values ('0', 0); +insert into t values ('1', 2); +insert into t values ('2', 4); +insert into t values ('3', 6); +insert into t values ('4', 8); +insert into t values ('5', 10); +insert into t values ('6', 12); +insert into t values ('7', 14); +insert into t values ('8', 16); +insert into t values ('9', 18); +batch limit 3 insert into t1 select * from t; +batch limit 3 insert into t1 select * from t on duplicate key update t1.a=t.a, t1.b=t.b; +batch limit 3 delete from t; +drop table if exists t, t1; +create table t(a int, b int, primary key(a, b) nonclustered); +create table t1(a int, b int, primary key(a, b) nonclustered); +insert into t values ('0', 0); +insert into t values ('1', 2); +insert into t values ('2', 4); +insert into t values ('3', 6); +insert into t values ('4', 8); +insert into t values ('5', 10); +insert into t values ('6', 12); +insert into t values ('7', 14); +insert into t values ('8', 16); +insert into t values ('9', 18); +batch limit 3 insert into t1 select * from t; +batch limit 3 insert into t1 select * from t on duplicate key update t1.a=t.a, t1.b=t.b; +batch limit 3 delete from t; +drop table if exists t, t1; +create table t(a varchar(30), b int, primary key(a) clustered); +create table t1(a varchar(30), b int, primary key(a) clustered); +insert into t values ('0', 0); +insert into t values ('1', 2); +insert into t values ('2', 4); +insert into t values ('3', 6); +insert into t values ('4', 8); +insert into t values ('5', 10); +insert into t values ('6', 12); +insert into t values ('7', 14); +insert into t values ('8', 16); +insert into t values ('9', 18); +batch limit 3 insert into t1 select * from t; +batch limit 3 insert into t1 select * from t on duplicate key update t1.a=t.a, t1.b=t.b; +batch limit 3 delete from t; +drop table if exists t, t1; +create table t(a varchar(30), b int, primary key(a, b) nonclustered); +create table t1(a varchar(30), b int, primary key(a, b) nonclustered); +insert into t values ('0', 0); +insert into t values ('1', 2); +insert into t values ('2', 4); +insert into t values ('3', 6); +insert into t values ('4', 8); +insert into t values ('5', 10); +insert into t values ('6', 12); +insert into t values ('7', 14); +insert into t values ('8', 16); +insert into t values ('9', 18); +batch limit 3 insert into t1 select * from t; +batch limit 3 insert into t1 select * from t on duplicate key update t1.a=t.a, t1.b=t.b; +batch limit 3 delete from t; +drop table if exists t, t1; +create table t(a int, b int, primary key(a, b) clustered); +create table t1(a int, b int, primary key(a, b) clustered); +insert into t values ('0', 0); +insert into t values ('1', 2); +insert into t values ('2', 4); +insert into t values ('3', 6); +insert into t values ('4', 8); +insert into t values ('5', 10); +insert into t values ('6', 12); +insert into t values ('7', 14); +insert into t values ('8', 16); +insert into t values ('9', 18); +-- error 1105 +batch limit 3 insert into t1 select * from t; +-- error 1105 +batch limit 3 insert into t1 select * from t on duplicate key update t1.a=t.a, t1.b=t.b; +-- error 1105 +batch limit 3 delete from t; +drop table if exists t, t1; +create table t(a varchar(30), b int, primary key(a, b) clustered); +create table t1(a varchar(30), b int, primary key(a, b) clustered); +insert into t values ('0', 0); +insert into t values ('1', 2); +insert into t values ('2', 4); +insert into t values ('3', 6); +insert into t values ('4', 8); +insert into t values ('5', 10); +insert into t values ('6', 12); +insert into t values ('7', 14); +insert into t values ('8', 16); +insert into t values ('9', 18); +-- error 1105 +batch limit 3 insert into t1 select * from t; +-- error 1105 +batch limit 3 insert into t1 select * from t on duplicate key update t1.a=t.a, t1.b=t.b; +-- error 1105 +batch limit 3 delete from t; + +# TestNonTransactionalWithShardOnGeneratedColumn +set @@tidb_max_chunk_size=35; +drop table if exists t, t1; +create table t(a int, b int, c double as (sqrt(a * a + b * b)), key(c)); +create table t1(a int, b int, c double as (sqrt(a * a + b * b)), unique key(c)); +insert into t values (0, 0, default); +insert into t values (1, 2, default); +insert into t values (2, 4, default); +insert into t values (3, 6, default); +insert into t values (4, 8, default); +insert into t values (5, 10, default); +insert into t values (6, 12, default); +insert into t values (7, 14, default); +insert into t values (8, 16, default); +insert into t values (9, 18, default); +insert into t values (10, 20, default); +insert into t values (11, 22, default); +insert into t values (12, 24, default); +insert into t values (13, 26, default); +insert into t values (14, 28, default); +insert into t values (15, 30, default); +insert into t values (16, 32, default); +insert into t values (17, 34, default); +insert into t values (18, 36, default); +insert into t values (19, 38, default); +insert into t values (20, 40, default); +insert into t values (21, 42, default); +insert into t values (22, 44, default); +insert into t values (23, 46, default); +insert into t values (24, 48, default); +insert into t values (25, 50, default); +insert into t values (26, 52, default); +insert into t values (27, 54, default); +insert into t values (28, 56, default); +insert into t values (29, 58, default); +insert into t values (30, 60, default); +insert into t values (31, 62, default); +insert into t values (32, 64, default); +insert into t values (33, 66, default); +insert into t values (34, 68, default); +insert into t values (35, 70, default); +insert into t values (36, 72, default); +insert into t values (37, 74, default); +insert into t values (38, 76, default); +insert into t values (39, 78, default); +insert into t values (40, 80, default); +insert into t values (41, 82, default); +insert into t values (42, 84, default); +insert into t values (43, 86, default); +insert into t values (44, 88, default); +insert into t values (45, 90, default); +insert into t values (46, 92, default); +insert into t values (47, 94, default); +insert into t values (48, 96, default); +insert into t values (49, 98, default); +insert into t values (50, 100, default); +insert into t values (51, 102, default); +insert into t values (52, 104, default); +insert into t values (53, 106, default); +insert into t values (54, 108, default); +insert into t values (55, 110, default); +insert into t values (56, 112, default); +insert into t values (57, 114, default); +insert into t values (58, 116, default); +insert into t values (59, 118, default); +insert into t values (60, 120, default); +insert into t values (61, 122, default); +insert into t values (62, 124, default); +insert into t values (63, 126, default); +insert into t values (64, 128, default); +insert into t values (65, 130, default); +insert into t values (66, 132, default); +insert into t values (67, 134, default); +insert into t values (68, 136, default); +insert into t values (69, 138, default); +insert into t values (70, 140, default); +insert into t values (71, 142, default); +insert into t values (72, 144, default); +insert into t values (73, 146, default); +insert into t values (74, 148, default); +insert into t values (75, 150, default); +insert into t values (76, 152, default); +insert into t values (77, 154, default); +insert into t values (78, 156, default); +insert into t values (79, 158, default); +insert into t values (80, 160, default); +insert into t values (81, 162, default); +insert into t values (82, 164, default); +insert into t values (83, 166, default); +insert into t values (84, 168, default); +insert into t values (85, 170, default); +insert into t values (86, 172, default); +insert into t values (87, 174, default); +insert into t values (88, 176, default); +insert into t values (89, 178, default); +insert into t values (90, 180, default); +insert into t values (91, 182, default); +insert into t values (92, 184, default); +insert into t values (93, 186, default); +insert into t values (94, 188, default); +insert into t values (95, 190, default); +insert into t values (96, 192, default); +insert into t values (97, 194, default); +insert into t values (98, 196, default); +insert into t values (99, 198, default); +batch on c limit 10 insert into t1(a, b) select a, b from t; +select count(*) from t; +select count(*) from t1; +(select * from t1 order by a) except (select * from t order by a); +(select * from t order by a) except (select * from t1 order by a); +update t1 set a=b, b=a; +select count(*) from t; +select count(*) from t1; +(select b, a from t1 order by a) except (select a, b from t order by a); +(select b, a from t order by a) except (select a, b from t1 order by a); +batch on c limit 10 insert into t1(a, b) select a, b from t on duplicate key update t1.a=t.a, t1.b=t.b; +select count(*) from t; +select count(*) from t1; +(select * from t1 order by a) except (select * from t order by a); +(select * from t order by a) except (select * from t1 order by a); +batch on c limit 10 delete from t; +select count(*) from t; +set @@tidb_max_chunk_size=default; + +# TestNonTransactionalWithSmallBatch +set @@tidb_max_chunk_size=1024; +drop table if exists t, t1; +create table t(a int, b int, key(a)); +create table t1(a int, b int, unique key(a)); +insert into t values ('0', 0); +insert into t values (null, null); +insert into t values ('1', 2); +insert into t values (null, null); +insert into t values ('2', 4); +insert into t values (null, null); +insert into t values ('3', 6); +insert into t values (null, null); +insert into t values ('4', 8); +insert into t values (null, null); +insert into t values ('5', 10); +insert into t values (null, null); +insert into t values ('6', 12); +insert into t values (null, null); +insert into t values ('7', 14); +insert into t values (null, null); +insert into t values ('8', 16); +insert into t values (null, null); +insert into t values ('9', 18); +insert into t values (null, null); +batch on a limit 1000 dry run delete from t; +batch on a limit 1000 dry run insert into t1 select * from t; +batch on a limit 1000 dry run insert into t1 select * from t on duplicate key update t1.b=t.b; +batch on a limit 1000 insert into t1 select * from t; +select count(*) from t; +select count(*) from t1; +(select * from t1 order by a) except (select * from t order by a); +(select * from t order by a) except (select * from t1 order by a); +update t1 set b = a; +batch on a limit 1000 insert into t1 select * from t on duplicate key update t1.b=t.b; +select count(*) from t where a is not null; +select count(*) from t1 where a is not null; +(select * from t1 where a is not null order by a) except (select * from t where a is not null order by a); +(select * from t where a is not null order by a) except (select * from t1 where a is not null order by a); +batch on a limit 1000 delete from t; +select count(*) from t; +set @@tidb_max_chunk_size=default; + +# TestNonTransactionalWithNull +set @@tidb_max_chunk_size=35; +drop table if exists t, t1; +create table t(a int, b int, key(a)); +create table t1(a int, b int, key(a)); +insert into t values ('0', 0); +insert into t values (null, null); +insert into t values ('1', 2); +insert into t values (null, null); +insert into t values ('2', 4); +insert into t values (null, null); +insert into t values ('3', 6); +insert into t values (null, null); +insert into t values ('4', 8); +insert into t values (null, null); +insert into t values ('5', 10); +insert into t values (null, null); +insert into t values ('6', 12); +insert into t values (null, null); +insert into t values ('7', 14); +insert into t values (null, null); +insert into t values ('8', 16); +insert into t values (null, null); +insert into t values ('9', 18); +insert into t values (null, null); +insert into t values ('10', 20); +insert into t values (null, null); +insert into t values ('11', 22); +insert into t values (null, null); +insert into t values ('12', 24); +insert into t values (null, null); +insert into t values ('13', 26); +insert into t values (null, null); +insert into t values ('14', 28); +insert into t values (null, null); +insert into t values ('15', 30); +insert into t values (null, null); +insert into t values ('16', 32); +insert into t values (null, null); +insert into t values ('17', 34); +insert into t values (null, null); +insert into t values ('18', 36); +insert into t values (null, null); +insert into t values ('19', 38); +insert into t values (null, null); +insert into t values ('20', 40); +insert into t values (null, null); +insert into t values ('21', 42); +insert into t values (null, null); +insert into t values ('22', 44); +insert into t values (null, null); +insert into t values ('23', 46); +insert into t values (null, null); +insert into t values ('24', 48); +insert into t values (null, null); +insert into t values ('25', 50); +insert into t values (null, null); +insert into t values ('26', 52); +insert into t values (null, null); +insert into t values ('27', 54); +insert into t values (null, null); +insert into t values ('28', 56); +insert into t values (null, null); +insert into t values ('29', 58); +insert into t values (null, null); +insert into t values ('30', 60); +insert into t values (null, null); +insert into t values ('31', 62); +insert into t values (null, null); +insert into t values ('32', 64); +insert into t values (null, null); +insert into t values ('33', 66); +insert into t values (null, null); +insert into t values ('34', 68); +insert into t values (null, null); +insert into t values ('35', 70); +insert into t values (null, null); +insert into t values ('36', 72); +insert into t values (null, null); +insert into t values ('37', 74); +insert into t values (null, null); +insert into t values ('38', 76); +insert into t values (null, null); +insert into t values ('39', 78); +insert into t values (null, null); +insert into t values ('40', 80); +insert into t values (null, null); +insert into t values ('41', 82); +insert into t values (null, null); +insert into t values ('42', 84); +insert into t values (null, null); +insert into t values ('43', 86); +insert into t values (null, null); +insert into t values ('44', 88); +insert into t values (null, null); +insert into t values ('45', 90); +insert into t values (null, null); +insert into t values ('46', 92); +insert into t values (null, null); +insert into t values ('47', 94); +insert into t values (null, null); +insert into t values ('48', 96); +insert into t values (null, null); +insert into t values ('49', 98); +insert into t values (null, null); +insert into t values ('50', 100); +insert into t values (null, null); +insert into t values ('51', 102); +insert into t values (null, null); +insert into t values ('52', 104); +insert into t values (null, null); +insert into t values ('53', 106); +insert into t values (null, null); +insert into t values ('54', 108); +insert into t values (null, null); +insert into t values ('55', 110); +insert into t values (null, null); +insert into t values ('56', 112); +insert into t values (null, null); +insert into t values ('57', 114); +insert into t values (null, null); +insert into t values ('58', 116); +insert into t values (null, null); +insert into t values ('59', 118); +insert into t values (null, null); +insert into t values ('60', 120); +insert into t values (null, null); +insert into t values ('61', 122); +insert into t values (null, null); +insert into t values ('62', 124); +insert into t values (null, null); +insert into t values ('63', 126); +insert into t values (null, null); +insert into t values ('64', 128); +insert into t values (null, null); +insert into t values ('65', 130); +insert into t values (null, null); +insert into t values ('66', 132); +insert into t values (null, null); +insert into t values ('67', 134); +insert into t values (null, null); +insert into t values ('68', 136); +insert into t values (null, null); +insert into t values ('69', 138); +insert into t values (null, null); +insert into t values ('70', 140); +insert into t values (null, null); +insert into t values ('71', 142); +insert into t values (null, null); +insert into t values ('72', 144); +insert into t values (null, null); +insert into t values ('73', 146); +insert into t values (null, null); +insert into t values ('74', 148); +insert into t values (null, null); +insert into t values ('75', 150); +insert into t values (null, null); +insert into t values ('76', 152); +insert into t values (null, null); +insert into t values ('77', 154); +insert into t values (null, null); +insert into t values ('78', 156); +insert into t values (null, null); +insert into t values ('79', 158); +insert into t values (null, null); +insert into t values ('80', 160); +insert into t values (null, null); +insert into t values ('81', 162); +insert into t values (null, null); +insert into t values ('82', 164); +insert into t values (null, null); +insert into t values ('83', 166); +insert into t values (null, null); +insert into t values ('84', 168); +insert into t values (null, null); +insert into t values ('85', 170); +insert into t values (null, null); +insert into t values ('86', 172); +insert into t values (null, null); +insert into t values ('87', 174); +insert into t values (null, null); +insert into t values ('88', 176); +insert into t values (null, null); +insert into t values ('89', 178); +insert into t values (null, null); +insert into t values ('90', 180); +insert into t values (null, null); +insert into t values ('91', 182); +insert into t values (null, null); +insert into t values ('92', 184); +insert into t values (null, null); +insert into t values ('93', 186); +insert into t values (null, null); +insert into t values ('94', 188); +insert into t values (null, null); +insert into t values ('95', 190); +insert into t values (null, null); +insert into t values ('96', 192); +insert into t values (null, null); +insert into t values ('97', 194); +insert into t values (null, null); +insert into t values ('98', 196); +insert into t values (null, null); +insert into t values ('99', 198); +insert into t values (null, null); +batch on a limit 3 delete from t; +select count(*) from t; +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +insert into t values (null, null); +batch on a limit 3 insert into t1 select * from t; +select count(*) from t; +select count(*) from t1; +(select * from t1 order by a) except (select * from t order by a); +(select * from t order by a) except (select * from t1 order by a); +batch on a limit 3 insert into t1 select * from t on duplicate key update t1.b=t.b; +select count(*) from t1; +batch on a limit 3 delete from t; +select count(*) from t; +set @@tidb_max_chunk_size=default; + +# TestNonTransactionalDMLShardingOnTiDBRowID +set @@tidb_max_chunk_size=35; +drop table if exists t, t1; +create table t(a int, b int); +create table t1(a int, b int, unique key(a)); +insert into t values ('0', 0); +insert into t values ('1', 2); +insert into t values ('2', 4); +insert into t values ('3', 6); +insert into t values ('4', 8); +insert into t values ('5', 10); +insert into t values ('6', 12); +insert into t values ('7', 14); +insert into t values ('8', 16); +insert into t values ('9', 18); +insert into t values ('10', 20); +insert into t values ('11', 22); +insert into t values ('12', 24); +insert into t values ('13', 26); +insert into t values ('14', 28); +insert into t values ('15', 30); +insert into t values ('16', 32); +insert into t values ('17', 34); +insert into t values ('18', 36); +insert into t values ('19', 38); +insert into t values ('20', 40); +insert into t values ('21', 42); +insert into t values ('22', 44); +insert into t values ('23', 46); +insert into t values ('24', 48); +insert into t values ('25', 50); +insert into t values ('26', 52); +insert into t values ('27', 54); +insert into t values ('28', 56); +insert into t values ('29', 58); +insert into t values ('30', 60); +insert into t values ('31', 62); +insert into t values ('32', 64); +insert into t values ('33', 66); +insert into t values ('34', 68); +insert into t values ('35', 70); +insert into t values ('36', 72); +insert into t values ('37', 74); +insert into t values ('38', 76); +insert into t values ('39', 78); +insert into t values ('40', 80); +insert into t values ('41', 82); +insert into t values ('42', 84); +insert into t values ('43', 86); +insert into t values ('44', 88); +insert into t values ('45', 90); +insert into t values ('46', 92); +insert into t values ('47', 94); +insert into t values ('48', 96); +insert into t values ('49', 98); +insert into t values ('50', 100); +insert into t values ('51', 102); +insert into t values ('52', 104); +insert into t values ('53', 106); +insert into t values ('54', 108); +insert into t values ('55', 110); +insert into t values ('56', 112); +insert into t values ('57', 114); +insert into t values ('58', 116); +insert into t values ('59', 118); +insert into t values ('60', 120); +insert into t values ('61', 122); +insert into t values ('62', 124); +insert into t values ('63', 126); +insert into t values ('64', 128); +insert into t values ('65', 130); +insert into t values ('66', 132); +insert into t values ('67', 134); +insert into t values ('68', 136); +insert into t values ('69', 138); +insert into t values ('70', 140); +insert into t values ('71', 142); +insert into t values ('72', 144); +insert into t values ('73', 146); +insert into t values ('74', 148); +insert into t values ('75', 150); +insert into t values ('76', 152); +insert into t values ('77', 154); +insert into t values ('78', 156); +insert into t values ('79', 158); +insert into t values ('80', 160); +insert into t values ('81', 162); +insert into t values ('82', 164); +insert into t values ('83', 166); +insert into t values ('84', 168); +insert into t values ('85', 170); +insert into t values ('86', 172); +insert into t values ('87', 174); +insert into t values ('88', 176); +insert into t values ('89', 178); +insert into t values ('90', 180); +insert into t values ('91', 182); +insert into t values ('92', 184); +insert into t values ('93', 186); +insert into t values ('94', 188); +insert into t values ('95', 190); +insert into t values ('96', 192); +insert into t values ('97', 194); +insert into t values ('98', 196); +insert into t values ('99', 198); +batch limit 3 dry run delete from t; +batch limit 3 dry run update t set b = 42; +batch limit 3 dry run insert into t1 select * from t; +batch limit 3 dry run insert into t1 select * from t on duplicate key update t1.b=t.b; +batch on _tidb_rowid limit 3 dry run delete from t; +batch on t._tidb_rowid limit 3 dry run delete from t; +batch on _tidb_rowid limit 3 dry run update t set b = 42; +batch on t._tidb_rowid limit 3 dry run update t set b = 42; +batch on _tidb_rowid limit 3 dry run insert into t1 select * from t; +batch on t._tidb_rowid limit 3 dry run insert into t1 select * from t; +batch on _tidb_rowid limit 3 dry run insert into t1 select * from t on duplicate key update t1.b=t.b; +batch on t._tidb_rowid limit 3 dry run insert into t1 select * from t on duplicate key update t1.b=t.b; +batch on _tidb_rowid limit 3 insert into t1 select * from t; +select count(*) from t; +select count(*) from t1; +(select * from t1 order by a) except (select * from t order by a); +(select * from t order by a) except (select * from t1 order by a); +update t1 set b = 0; +batch on _tidb_rowid limit 3 insert into t1 select * from t on duplicate key update t1.b=t.b; +select count(*) from t; +select count(*) from t1; +(select * from t1 order by a) except (select * from t order by a); +(select * from t order by a) except (select * from t1 order by a); +batch on _tidb_rowid limit 3 update t set b = 42; +select sum(b) from t; +batch on _tidb_rowid limit 3 delete from t; +select count(*) from t; +set @@tidb_max_chunk_size=default; + +# TestNonTransactionalDMLDryRun +set @@tidb_max_chunk_size=35; +drop table if exists t, t1; +create table t(a int, b int, primary key(a, b) clustered); +create table t1(a int, b int, primary key(a, b) clustered); +insert into t values ('0', 0); +insert into t values ('1', 2); +insert into t values ('2', 4); +insert into t values ('3', 6); +insert into t values ('4', 8); +insert into t values ('5', 10); +insert into t values ('6', 12); +insert into t values ('7', 14); +insert into t values ('8', 16); +insert into t values ('9', 18); +insert into t values ('10', 20); +insert into t values ('11', 22); +insert into t values ('12', 24); +insert into t values ('13', 26); +insert into t values ('14', 28); +insert into t values ('15', 30); +insert into t values ('16', 32); +insert into t values ('17', 34); +insert into t values ('18', 36); +insert into t values ('19', 38); +insert into t values ('20', 40); +insert into t values ('21', 42); +insert into t values ('22', 44); +insert into t values ('23', 46); +insert into t values ('24', 48); +insert into t values ('25', 50); +insert into t values ('26', 52); +insert into t values ('27', 54); +insert into t values ('28', 56); +insert into t values ('29', 58); +insert into t values ('30', 60); +insert into t values ('31', 62); +insert into t values ('32', 64); +insert into t values ('33', 66); +insert into t values ('34', 68); +insert into t values ('35', 70); +insert into t values ('36', 72); +insert into t values ('37', 74); +insert into t values ('38', 76); +insert into t values ('39', 78); +insert into t values ('40', 80); +insert into t values ('41', 82); +insert into t values ('42', 84); +insert into t values ('43', 86); +insert into t values ('44', 88); +insert into t values ('45', 90); +insert into t values ('46', 92); +insert into t values ('47', 94); +insert into t values ('48', 96); +insert into t values ('49', 98); +insert into t values ('50', 100); +insert into t values ('51', 102); +insert into t values ('52', 104); +insert into t values ('53', 106); +insert into t values ('54', 108); +insert into t values ('55', 110); +insert into t values ('56', 112); +insert into t values ('57', 114); +insert into t values ('58', 116); +insert into t values ('59', 118); +insert into t values ('60', 120); +insert into t values ('61', 122); +insert into t values ('62', 124); +insert into t values ('63', 126); +insert into t values ('64', 128); +insert into t values ('65', 130); +insert into t values ('66', 132); +insert into t values ('67', 134); +insert into t values ('68', 136); +insert into t values ('69', 138); +insert into t values ('70', 140); +insert into t values ('71', 142); +insert into t values ('72', 144); +insert into t values ('73', 146); +insert into t values ('74', 148); +insert into t values ('75', 150); +insert into t values ('76', 152); +insert into t values ('77', 154); +insert into t values ('78', 156); +insert into t values ('79', 158); +insert into t values ('80', 160); +insert into t values ('81', 162); +insert into t values ('82', 164); +insert into t values ('83', 166); +insert into t values ('84', 168); +insert into t values ('85', 170); +insert into t values ('86', 172); +insert into t values ('87', 174); +insert into t values ('88', 176); +insert into t values ('89', 178); +insert into t values ('90', 180); +insert into t values ('91', 182); +insert into t values ('92', 184); +insert into t values ('93', 186); +insert into t values ('94', 188); +insert into t values ('95', 190); +insert into t values ('96', 192); +insert into t values ('97', 194); +insert into t values ('98', 196); +insert into t values ('99', 198); +batch on a limit 3 dry run insert into t1 select * from t; +batch on a limit 3 dry run insert into t1 select * from t on duplicate key update t1.b=t.b; +batch on a limit 3 dry run delete from t; +batch on a limit 3 dry run update t set b = b + 42; +batch on a limit 3 dry run query insert into t1 select * from t; +batch on a limit 3 dry run query insert into t1 select * from t on duplicate key update t1.b=t.b; +batch on a limit 3 dry run query delete from t; +batch on a limit 3 dry run query update t set b = b + 42; +select count(*) from t; +select sum(b) from t; +set @@tidb_max_chunk_size=default; +