From 958144274716dd41219dd94dbadef5310945253f Mon Sep 17 00:00:00 2001 From: Henry Baba-Weiss Date: Fri, 17 May 2024 01:17:44 -0700 Subject: [PATCH] tests: move `TestNoopFunctions` to `tests/integrationtest` (#53343) ref pingcap/tidb#45961 --- pkg/expression/integration_test/BUILD.bazel | 2 +- .../integration_test/integration_test.go | 66 ---------------- .../r/expression/noop_functions.result | 79 +++++++++++++++++++ .../t/expression/noop_functions.test | 74 +++++++++++++++++ 4 files changed, 154 insertions(+), 67 deletions(-) diff --git a/pkg/expression/integration_test/BUILD.bazel b/pkg/expression/integration_test/BUILD.bazel index 8d15c35a41453..1e47b89a78cbc 100644 --- a/pkg/expression/integration_test/BUILD.bazel +++ b/pkg/expression/integration_test/BUILD.bazel @@ -8,7 +8,7 @@ go_test( "main_test.go", ], flaky = True, - shard_count = 27, + shard_count = 26, deps = [ "//pkg/config", "//pkg/domain", diff --git a/pkg/expression/integration_test/integration_test.go b/pkg/expression/integration_test/integration_test.go index e109be83acc50..f8ef22f18a856 100644 --- a/pkg/expression/integration_test/integration_test.go +++ b/pkg/expression/integration_test/integration_test.go @@ -2771,72 +2771,6 @@ func TestIssue16205(t *testing.T) { 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) diff --git a/tests/integrationtest/r/expression/noop_functions.result b/tests/integrationtest/r/expression/noop_functions.result index 1a3266f638cf1..6c57a4a526aba 100644 --- a/tests/integrationtest/r/expression/noop_functions.result +++ b/tests/integrationtest/r/expression/noop_functions.result @@ -14,6 +14,16 @@ a SELECT * FROM t1 WHERE a=1 LOCK IN SHARE MODE; a 1 +SELECT * FROM t1 GROUP BY a DESC; +a +1 +2 +3 +SELECT * FROM t1 GROUP BY a ASC; +a +1 +2 +3 SET @@tidb_enable_noop_functions='WARN'; SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1; a @@ -32,6 +42,20 @@ a 1 Level Code Message Warning 1235 function LOCK IN SHARE MODE has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions +SELECT * FROM t1 GROUP BY a DESC; +a +1 +2 +3 +Level Code Message +Warning 1235 function GROUP BY expr ASC|DESC has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions +SELECT * FROM t1 GROUP BY a ASC; +a +1 +2 +3 +Level Code Message +Warning 1235 function GROUP BY expr ASC|DESC has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions SET @@tidb_enable_noop_functions='OFF'; SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1; Error 1235 (42000): function SQL_CALC_FOUND_ROWS has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions @@ -39,3 +63,58 @@ SELECT * FROM t1 LOCK IN SHARE MODE; Error 1235 (42000): function LOCK IN SHARE MODE has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions SELECT * FROM t1 WHERE a=1 LOCK IN SHARE MODE; Error 1235 (42000): function LOCK IN SHARE MODE has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions +SELECT * FROM t1 GROUP BY a DESC; +Error 1235 (42000): function GROUP BY expr ASC|DESC has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions +SELECT * FROM t1 GROUP BY a ASC; +Error 1235 (42000): function GROUP BY expr ASC|DESC has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions +SET @@tidb_enable_noop_functions='ON'; +START TRANSACTION READ ONLY; +SET tx_read_only = 0; +SET transaction_read_only = 0; +SET TRANSACTION READ ONLY; +SET tx_read_only = 0; +SET transaction_read_only = 0; +SET tx_read_only = 1; +SET tx_read_only = 0; +SET transaction_read_only = 0; +SET transaction_read_only = 1; +SET tx_read_only = 0; +SET transaction_read_only = 0; +SET @@tidb_enable_noop_functions='WARN'; +START TRANSACTION READ ONLY; +Level Code Message +Warning 1235 function READ ONLY has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions +SET tx_read_only = 0; +SET transaction_read_only = 0; +SET TRANSACTION READ ONLY; +Level Code Message +Warning 1235 function READ ONLY has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions +SET tx_read_only = 0; +SET transaction_read_only = 0; +SET tx_read_only = 1; +Level Code Message +Warning 1235 function READ ONLY has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions +SET tx_read_only = 0; +SET transaction_read_only = 0; +SET transaction_read_only = 1; +Level Code Message +Warning 1235 function READ ONLY has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions +SET tx_read_only = 0; +SET transaction_read_only = 0; +SET @@tidb_enable_noop_functions='OFF'; +START TRANSACTION READ ONLY; +Error 1235 (42000): function READ ONLY has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions +SET tx_read_only = 0; +SET transaction_read_only = 0; +SET TRANSACTION READ ONLY; +Error 1235 (42000): function READ ONLY has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions +SET tx_read_only = 0; +SET transaction_read_only = 0; +SET tx_read_only = 1; +Error 1235 (42000): function READ ONLY has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions +SET tx_read_only = 0; +SET transaction_read_only = 0; +SET transaction_read_only = 1; +Error 1235 (42000): function READ ONLY has only noop implementation in tidb now, use tidb_enable_noop_functions to enable these functions +SET tx_read_only = 0; +SET transaction_read_only = 0; diff --git a/tests/integrationtest/t/expression/noop_functions.test b/tests/integrationtest/t/expression/noop_functions.test index d0e588a7e14fc..bb32a10a5c049 100644 --- a/tests/integrationtest/t/expression/noop_functions.test +++ b/tests/integrationtest/t/expression/noop_functions.test @@ -1,3 +1,6 @@ +# TestNoopFunctions +# issues 14448, 19383, 17734, 52432 + # variable changes in the test will not affect the plan cache set tidb_enable_non_prepared_plan_cache=0; DROP TABLE IF EXISTS t1; @@ -9,12 +12,16 @@ SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1; SELECT * FROM t1 LOCK IN SHARE MODE; # test the fast path for point-get queries SELECT * FROM t1 WHERE a=1 LOCK IN SHARE MODE; +SELECT * FROM t1 GROUP BY a DESC; +SELECT * FROM t1 GROUP BY a ASC; SET @@tidb_enable_noop_functions='WARN'; --enable_warnings SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1; SELECT * FROM t1 LOCK IN SHARE MODE; SELECT * FROM t1 WHERE a=1 LOCK IN SHARE MODE; +SELECT * FROM t1 GROUP BY a DESC; +SELECT * FROM t1 GROUP BY a ASC; --disable_warnings SET @@tidb_enable_noop_functions='OFF'; @@ -24,3 +31,70 @@ SELECT SQL_CALC_FOUND_ROWS * FROM t1 LIMIT 1; SELECT * FROM t1 LOCK IN SHARE MODE; --error 1235 SELECT * FROM t1 WHERE a=1 LOCK IN SHARE MODE; +--error 1235 +SELECT * FROM t1 GROUP BY a DESC; +--error 1235 +SELECT * FROM t1 GROUP BY a ASC; + +# After each of these statements execute, we need to reset the values +# because otherwise tidb_enable_noop_functions can't be changed. + +SET @@tidb_enable_noop_functions='ON'; + +START TRANSACTION READ ONLY; +SET tx_read_only = 0; +SET transaction_read_only = 0; + +SET TRANSACTION READ ONLY; +SET tx_read_only = 0; +SET transaction_read_only = 0; + +SET tx_read_only = 1; +SET tx_read_only = 0; +SET transaction_read_only = 0; + +SET transaction_read_only = 1; +SET tx_read_only = 0; +SET transaction_read_only = 0; + +SET @@tidb_enable_noop_functions='WARN'; + +--enable_warnings +START TRANSACTION READ ONLY; +SET tx_read_only = 0; +SET transaction_read_only = 0; + +SET TRANSACTION READ ONLY; +SET tx_read_only = 0; +SET transaction_read_only = 0; + +SET tx_read_only = 1; +SET tx_read_only = 0; +SET transaction_read_only = 0; + +SET transaction_read_only = 1; +SET tx_read_only = 0; +SET transaction_read_only = 0; +--disable_warnings + +SET @@tidb_enable_noop_functions='OFF'; + +--error 1235 +START TRANSACTION READ ONLY; +SET tx_read_only = 0; +SET transaction_read_only = 0; + +--error 1235 +SET TRANSACTION READ ONLY; +SET tx_read_only = 0; +SET transaction_read_only = 0; + +--error 1235 +SET tx_read_only = 1; +SET tx_read_only = 0; +SET transaction_read_only = 0; + +--error 1235 +SET transaction_read_only = 1; +SET tx_read_only = 0; +SET transaction_read_only = 0;