From 2165ca5bd993ce3d242624f2539f7fad415a174f Mon Sep 17 00:00:00 2001 From: Hangjie Mo Date: Mon, 6 Nov 2023 09:42:40 +0800 Subject: [PATCH] tests: move IT in `executor` to `tests/integrationtest` (PART 10) (#48263) ref pingcap/tidb#47076 --- pkg/executor/set_test.go | 482 ------------ pkg/executor/test/ddl/BUILD.bazel | 5 +- pkg/executor/test/ddl/ddl_test.go | 357 --------- pkg/executor/test/issuetest/BUILD.bazel | 2 +- .../test/issuetest/executor_issue_test.go | 82 --- pkg/executor/test/jointest/BUILD.bazel | 2 +- pkg/executor/test/jointest/join_test.go | 546 -------------- pkg/executor/test/writetest/BUILD.bazel | 2 +- pkg/executor/test/writetest/write_test.go | 69 -- tests/integrationtest/r/executor/ddl.result | 292 ++++++++ .../integrationtest/r/executor/issues.result | 75 ++ .../r/executor/jointest/join.result | 683 ++++++++++++++++++ tests/integrationtest/r/executor/set.result | 446 ++++++++++++ tests/integrationtest/r/executor/write.result | 95 +++ tests/integrationtest/t/executor/ddl.test | 296 ++++++++ tests/integrationtest/t/executor/issues.test | 64 ++ .../t/executor/jointest/join.test | 470 ++++++++++++ tests/integrationtest/t/executor/set.test | 279 +++++++ tests/integrationtest/t/executor/write.test | 69 ++ 19 files changed, 2773 insertions(+), 1543 deletions(-) diff --git a/pkg/executor/set_test.go b/pkg/executor/set_test.go index 8850d53eeea74..2cab2decee195 100644 --- a/pkg/executor/set_test.go +++ b/pkg/executor/set_test.go @@ -904,172 +904,6 @@ func TestSetVar(t *testing.T) { tk.MustQuery("select @@global.tidb_schema_version_cache_limit").Check(testkit.Rows("64")) } -func TestGetSetNoopVars(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - // By default you can get/set noop sysvars without issue. - tk.MustQuery("SELECT @@query_cache_type").Check(testkit.Rows("OFF")) - tk.MustQuery("SHOW VARIABLES LIKE 'query_cache_type'").Check(testkit.Rows("query_cache_type OFF")) - tk.MustExec("SET query_cache_type=2") - tk.MustQuery("SELECT @@query_cache_type").Check(testkit.Rows("DEMAND")) - // When tidb_enable_noop_variables is OFF, you can GET in @@ context - // and always SET. But you can't see in SHOW VARIABLES. - // Warnings are also returned. - tk.MustExec("SET GLOBAL tidb_enable_noop_variables = OFF") - defer tk.MustExec("SET GLOBAL tidb_enable_noop_variables = ON") - tk.MustQuery("SELECT @@global.tidb_enable_noop_variables").Check(testkit.Rows("OFF")) - tk.MustQuery("SELECT @@query_cache_type").Check(testkit.Rows("DEMAND")) - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 8145 variable query_cache_type has no effect in TiDB")) - tk.MustQuery("SHOW VARIABLES LIKE 'query_cache_type'").Check(testkit.Rows()) - tk.MustExec("SET query_cache_type = OFF") - tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 8144 setting query_cache_type has no effect in TiDB")) - // but the change is still effective. - tk.MustQuery("SELECT @@query_cache_type").Check(testkit.Rows("OFF")) - - // Only ON and OFF supported - err := tk.ExecToErr("SET GLOBAL tidb_enable_noop_variables = 2") - require.Error(t, err) - require.Equal(t, "[variable:1231]Variable 'tidb_enable_noop_variables' can't be set to the value of '2'", err.Error()) - - err = tk.ExecToErr("SET GLOBAL tidb_enable_noop_variables = 'warn'") - require.Error(t, err) - require.Equal(t, "[variable:1231]Variable 'tidb_enable_noop_variables' can't be set to the value of 'warn'", err.Error()) -} - -func TestTruncateIncorrectIntSessionVar(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - testCases := []struct { - sessionVarName string - minValue int - maxValue int - }{ - {"auto_increment_increment", 1, 65535}, - {"auto_increment_offset", 1, 65535}, - } - - for _, tc := range testCases { - name := tc.sessionVarName - selectSQL := fmt.Sprintf("select @@%s;", name) - validValue := tc.minValue + (tc.maxValue-tc.minValue)/2 - tk.MustExec(fmt.Sprintf("set @@%s = %d", name, validValue)) - tk.MustQuery(selectSQL).Check(testkit.Rows(fmt.Sprintf("%d", validValue))) - - tk.MustExec(fmt.Sprintf("set @@%s = %d", name, tc.minValue-1)) - warnMsg := fmt.Sprintf("Warning 1292 Truncated incorrect %s value: '%d'", name, tc.minValue-1) - tk.MustQuery("show warnings").Check(testkit.Rows(warnMsg)) - tk.MustQuery(selectSQL).Check(testkit.Rows(fmt.Sprintf("%d", tc.minValue))) - - tk.MustExec(fmt.Sprintf("set @@%s = %d", name, tc.maxValue+1)) - warnMsg = fmt.Sprintf("Warning 1292 Truncated incorrect %s value: '%d'", name, tc.maxValue+1) - tk.MustQuery("show warnings").Check(testkit.Rows(warnMsg)) - tk.MustQuery(selectSQL).Check(testkit.Rows(fmt.Sprintf("%d", tc.maxValue))) - } -} - -func TestSetCharset(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - sessionVars := tk.Session().GetSessionVars() - - var characterSetVariables = []string{ - "character_set_client", - "character_set_connection", - "character_set_results", - "character_set_server", - "character_set_database", - "character_set_system", - "character_set_filesystem", - } - - check := func(args ...string) { - for i, v := range characterSetVariables { - sVar, err := sessionVars.GetSessionOrGlobalSystemVar(context.Background(), v) - require.NoError(t, err) - require.Equal(t, args[i], sVar, fmt.Sprintf("%d: %s", i, characterSetVariables[i])) - } - } - - check( - "utf8mb4", - "utf8mb4", - "utf8mb4", - "utf8mb4", - "utf8mb4", - "utf8", - "binary", - ) - - tk.MustExec(`SET NAMES latin1`) - check( - "latin1", - "latin1", - "latin1", - "utf8mb4", - "utf8mb4", - "utf8", - "binary", - ) - - tk.MustExec(`SET NAMES default`) - check( - "utf8mb4", - "utf8mb4", - "utf8mb4", - "utf8mb4", - "utf8mb4", - "utf8", - "binary", - ) - - // Issue #1523 - tk.MustExec(`SET NAMES binary`) - check( - "binary", - "binary", - "binary", - "utf8mb4", - "utf8mb4", - "utf8", - "binary", - ) - - tk.MustExec(`SET NAMES utf8`) - check( - "utf8", - "utf8", - "utf8", - "utf8mb4", - "utf8mb4", - "utf8", - "binary", - ) - - tk.MustExec(`SET CHARACTER SET latin1`) - check( - "latin1", - "utf8mb4", - "latin1", - "utf8mb4", - "utf8mb4", - "utf8", - "binary", - ) - - tk.MustExec(`SET CHARACTER SET default`) - check( - "utf8mb4", - "utf8mb4", - "utf8mb4", - "utf8mb4", - "utf8mb4", - "utf8", - "binary", - ) -} - func TestSetCollationAndCharset(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -1498,27 +1332,6 @@ func TestValidateSetVar(t *testing.T) { tk.MustQuery("select @@global.allow_auto_random_explicit_insert;").Check(testkit.Rows("1")) } -func TestSelectGlobalVar(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustQuery("select @@global.max_connections;").Check(testkit.Rows("0")) - tk.MustQuery("select @@max_connections;").Check(testkit.Rows("0")) - - tk.MustExec("set @@global.max_connections=100;") - - tk.MustQuery("select @@global.max_connections;").Check(testkit.Rows("100")) - tk.MustQuery("select @@max_connections;").Check(testkit.Rows("100")) - - tk.MustExec("set @@global.max_connections=0;") - - // test for unknown variable. - err := tk.ExecToErr("select @@invalid") - require.True(t, terror.ErrorEqual(err, variable.ErrUnknownSystemVar), fmt.Sprintf("err %v", err)) - err = tk.ExecToErr("select @@global.invalid") - require.True(t, terror.ErrorEqual(err, variable.ErrUnknownSystemVar), fmt.Sprintf("err %v", err)) -} - func TestSetConcurrency(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -1723,72 +1536,6 @@ func TestEnableNoopFunctionsVar(t *testing.T) { require.Error(t, tk.ExecToErr("set global read_only = abc")) } -// https://github.com/pingcap/tidb/issues/29670 -func TestDefaultBehavior(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustQuery("SELECT @@default_storage_engine").Check(testkit.Rows("InnoDB")) - tk.MustExec("SET GLOBAL default_storage_engine = 'somethingweird'") - tk.MustExec("SET default_storage_engine = 'MyISAM'") - tk.MustQuery("SELECT @@default_storage_engine").Check(testkit.Rows("MyISAM")) - tk.MustExec("SET default_storage_engine = DEFAULT") // reads from global value - tk.MustQuery("SELECT @@default_storage_engine").Check(testkit.Rows("somethingweird")) - tk.MustExec("SET @@SESSION.default_storage_engine = @@GLOBAL.default_storage_engine") // example from MySQL manual - tk.MustQuery("SELECT @@default_storage_engine").Check(testkit.Rows("somethingweird")) - tk.MustExec("SET GLOBAL default_storage_engine = 'somethingweird2'") - tk.MustExec("SET default_storage_engine = @@GLOBAL.default_storage_engine") // variation of example - tk.MustQuery("SELECT @@default_storage_engine").Check(testkit.Rows("somethingweird2")) - tk.MustExec("SET default_storage_engine = DEFAULT") // restore default again for session global - tk.MustExec("SET GLOBAL default_storage_engine = DEFAULT") // restore default for global - tk.MustQuery("SELECT @@SESSION.default_storage_engine, @@GLOBAL.default_storage_engine").Check(testkit.Rows("somethingweird2 InnoDB")) - - // Try sql_mode option which has validation - err := tk.ExecToErr("SET GLOBAL sql_mode = 'DEFAULT'") // illegal now - require.EqualError(t, err, `ERROR 1231 (42000): Variable 'sql_mode' can't be set to the value of 'DEFAULT'`) - tk.MustExec("SET GLOBAL sql_mode = DEFAULT") -} - -func TestTiDBReadOnly(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - // turn on tidb_restricted_read_only should turn on tidb_super_read_only - tk.MustExec("SET GLOBAL tidb_restricted_read_only = ON") - tk.MustQuery("SELECT @@GLOBAL.tidb_super_read_only").Check(testkit.Rows("1")) - - // can't turn off tidb_super_read_only if tidb_restricted_read_only is on - err := tk.ExecToErr("SET GLOBAL tidb_super_read_only = OFF") - require.Error(t, err) - require.Equal(t, "can't turn off tidb_super_read_only when tidb_restricted_read_only is on", err.Error()) - - // turn off tidb_restricted_read_only won't affect tidb_super_read_only - tk.MustExec("SET GLOBAL tidb_restricted_read_only = OFF") - tk.MustQuery("SELECT @@GLOBAL.tidb_restricted_read_only").Check(testkit.Rows("0")) - tk.MustQuery("SELECT @@GLOBAL.tidb_super_read_only").Check(testkit.Rows("1")) - - // it is ok to turn off tidb_super_read_only now - tk.MustExec("SET GLOBAL tidb_super_read_only = OFF") - tk.MustQuery("SELECT @@GLOBAL.tidb_super_read_only").Check(testkit.Rows("0")) -} - -func TestRemovedSysVars(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - // test for tidb_enable_noop_functions - // In SET context, it just noops: - tk.MustExec(`SET tidb_enable_global_temporary_table = 1`) - tk.MustExec(`SET tidb_slow_log_masking = 1`) - tk.MustExec(`SET GLOBAL tidb_enable_global_temporary_table = 1`) - tk.MustExec(`SET GLOBAL tidb_slow_log_masking = 1`) - - // In SELECT context it returns a specifc error - // (to avoid presenting dummy data) - tk.MustGetErrCode("SELECT @@tidb_slow_log_masking", errno.ErrVariableNoLongerSupported) - tk.MustGetErrCode("SELECT @@tidb_enable_global_temporary_table", errno.ErrVariableNoLongerSupported) -} - func TestSetClusterConfig(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -1940,232 +1687,3 @@ func TestSetTopSQLVariables(t *testing.T) { tk.MustQuery("show variables like '%top_sql%'").Check(testkit.Rows("tidb_enable_top_sql OFF", "tidb_top_sql_max_meta_count 5000", "tidb_top_sql_max_time_series_count 20")) tk.MustQuery("show global variables like '%top_sql%'").Check(testkit.Rows("tidb_enable_top_sql OFF", "tidb_top_sql_max_meta_count 5000", "tidb_top_sql_max_time_series_count 20")) } - -func TestPreparePlanCacheValid(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - // global scope - tk.MustQuery("select @@global.tidb_session_plan_cache_size").Check(testkit.Rows("100")) // default value - tk.MustExec("SET GLOBAL tidb_session_plan_cache_size = 0") - tk.MustQuery("show warnings").Check(testkit.Rows( - "Warning 1292 Truncated incorrect tidb_session_plan_cache_size value: '0'")) - tk.MustQuery("select @@global.tidb_session_plan_cache_size").Check(testkit.Rows("1")) - tk.MustExec("SET GLOBAL tidb_session_plan_cache_size = 2") - tk.MustQuery("select @@global.tidb_session_plan_cache_size").Check(testkit.Rows("2")) - // session scope - tk.MustQuery("select @@session.tidb_session_plan_cache_size").Check(testkit.Rows("100")) // default value - tk.MustExec("SET SESSION tidb_session_plan_cache_size = 0") - tk.MustQuery("show warnings").Check(testkit.Rows( - "Warning 1292 Truncated incorrect tidb_session_plan_cache_size value: '0'")) - tk.MustQuery("select @@session.tidb_session_plan_cache_size").Check(testkit.Rows("1")) - tk.MustExec("SET SESSION tidb_session_plan_cache_size = 2") - tk.MustQuery("select @@session.tidb_session_plan_cache_size").Check(testkit.Rows("2")) - - tk.MustExec("SET GLOBAL tidb_prepared_plan_cache_memory_guard_ratio = -0.1") - tk.MustQuery("show warnings").Check(testkit.Rows( - "Warning 1292 Truncated incorrect tidb_prepared_plan_cache_memory_guard_ratio value: '-0.1'")) - tk.MustQuery("select @@global.tidb_prepared_plan_cache_memory_guard_ratio").Check(testkit.Rows("0")) - tk.MustExec("SET GLOBAL tidb_prepared_plan_cache_memory_guard_ratio = 2.2") - tk.MustQuery("show warnings").Check(testkit.Rows( - "Warning 1292 Truncated incorrect tidb_prepared_plan_cache_memory_guard_ratio value: '2.2'")) - tk.MustQuery("select @@global.tidb_prepared_plan_cache_memory_guard_ratio").Check(testkit.Rows("1")) - tk.MustExec("SET GLOBAL tidb_prepared_plan_cache_memory_guard_ratio = 0.5") - tk.MustQuery("select @@global.tidb_prepared_plan_cache_memory_guard_ratio").Check(testkit.Rows("0.5")) - - tk.MustExec("SET GLOBAL tidb_enable_prepared_plan_cache = 0") - tk.MustQuery("select @@global.tidb_enable_prepared_plan_cache").Check(testkit.Rows("0")) - tk.MustExec("SET GLOBAL tidb_enable_prepared_plan_cache = 1") - tk.MustQuery("select @@global.tidb_enable_prepared_plan_cache").Check(testkit.Rows("1")) - tk.MustExec("SET GLOBAL tidb_enable_prepared_plan_cache = 0") - tk.MustQuery("select @@global.tidb_enable_prepared_plan_cache").Check(testkit.Rows("0")) -} - -func TestInstanceScopeSwitching(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - // enable 'switching' to SESSION variables - tk.MustExec("set tidb_enable_legacy_instance_scope = 1") - tk.MustExec("set tidb_general_log = 1") - tk.MustQuery(`show warnings`).Check(testkit.Rows(fmt.Sprintf("Warning %d modifying tidb_general_log will require SET GLOBAL in a future version of TiDB", errno.ErrInstanceScope))) - - // disable 'switching' to SESSION variables - tk.MustExec("set tidb_enable_legacy_instance_scope = 0") - tk.MustGetErrCode("set tidb_general_log = 1", errno.ErrGlobalVariable) -} - -func TestGcMaxWaitTime(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - tk.MustExec("set global tidb_gc_max_wait_time = 1000") - tk.MustExec("set global tidb_gc_life_time = \"72h\"") - tk.MustExec("set global tidb_gc_life_time = \"24h\"") - tk.MustExec("set global tidb_gc_life_time = \"10m\"") - - tk.MustExec("set global tidb_gc_max_wait_time = 86400") - tk.MustExec("set global tidb_gc_life_time = \"72h\"") - tk.MustExec("set global tidb_gc_max_wait_time = 1000") -} - -func TestTiFlashFineGrainedShuffle(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - // Default is 0. - tk.MustQuery("select @@tiflash_fine_grained_shuffle_stream_count;").Check(testkit.Rows("0")) - - tk.MustExec("set @@tiflash_fine_grained_shuffle_stream_count = 0") - tk.MustQuery("select @@tiflash_fine_grained_shuffle_stream_count;").Check(testkit.Rows("0")) - // Min val is -1. - tk.MustExec("set @@tiflash_fine_grained_shuffle_stream_count = -2") - tk.MustQuery("select @@tiflash_fine_grained_shuffle_stream_count;").Check(testkit.Rows("-1")) - - tk.MustExec("set @@tiflash_fine_grained_shuffle_stream_count = 0") - tk.MustQuery("select @@tiflash_fine_grained_shuffle_stream_count;").Check(testkit.Rows("0")) - - tk.MustExec("set @@tiflash_fine_grained_shuffle_stream_count = 1024") - tk.MustQuery("select @@tiflash_fine_grained_shuffle_stream_count;").Check(testkit.Rows("1024")) - // Max val is 1024. - tk.MustExec("set @@tiflash_fine_grained_shuffle_stream_count = 1025") - tk.MustQuery("select @@tiflash_fine_grained_shuffle_stream_count;").Check(testkit.Rows("1024")) - - // Default is 8192. - tk.MustQuery("select @@tiflash_fine_grained_shuffle_batch_size;").Check(testkit.Rows("8192")) - - // Min is 1. - tk.MustExec("set @@tiflash_fine_grained_shuffle_batch_size = 0") - tk.MustQuery("select @@tiflash_fine_grained_shuffle_batch_size;").Check(testkit.Rows("1")) - tk.MustExec("set @@tiflash_fine_grained_shuffle_batch_size = -1") - tk.MustQuery("select @@tiflash_fine_grained_shuffle_batch_size;").Check(testkit.Rows("1")) - - // Max is uint64_max. - tk.MustExec("set @@tiflash_fine_grained_shuffle_batch_size = 18446744073709551615") - tk.MustQuery("select @@tiflash_fine_grained_shuffle_batch_size;").Check(testkit.Rows("18446744073709551615")) - - // Test set global. - tk.MustExec("set global tiflash_fine_grained_shuffle_stream_count = -1") - tk.MustExec("set global tiflash_fine_grained_shuffle_batch_size = 8192") -} - -func TestSetTiFlashFastScanVariable(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int);") - tk.MustExec("insert into t values(1);") - - // check the default tiflash read mode - tk.MustQuery("select @@session.tiflash_fastscan").Check(testkit.Rows("0")) - tk.MustQuery("select @@global.tiflash_fastscan").Check(testkit.Rows("0")) - - tk.MustExec("set @@tiflash_fastscan=ON;") - tk.MustQuery("select @@session.tiflash_fastscan").Check(testkit.Rows("1")) - - tk.MustExec("set GLOBAL tiflash_fastscan=OFF;") - tk.MustQuery("select @@global.tiflash_fastscan").Check(testkit.Rows("0")) -} - -func TestSetPlanCacheMemoryMonitor(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - tk.MustQuery("select @@session.tidb_enable_prepared_plan_cache_memory_monitor").Check(testkit.Rows("1")) - tk.MustQuery("select @@global.tidb_enable_prepared_plan_cache_memory_monitor").Check(testkit.Rows("1")) - - tk.MustExec("set @@session.tidb_enable_prepared_plan_cache_memory_monitor=OFF;") - tk.MustQuery("select @@session.tidb_enable_prepared_plan_cache_memory_monitor").Check(testkit.Rows("0")) - - tk.MustExec("set @@session.tidb_enable_prepared_plan_cache_memory_monitor=1;") - tk.MustQuery("select @@session.tidb_enable_prepared_plan_cache_memory_monitor").Check(testkit.Rows("1")) - - tk.MustExec("set @@global.tidb_enable_prepared_plan_cache_memory_monitor=off;") - tk.MustQuery("select @@global.tidb_enable_prepared_plan_cache_memory_monitor").Check(testkit.Rows("0")) -} - -func TestSetChunkReuseVariable(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("set @@tidb_enable_reuse_chunk=ON;") - tk.MustQuery("select @@session.tidb_enable_reuse_chunk").Check(testkit.Rows("1")) - tk.MustExec("set GLOBAL tidb_enable_reuse_chunk=ON;") - tk.MustQuery("select @@global.tidb_enable_reuse_chunk").Check(testkit.Rows("1")) - - tk.MustExec("set @@tidb_enable_reuse_chunk=OFF;") - tk.MustQuery("select @@session.tidb_enable_reuse_chunk").Check(testkit.Rows("0")) - tk.MustExec("set GLOBAL tidb_enable_reuse_chunk=OFF;") - tk.MustQuery("select @@global.tidb_enable_reuse_chunk").Check(testkit.Rows("0")) - - // error value - tk.MustGetErrCode("set @@tidb_enable_reuse_chunk=s;", errno.ErrWrongValueForVar) -} - -func TestSetMppVersionVariable(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustQuery("select @@session.mpp_version").Check(testkit.Rows("UNSPECIFIED")) - tk.MustExec("SET SESSION mpp_version = -1") - tk.MustQuery("select @@session.mpp_version").Check(testkit.Rows("-1")) - tk.MustExec("SET SESSION mpp_version = 0") - tk.MustQuery("select @@session.mpp_version").Check(testkit.Rows("0")) - tk.MustExec("SET SESSION mpp_version = 1") - tk.MustQuery("select @@session.mpp_version").Check(testkit.Rows("1")) - tk.MustExec("SET SESSION mpp_version = 2") - tk.MustQuery("select @@session.mpp_version").Check(testkit.Rows("2")) - tk.MustExec("SET SESSION mpp_version = unspecified") - tk.MustQuery("select @@session.mpp_version").Check(testkit.Rows("unspecified")) - { - tk.MustGetErrMsg("SET SESSION mpp_version = 3", "incorrect value: 3. mpp_version options: -1 (unspecified), 0, 1, 2") - } - { - tk.MustExec("SET GLOBAL mpp_version = 1") - tk.MustQuery("select @@global.mpp_version").Check(testkit.Rows("1")) - tk.MustExec("SET GLOBAL mpp_version = -1") - tk.MustQuery("select @@global.mpp_version").Check(testkit.Rows("-1")) - } -} - -func TestSetMppExchangeCompressionModeVariable(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustGetErrMsg( - "SET SESSION mpp_exchange_compression_mode = 123", - "incorrect value: `123`. mpp_exchange_compression_mode options: NONE, FAST, HIGH_COMPRESSION, UNSPECIFIED") - tk.MustQuery("select @@session.mpp_exchange_compression_mode").Check(testkit.Rows("UNSPECIFIED")) - - tk.MustExec("SET SESSION mpp_exchange_compression_mode = none") - tk.MustQuery("select @@session.mpp_exchange_compression_mode").Check(testkit.Rows("none")) - tk.MustExec("SET SESSION mpp_exchange_compression_mode = fast") - tk.MustQuery("select @@session.mpp_exchange_compression_mode").Check(testkit.Rows("fast")) - tk.MustExec("SET SESSION mpp_exchange_compression_mode = HIGH_COMPRESSION") - tk.MustQuery("select @@session.mpp_exchange_compression_mode").Check(testkit.Rows("HIGH_COMPRESSION")) - - { - tk.MustExec("SET GLOBAL mpp_exchange_compression_mode = none") - tk.MustQuery("select @@global.mpp_exchange_compression_mode").Check(testkit.Rows("none")) - } - { - tk.MustExec("SET mpp_version = 0") - tk.MustExec("SET mpp_exchange_compression_mode = unspecified") - require.Equal(t, len(tk.Session().GetSessionVars().StmtCtx.GetWarnings()), 0) - } - { - tk.MustExec("SET mpp_version = 0") - tk.MustExec("SET mpp_exchange_compression_mode = HIGH_COMPRESSION") - warnings := tk.Session().GetSessionVars().StmtCtx.GetWarnings() - require.Equal(t, len(warnings), 1) - require.Equal(t, warnings[0].Err.Error(), "mpp exchange compression won't work under current mpp version 0") - } -} - -func TestDeprecateEnableTiFlashPipelineModel(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec(`set @@global.tidb_enable_tiflash_pipeline_model = 1`) - tk.MustQuery(`show warnings`).Check(testkit.Rows("Warning 1681 tidb_enable_tiflash_pipeline_model is deprecated and will be removed in a future release.")) -} diff --git a/pkg/executor/test/ddl/BUILD.bazel b/pkg/executor/test/ddl/BUILD.bazel index 9ff2e29495c50..49243d6b8205b 100644 --- a/pkg/executor/test/ddl/BUILD.bazel +++ b/pkg/executor/test/ddl/BUILD.bazel @@ -8,7 +8,7 @@ go_test( "main_test.go", ], flaky = True, - shard_count = 27, + shard_count = 17, deps = [ "//pkg/config", "//pkg/ddl/schematracker", @@ -16,13 +16,11 @@ go_test( "//pkg/ddl/util", "//pkg/domain", "//pkg/errno", - "//pkg/infoschema", "//pkg/kv", "//pkg/meta", "//pkg/meta/autoid", "//pkg/parser/model", "//pkg/parser/mysql", - "//pkg/parser/terror", "//pkg/planner/core", "//pkg/sessionctx/variable", "//pkg/sessionctx/variable/featuretag/disttask", @@ -35,7 +33,6 @@ go_test( "//pkg/types", "//pkg/util/chunk", "//pkg/util/dbterror", - "//pkg/util/dbterror/exeerrors", "@com_github_pingcap_failpoint//:failpoint", "@com_github_stretchr_testify//require", "@com_github_tikv_client_go_v2//tikv", diff --git a/pkg/executor/test/ddl/ddl_test.go b/pkg/executor/test/ddl/ddl_test.go index 2e1ed3c901cc1..00a30d2bb4364 100644 --- a/pkg/executor/test/ddl/ddl_test.go +++ b/pkg/executor/test/ddl/ddl_test.go @@ -19,7 +19,6 @@ import ( "fmt" "math" "strconv" - "strings" "testing" "time" @@ -29,13 +28,11 @@ import ( ddlutil "github.com/pingcap/tidb/pkg/ddl/util" "github.com/pingcap/tidb/pkg/domain" "github.com/pingcap/tidb/pkg/errno" - "github.com/pingcap/tidb/pkg/infoschema" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/meta" "github.com/pingcap/tidb/pkg/meta/autoid" "github.com/pingcap/tidb/pkg/parser/model" "github.com/pingcap/tidb/pkg/parser/mysql" - "github.com/pingcap/tidb/pkg/parser/terror" plannercore "github.com/pingcap/tidb/pkg/planner/core" "github.com/pingcap/tidb/pkg/sessionctx/variable" "github.com/pingcap/tidb/pkg/sessionctx/variable/featuretag/disttask" @@ -48,7 +45,6 @@ import ( "github.com/pingcap/tidb/pkg/types" "github.com/pingcap/tidb/pkg/util/chunk" "github.com/pingcap/tidb/pkg/util/dbterror" - "github.com/pingcap/tidb/pkg/util/dbterror/exeerrors" "github.com/stretchr/testify/require" ) @@ -70,18 +66,6 @@ func TestInTxnExecDDLFail(t *testing.T) { tk.MustQuery("select count(*) from t").Check(testkit.Rows("1")) } -func TestInTxnExecDDLInvalid(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("drop table if exists t;") - tk.MustExec("create table t (c_int int, c_str varchar(40));") - tk.MustExec("insert into t values (1, 'quizzical hofstadter');") - tk.MustExec("begin;") - _ = tk.MustQuery("select c_int from t where c_str is not null for update;") - tk.MustExec("alter table t add index idx_4 (c_str);") -} - func TestCreateTable(t *testing.T) { store := testkit.CreateMockStore(t, mockstore.WithDDLChecker()) @@ -188,154 +172,6 @@ func TestCreateTable(t *testing.T) { tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Note|1051|Unknown table 'test.t2_if_exists'", "Note|1051|Unknown table 'test.t3_if_exists'")) } -func TestCreateView(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - // create an source table - tk.MustExec("CREATE TABLE source_table (id INT NOT NULL DEFAULT 1, name varchar(255), PRIMARY KEY(id));") - // test create a exist view - tk.MustExec("CREATE VIEW view_t AS select id , name from source_table") - defer tk.MustExec("DROP VIEW IF EXISTS view_t") - tk.MustGetErrMsg("CREATE VIEW view_t AS select id , name from source_table", "[schema:1050]Table 'test.view_t' already exists") - // create view on nonexistent table - tk.MustGetErrMsg("create view v1 (c,d) as select a,b from t1", "[schema:1146]Table 'test.t1' doesn't exist") - // simple view - tk.MustExec("create table t1 (a int ,b int)") - tk.MustExec("insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10)") - // view with colList and SelectFieldExpr - tk.MustExec("create view v1 (c) as select b+1 from t1") - // view with SelectFieldExpr - tk.MustExec("create view v2 as select b+1 from t1") - // view with SelectFieldExpr and AsName - tk.MustExec("create view v3 as select b+1 as c from t1") - // view with colList , SelectField and AsName - tk.MustExec("create view v4 (c) as select b+1 as d from t1") - // view with select wild card - tk.MustExec("create view v5 as select * from t1") - tk.MustExec("create view v6 (c,d) as select * from t1") - tk.MustGetErrCode("create view v7 (c,d,e) as select * from t1", errno.ErrViewWrongList) - // drop multiple views in a statement - tk.MustExec("drop view v1,v2,v3,v4,v5,v6") - // view with variable - tk.MustExec("create view v1 (c,d) as select a,b+@@global.max_user_connections from t1") - tk.MustGetErrMsg("create view v1 (c,d) as select a,b from t1 where a = @@global.max_user_connections", "[schema:1050]Table 'test.v1' already exists") - tk.MustExec("drop view v1") - // view with different col counts - tk.MustGetErrCode("create view v1 (c,d,e) as select a,b from t1 ", errno.ErrViewWrongList) - tk.MustGetErrCode("create view v1 (c) as select a,b from t1 ", errno.ErrViewWrongList) - // view with or_replace flag - tk.MustExec("drop view if exists v1") - tk.MustExec("create view v1 (c,d) as select a,b from t1") - tk.MustExec("create or replace view v1 (c,d) as select a,b from t1 ") - tk.MustExec("create table if not exists t1 (a int ,b int)") - err := tk.ExecToErr("create or replace view t1 as select * from t1") - require.Equal(t, dbterror.ErrWrongObject.GenWithStackByArgs("test", "t1", "VIEW").Error(), err.Error()) - // create view using prepare - tk.MustExec(`prepare stmt from "create view v10 (x) as select 1";`) - tk.MustExec("execute stmt") - - // create view on union - tk.MustExec("drop table if exists t1, t2") - tk.MustExec("drop view if exists v") - tk.MustGetDBError("create view v as select * from t1 union select * from t2", infoschema.ErrTableNotExists) - tk.MustExec("create table t1(a int, b int)") - tk.MustExec("create table t2(a int, b int)") - tk.MustExec("insert into t1 values(1,2), (1,1), (1,2)") - tk.MustExec("insert into t2 values(1,1),(1,3)") - tk.MustExec("create definer='root'@'localhost' view v as select * from t1 union select * from t2") - tk.MustQuery("select * from v").Sort().Check(testkit.Rows("1 1", "1 2", "1 3")) - tk.MustExec("alter table t1 drop column a") - tk.MustGetDBError("select * from v", plannercore.ErrViewInvalid) - tk.MustExec("alter table t1 add column a int") - tk.MustQuery("select * from v").Sort().Check(testkit.Rows("1 1", "1 3", " 1", " 2")) - tk.MustExec("alter table t1 drop column a") - tk.MustExec("alter table t2 drop column b") - tk.MustGetDBError("select * from v", plannercore.ErrViewInvalid) - tk.MustExec("drop view v") - - tk.MustExec("create view v as (select * from t1)") - tk.MustExec("drop view v") - tk.MustExec("create view v as (select * from t1 union select * from t2)") - tk.MustExec("drop view v") - - // Test for `drop view if exists`. - tk.MustExec("drop view if exists v_if_exists;") - tk.MustQuery("show warnings;").Check(testkit.Rows("Note 1051 Unknown table 'test.v_if_exists'")) - tk.MustExec("create view v1_if_exists as (select * from t1)") - tk.MustExec("drop view if exists v1_if_exists,v2_if_exists,v3_if_exists") - tk.MustQuery("show warnings").Check(testkit.RowsWithSep("|", "Note|1051|Unknown table 'test.v2_if_exists'", "Note|1051|Unknown table 'test.v3_if_exists'")) - - // Test for create nested view. - tk.MustExec("create table test_v_nested(a int)") - tk.MustExec("create definer='root'@'localhost' view v_nested as select * from test_v_nested") - tk.MustExec("create definer='root'@'localhost' view v_nested2 as select * from v_nested") - tk.MustGetDBError("create or replace definer='root'@'localhost' view v_nested as select * from v_nested2", plannercore.ErrNoSuchTable) - tk.MustExec("drop table test_v_nested") - tk.MustExec("drop view v_nested, v_nested2") - - // Refer https://github.com/pingcap/tidb/issues/25876 - err = tk.ExecToErr("create view v_stale as select * from source_table as of timestamp current_timestamp(3)") - require.Truef(t, terror.ErrorEqual(err, exeerrors.ErrViewInvalid), "err %s", err) - - // Refer https://github.com/pingcap/tidb/issues/32682 - tk.MustExec("drop view if exists v1,v2;") - tk.MustExec("drop table if exists t1;") - tk.MustExec("CREATE TABLE t1(a INT, b INT);") - err = tk.ExecToErr("CREATE DEFINER=1234567890abcdefGHIKL1234567890abcdefGHIKL@localhost VIEW v1 AS SELECT a FROM t1;") - require.Truef(t, terror.ErrorEqual(err, exeerrors.ErrWrongStringLength), "ERROR 1470 (HY000): String '1234567890abcdefGHIKL1234567890abcdefGHIKL' is too long for user name (should be no longer than 32)") - err = tk.ExecToErr("CREATE DEFINER=some_user_name@host_1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890X VIEW v2 AS SELECT b FROM t1;") - require.Truef(t, terror.ErrorEqual(err, exeerrors.ErrWrongStringLength), "ERROR 1470 (HY000): String 'host_1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij12345' is too long for host name (should be no longer than 255)") -} - -func TestCreateViewWithOverlongColName(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t(a int)") - defer tk.MustExec("drop table t") - tk.MustExec("create view v as select distinct'" + strings.Repeat("a", 65) + "', " + - "max('" + strings.Repeat("b", 65) + "'), " + - "'cccccccccc', '" + strings.Repeat("d", 65) + "';") - resultCreateStmt := "CREATE ALGORITHM=UNDEFINED DEFINER=``@`` SQL SECURITY DEFINER VIEW `v` (`name_exp_1`, `name_exp_2`, `cccccccccc`, `name_exp_4`) AS " + - "SELECT DISTINCT _UTF8MB4'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' AS `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa`," + - "MAX(_UTF8MB4'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb') AS `max('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb')`," + - "_UTF8MB4'cccccccccc' AS `cccccccccc`,_UTF8MB4'ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd' AS `ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd`" - tk.MustQuery("select * from v") - tk.MustQuery("select name_exp_1, name_exp_2, cccccccccc, name_exp_4 from v") - tk.MustQuery("show create view v").Check(testkit.Rows("v " + resultCreateStmt + " utf8mb4 utf8mb4_bin")) - tk.MustExec("drop view v;") - tk.MustExec(resultCreateStmt) - - tk.MustExec("drop view v ") - tk.MustExec("create definer='root'@'localhost' view v as select 'a', '" + strings.Repeat("b", 65) + "' from t " + - "union select '" + strings.Repeat("c", 65) + "', " + - "count(distinct '" + strings.Repeat("b", 65) + "', " + - "'c');") - resultCreateStmt = "CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` (`a`, `name_exp_2`) AS " + - "SELECT _UTF8MB4'a' AS `a`,_UTF8MB4'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' AS `bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb` FROM `test`.`t` " + - "UNION SELECT _UTF8MB4'ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc' AS `ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc`," + - "COUNT(DISTINCT _UTF8MB4'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', _UTF8MB4'c') AS `count(distinct 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'c')`" - tk.MustQuery("select * from v") - tk.MustQuery("select a, name_exp_2 from v") - tk.MustQuery("show create view v").Check(testkit.Rows("v " + resultCreateStmt + " utf8mb4 utf8mb4_bin")) - tk.MustExec("drop view v;") - tk.MustExec(resultCreateStmt) - - tk.MustExec("drop view v ") - tk.MustExec("create definer='root'@'localhost' view v as select 'a' as '" + strings.Repeat("b", 65) + "' from t;") - tk.MustQuery("select * from v") - tk.MustQuery("select name_exp_1 from v") - resultCreateStmt = "CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` (`name_exp_1`) AS SELECT _UTF8MB4'a' AS `" + strings.Repeat("b", 65) + "` FROM `test`.`t`" - tk.MustQuery("show create view v").Check(testkit.Rows("v " + resultCreateStmt + " utf8mb4 utf8mb4_bin")) - tk.MustExec("drop view v;") - tk.MustExec(resultCreateStmt) - - tk.MustExec("drop view v ") - err := tk.ExecToErr("create view v(`" + strings.Repeat("b", 65) + "`) as select a from t;") - require.EqualError(t, err, "[ddl:1059]Identifier name 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' is too long") -} - func TestCreateDropDatabase(t *testing.T) { store, dom := testkit.CreateMockStoreAndDomain(t, mockstore.WithDDLChecker()) @@ -400,39 +236,6 @@ func TestCreateDropDatabase(t *testing.T) { )) } -func TestCreateDropTable(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table if not exists drop_test (a int)") - tk.MustExec("drop table if exists drop_test") - tk.MustExec("create table drop_test (a int)") - tk.MustExec("drop table drop_test") - tk.MustExecToErr("drop table mysql.gc_delete_range") -} - -func TestCreateDropView(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create or replace view drop_test as select 1,2") - tk.MustGetErrMsg("drop table drop_test", "[schema:1051]Unknown table 'test.drop_test'") - - tk.MustExec("drop view if exists drop_test") - - tk.MustGetErrMsg("drop view mysql.gc_delete_range", "Drop tidb system table 'mysql.gc_delete_range' is forbidden") - tk.MustGetErrMsg("drop view drop_test", "[schema:1051]Unknown table 'test.drop_test'") - tk.MustExec("create table t_v(a int)") - tk.MustGetErrMsg("drop view t_v", "[ddl:1347]'test.t_v' is not VIEW") - - tk.MustExec("create table t_v1(a int, b int);") - tk.MustExec("create table t_v2(a int, b int);") - tk.MustExec("create view v as select * from t_v1;") - tk.MustExec("create or replace view v as select * from t_v2;") - tk.MustQuery("select * from information_schema.views where table_name ='v';").Check( - testkit.Rows("def test v SELECT `test`.`t_v2`.`a` AS `a`,`test`.`t_v2`.`b` AS `b` FROM `test`.`t_v2` CASCADED NO @ DEFINER utf8mb4 utf8mb4_bin")) -} - func TestAlterTableAddColumn(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -666,42 +469,6 @@ func TestColumnCharsetAndCollate(t *testing.T) { tk.MustExec("drop database " + dbName) } -func TestTooLargeIdentifierLength(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - // for database. - dbName1, dbName2 := strings.Repeat("a", mysql.MaxDatabaseNameLength), strings.Repeat("a", mysql.MaxDatabaseNameLength+1) - tk.MustExec(fmt.Sprintf("create database %s", dbName1)) - tk.MustExec(fmt.Sprintf("drop database %s", dbName1)) - tk.MustGetErrMsg(fmt.Sprintf("create database %s", dbName2), fmt.Sprintf("[ddl:1059]Identifier name '%s' is too long", dbName2)) - - // for table. - tk.MustExec("use test") - tableName1, tableName2 := strings.Repeat("b", mysql.MaxTableNameLength), strings.Repeat("b", mysql.MaxTableNameLength+1) - tk.MustExec(fmt.Sprintf("create table %s(c int)", tableName1)) - tk.MustExec(fmt.Sprintf("drop table %s", tableName1)) - tk.MustGetErrMsg(fmt.Sprintf("create table %s(c int)", tableName2), fmt.Sprintf("[ddl:1059]Identifier name '%s' is too long", tableName2)) - - // for column. - tk.MustExec("drop table if exists t;") - columnName1, columnName2 := strings.Repeat("c", mysql.MaxColumnNameLength), strings.Repeat("c", mysql.MaxColumnNameLength+1) - tk.MustExec(fmt.Sprintf("create table t(%s int)", columnName1)) - tk.MustExec("drop table t") - tk.MustGetErrMsg(fmt.Sprintf("create table t(%s int)", columnName2), fmt.Sprintf("[ddl:1059]Identifier name '%s' is too long", columnName2)) - - // for index. - tk.MustExec("create table t(c int);") - indexName1, indexName2 := strings.Repeat("d", mysql.MaxIndexIdentifierLen), strings.Repeat("d", mysql.MaxIndexIdentifierLen+1) - tk.MustExec(fmt.Sprintf("create index %s on t(c)", indexName1)) - tk.MustExec(fmt.Sprintf("drop index %s on t", indexName1)) - tk.MustGetErrMsg(fmt.Sprintf("create index %s on t(c)", indexName2), fmt.Sprintf("[ddl:1059]Identifier name '%s' is too long", indexName2)) - - // for create table with index. - tk.MustExec("drop table t;") - tk.MustGetErrMsg(fmt.Sprintf("create table t(c int, index %s(c));", indexName2), fmt.Sprintf("[ddl:1059]Identifier name '%s' is too long", indexName2)) -} - func TestShardRowIDBits(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -1086,76 +853,6 @@ func TestSetDDLReorgBatchSize(t *testing.T) { res.Check(testkit.Rows("1000")) } -func TestIllegalFunctionCall4GeneratedColumns(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - // Test create an exist database - tk.MustExecToErr("CREATE database test") - - tk.MustGetErrMsg("create table t1 (b double generated always as (rand()) virtual);", - dbterror.ErrGeneratedColumnFunctionIsNotAllowed.GenWithStackByArgs("b").Error()) - tk.MustGetErrMsg("create table t1 (a varchar(64), b varchar(1024) generated always as (load_file(a)) virtual);", - dbterror.ErrGeneratedColumnFunctionIsNotAllowed.GenWithStackByArgs("b").Error()) - tk.MustGetErrMsg("create table t1 (a datetime generated always as (curdate()) virtual);", - dbterror.ErrGeneratedColumnFunctionIsNotAllowed.GenWithStackByArgs("a").Error()) - tk.MustGetErrMsg("create table t1 (a datetime generated always as (current_time()) virtual);", - dbterror.ErrGeneratedColumnFunctionIsNotAllowed.GenWithStackByArgs("a").Error()) - tk.MustGetErrMsg("create table t1 (a datetime generated always as (current_timestamp()) virtual);", - dbterror.ErrGeneratedColumnFunctionIsNotAllowed.GenWithStackByArgs("a").Error()) - tk.MustGetErrMsg("create table t1 (a datetime, b varchar(10) generated always as (localtime()) virtual);", - dbterror.ErrGeneratedColumnFunctionIsNotAllowed.GenWithStackByArgs("b").Error()) - tk.MustGetErrMsg("create table t1 (a varchar(1024) generated always as (uuid()) virtual);", - dbterror.ErrGeneratedColumnFunctionIsNotAllowed.GenWithStackByArgs("a").Error()) - tk.MustGetErrMsg("create table t1 (a varchar(1024), b varchar(1024) generated always as (is_free_lock(a)) virtual);", - dbterror.ErrGeneratedColumnFunctionIsNotAllowed.GenWithStackByArgs("b").Error()) - - tk.MustExec("create table t1 (a bigint not null primary key auto_increment, b bigint, c bigint as (b + 1));") - - tk.MustGetErrMsg("alter table t1 add column d varchar(1024) generated always as (database());", - dbterror.ErrGeneratedColumnFunctionIsNotAllowed.GenWithStackByArgs("d").Error()) - - tk.MustExec("alter table t1 add column d bigint generated always as (b + 1); ") - - tk.MustGetErrMsg("alter table t1 modify column d bigint generated always as (connection_id());", - dbterror.ErrGeneratedColumnFunctionIsNotAllowed.GenWithStackByArgs("d").Error()) - tk.MustGetErrMsg("alter table t1 change column c cc bigint generated always as (connection_id());", - dbterror.ErrGeneratedColumnFunctionIsNotAllowed.GenWithStackByArgs("cc").Error()) -} - -func TestGeneratedColumnRelatedDDL(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - // Test create an exist database - err := tk.ExecToErr("CREATE database test") - require.Error(t, err) - - tk.MustGetErrMsg("create table t1 (a bigint not null primary key auto_increment, b bigint as (a + 1));", - dbterror.ErrGeneratedColumnRefAutoInc.GenWithStackByArgs("b").Error()) - tk.MustExec("create table t1 (a bigint not null primary key auto_increment, b bigint, c bigint as (b + 1));") - tk.MustGetErrMsg("alter table t1 add column d bigint generated always as (a + 1);", - dbterror.ErrGeneratedColumnRefAutoInc.GenWithStackByArgs("d").Error()) - tk.MustExec("alter table t1 add column d bigint generated always as (b + 1);") - tk.MustGetErrMsg("alter table t1 modify column d bigint generated always as (a + 1);", - dbterror.ErrGeneratedColumnRefAutoInc.GenWithStackByArgs("d").Error()) - - // This mysql compatibility check can be disabled using tidb_enable_auto_increment_in_generated - tk.MustExec("set session tidb_enable_auto_increment_in_generated = 1;") - tk.MustExec("alter table t1 modify column d bigint generated always as (a + 1);") - - tk.MustGetErrMsg("alter table t1 add column e bigint as (z + 1);", - dbterror.ErrBadField.GenWithStackByArgs("z", "generated column function").Error()) - - tk.MustExec("drop table t1;") - - tk.MustExec("create table t1(a int, b int as (a+1), c int as (b+1));") - tk.MustExec("insert into t1 (a) values (1);") - tk.MustGetErrCode("alter table t1 modify column c int as (b+1) first;", mysql.ErrGeneratedColumnNonPrior) - tk.MustGetErrCode("alter table t1 modify column b int as (a+1) after c;", mysql.ErrGeneratedColumnNonPrior) - tk.MustQuery("select * from t1").Check(testkit.Rows("1 2 3")) -} - func TestSetDDLErrorCountLimit(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) @@ -1263,23 +960,6 @@ func TestRenameTable(t *testing.T) { tk.MustExec("drop database rename2") } -func TestAutoIncrementColumnErrorMessage(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - // Test create an exist database - tk.MustExecToErr("CREATE database test") - - tk.MustExec("CREATE TABLE t1 (t1_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY);") - - tk.MustGetErrMsg("CREATE INDEX idx1 ON t1 ((t1_id + t1_id));", - dbterror.ErrExpressionIndexCanNotRefer.GenWithStackByArgs("idx1").Error()) - - // This mysql compatibility check can be disabled using tidb_enable_auto_increment_in_generated - tk.MustExec("SET SESSION tidb_enable_auto_increment_in_generated = 1;") - tk.MustExec("CREATE INDEX idx1 ON t1 ((t1_id + t1_id));") -} - func TestRenameMultiTables(t *testing.T) { require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/meta/autoid/mockAutoIDChange", `return(true)`)) defer func() { @@ -1339,40 +1019,3 @@ func TestRenameMultiTables(t *testing.T) { tk.MustExec("drop database rename2") tk.MustExec("drop database rename3") } - -func TestCheckPrimaryKeyForTTLTable(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - - // create table should fail when pk contains double/float - tk.MustGetDBError("create table t1(id float primary key, t timestamp) TTL=`t`+INTERVAL 1 DAY", dbterror.ErrUnsupportedPrimaryKeyTypeWithTTL) - tk.MustGetDBError("create table t1(id float(10,2) primary key, t timestamp) TTL=`t`+INTERVAL 1 DAY", dbterror.ErrUnsupportedPrimaryKeyTypeWithTTL) - tk.MustGetDBError("create table t1(id double primary key, t timestamp) TTL=`t`+INTERVAL 1 DAY", dbterror.ErrUnsupportedPrimaryKeyTypeWithTTL) - tk.MustGetDBError("create table t1(id float(10,2) primary key, t timestamp) TTL=`t`+INTERVAL 1 DAY", dbterror.ErrUnsupportedPrimaryKeyTypeWithTTL) - tk.MustGetDBError("create table t1(id1 int, id2 float, t timestamp, primary key(id1, id2)) TTL=`t`+INTERVAL 1 DAY", dbterror.ErrUnsupportedPrimaryKeyTypeWithTTL) - tk.MustGetDBError("create table t1(id1 int, id2 double, t timestamp, primary key(id1, id2)) TTL=`t`+INTERVAL 1 DAY", dbterror.ErrUnsupportedPrimaryKeyTypeWithTTL) - - // alter table should fail when pk contains double/float - tk.MustExec("create table t1(id float primary key, t timestamp)") - tk.MustExec("create table t2(id double primary key, t timestamp)") - tk.MustExec("create table t3(id1 int, id2 float, primary key(id1, id2), t timestamp)") - tk.MustExec("create table t4(id1 int, id2 double, primary key(id1, id2), t timestamp)") - tk.MustGetDBError("alter table t1 TTL=`t`+INTERVAL 1 DAY", dbterror.ErrUnsupportedPrimaryKeyTypeWithTTL) - tk.MustGetDBError("alter table t2 TTL=`t`+INTERVAL 1 DAY", dbterror.ErrUnsupportedPrimaryKeyTypeWithTTL) - tk.MustGetDBError("alter table t3 TTL=`t`+INTERVAL 1 DAY", dbterror.ErrUnsupportedPrimaryKeyTypeWithTTL) - tk.MustGetDBError("alter table t4 TTL=`t`+INTERVAL 1 DAY", dbterror.ErrUnsupportedPrimaryKeyTypeWithTTL) - - // create table should not fail when the pk is not clustered - tk.MustExec("create table t11(id float primary key nonclustered, t timestamp) TTL=`t`+INTERVAL 1 DAY") - tk.MustExec("create table t12(id double primary key nonclustered, t timestamp) TTL=`t`+INTERVAL 1 DAY") - tk.MustExec("create table t13(id1 int, id2 float, t timestamp, primary key(id1, id2) nonclustered) TTL=`t`+INTERVAL 1 DAY") - - // alter table should not fail when the pk is not clustered - tk.MustExec("create table t21(id float primary key nonclustered, t timestamp)") - tk.MustExec("create table t22(id double primary key nonclustered, t timestamp)") - tk.MustExec("create table t23(id1 int, id2 float, t timestamp, primary key(id1, id2) nonclustered)") - tk.MustExec("alter table t21 TTL=`t`+INTERVAL 1 DAY") - tk.MustExec("alter table t22 TTL=`t`+INTERVAL 1 DAY") - tk.MustExec("alter table t23 TTL=`t`+INTERVAL 1 DAY") -} diff --git a/pkg/executor/test/issuetest/BUILD.bazel b/pkg/executor/test/issuetest/BUILD.bazel index 8c3892640c44f..f03a2147ddc4d 100644 --- a/pkg/executor/test/issuetest/BUILD.bazel +++ b/pkg/executor/test/issuetest/BUILD.bazel @@ -8,7 +8,7 @@ go_test( "main_test.go", ], flaky = True, - shard_count = 17, + shard_count = 15, deps = [ "//pkg/autoid_service", "//pkg/config", diff --git a/pkg/executor/test/issuetest/executor_issue_test.go b/pkg/executor/test/issuetest/executor_issue_test.go index 96d12ba48332c..78eeee0f0e019 100644 --- a/pkg/executor/test/issuetest/executor_issue_test.go +++ b/pkg/executor/test/issuetest/executor_issue_test.go @@ -340,88 +340,6 @@ func TestFix31038(t *testing.T) { require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/store/copr/disable-collect-execution")) } -func TestFix31537(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("set @@foreign_key_checks=0") - tk.MustExec(`CREATE TABLE trade ( - t_id bigint(16) NOT NULL AUTO_INCREMENT, - t_dts datetime NOT NULL, - t_st_id char(4) NOT NULL, - t_tt_id char(3) NOT NULL, - t_is_cash tinyint(1) NOT NULL, - t_s_symb char(15) NOT NULL, - t_qty mediumint(7) NOT NULL, - t_bid_price decimal(8,2) NOT NULL, - t_ca_id bigint(12) NOT NULL, - t_exec_name varchar(49) NOT NULL, - t_trade_price decimal(8,2) DEFAULT NULL, - t_chrg decimal(10,2) NOT NULL, - t_comm decimal(10,2) NOT NULL, - t_tax decimal(10,2) NOT NULL, - t_lifo tinyint(1) NOT NULL, - PRIMARY KEY (t_id) /*T![clustered_index] CLUSTERED */, - KEY i_t_ca_id_dts (t_ca_id,t_dts), - KEY i_t_s_symb_dts (t_s_symb,t_dts), - CONSTRAINT fk_trade_st FOREIGN KEY (t_st_id) REFERENCES status_type (st_id), - CONSTRAINT fk_trade_tt FOREIGN KEY (t_tt_id) REFERENCES trade_type (tt_id), - CONSTRAINT fk_trade_s FOREIGN KEY (t_s_symb) REFERENCES security (s_symb), - CONSTRAINT fk_trade_ca FOREIGN KEY (t_ca_id) REFERENCES customer_account (ca_id) -) ;`) - tk.MustExec(`CREATE TABLE trade_history ( - th_t_id bigint(16) NOT NULL, - th_dts datetime NOT NULL, - th_st_id char(4) NOT NULL, - PRIMARY KEY (th_t_id,th_st_id) /*T![clustered_index] NONCLUSTERED */, - KEY i_th_t_id_dts (th_t_id,th_dts), - CONSTRAINT fk_trade_history_t FOREIGN KEY (th_t_id) REFERENCES trade (t_id), - CONSTRAINT fk_trade_history_st FOREIGN KEY (th_st_id) REFERENCES status_type (st_id) -); -`) - tk.MustExec(`CREATE TABLE status_type ( - st_id char(4) NOT NULL, - st_name char(10) NOT NULL, - PRIMARY KEY (st_id) /*T![clustered_index] NONCLUSTERED */ -);`) - tk.MustQuery(`trace plan SELECT T_ID, T_S_SYMB, T_QTY, ST_NAME, TH_DTS FROM ( SELECT T_ID AS ID FROM TRADE WHERE T_CA_ID = 43000014236 ORDER BY T_DTS DESC LIMIT 10 ) T, TRADE, TRADE_HISTORY, STATUS_TYPE WHERE TRADE.T_ID = ID AND TRADE_HISTORY.TH_T_ID = TRADE.T_ID AND STATUS_TYPE.ST_ID = TRADE_HISTORY.TH_ST_ID ORDER BY TH_DTS DESC LIMIT 30;`) -} - -func TestIssue30382(t *testing.T) { - failpoint.Enable("github.com/pingcap/tidb/pkg/planner/core/forceDynamicPrune", `return(true)`) - defer failpoint.Disable("github.com/pingcap/tidb/pkg/planner/core/forceDynamicPrune") - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("set tidb_cost_model_version=2") - tk.MustExec("set @@session.tidb_enable_list_partition = ON;") - tk.MustExec("drop table if exists t1, t2;") - tk.MustExec("create table t1 (c_int int, c_str varchar(40), c_decimal decimal(12, 6), primary key (c_int) , key(c_str(2)) , key(c_decimal) ) partition by list (c_int) ( partition p0 values IN (1, 5, 9, 13, 17, 21, 25, 29, 33, 37), partition p1 values IN (2, 6, 10, 14, 18, 22, 26, 30, 34, 38), partition p2 values IN (3, 7, 11, 15, 19, 23, 27, 31, 35, 39), partition p3 values IN (4, 8, 12, 16, 20, 24, 28, 32, 36, 40)) ;") - tk.MustExec("create table t2 (c_int int, c_str varchar(40), c_decimal decimal(12, 6), primary key (c_int) , key(c_str) , key(c_decimal) ) partition by hash (c_int) partitions 4;") - tk.MustExec("insert into t1 values (6, 'musing mayer', 1.280), (7, 'wizardly heisenberg', 6.589), (8, 'optimistic swirles', 9.633), (9, 'hungry haslett', 2.659), (10, 'stupefied wiles', 2.336);") - tk.MustExec("insert into t2 select * from t1 ;") - tk.MustExec("begin;") - tk.MustQuery("select * from t1 where c_str <> any (select c_str from t2 where c_decimal < 5) for update;").Sort().Check(testkit.Rows( - "10 stupefied wiles 2.336000", - "6 musing mayer 1.280000", - "7 wizardly heisenberg 6.589000", - "8 optimistic swirles 9.633000", - "9 hungry haslett 2.659000")) - tk.MustQuery("explain format = 'brief' select * from t1 where c_str <> any (select c_str from t2 where c_decimal < 5) for update;").Check(testkit.Rows( - "SelectLock 6400.00 root for update 0", - "└─HashJoin 6400.00 root CARTESIAN inner join, other cond:or(gt(Column#8, 1), or(ne(test.t1.c_str, Column#7), if(ne(Column#9, 0), NULL, 0)))", - " ├─Selection(Build) 0.80 root ne(Column#10, 0)", - " │ └─HashAgg 1.00 root funcs:max(Column#17)->Column#7, funcs:count(distinct Column#18)->Column#8, funcs:sum(Column#19)->Column#9, funcs:count(1)->Column#10", - " │ └─Projection 3323.33 root test.t2.c_str->Column#17, test.t2.c_str->Column#18, cast(isnull(test.t2.c_str), decimal(20,0) BINARY)->Column#19", - " │ └─TableReader 3323.33 root partition:all data:Selection", - " │ └─Selection 3323.33 cop[tikv] lt(test.t2.c_decimal, 5)", - " │ └─TableFullScan 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", - " └─TableReader(Probe) 8000.00 root partition:all data:Selection", - " └─Selection 8000.00 cop[tikv] if(isnull(test.t1.c_str), NULL, 1)", - " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo")) - tk.MustExec("commit") -} - func issue20975Prepare(t *testing.T, store kv.Storage) (*testkit.TestKit, *testkit.TestKit) { tk1 := testkit.NewTestKit(t, store) tk2 := testkit.NewTestKit(t, store) diff --git a/pkg/executor/test/jointest/BUILD.bazel b/pkg/executor/test/jointest/BUILD.bazel index 5110896f6dff0..6cf13e3ba917e 100644 --- a/pkg/executor/test/jointest/BUILD.bazel +++ b/pkg/executor/test/jointest/BUILD.bazel @@ -9,7 +9,7 @@ go_test( ], flaky = True, race = "on", - shard_count = 12, + shard_count = 9, deps = [ "//pkg/config", "//pkg/meta/autoid", diff --git a/pkg/executor/test/jointest/join_test.go b/pkg/executor/test/jointest/join_test.go index a8a634c674ae6..d9409a6693c5e 100644 --- a/pkg/executor/test/jointest/join_test.go +++ b/pkg/executor/test/jointest/join_test.go @@ -316,552 +316,6 @@ func TestJoin2(t *testing.T) { tk.MustQuery("select min(t2.b) from t1 right join t2 on t2.a=t1.a right join t3 on t2.a=t3.a left join t4 on t3.a=t4.a").Check(testkit.Rows("1")) } -func TestJoinCast(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - var result *testkit.Result - - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t(c1 int)") - tk.MustExec("create table t1(c1 int unsigned)") - tk.MustExec("insert into t values (1)") - tk.MustExec("insert into t1 values (1)") - result = tk.MustQuery("select t.c1 from t , t1 where t.c1 = t1.c1") - result.Check(testkit.Rows("1")) - - // int64(-1) != uint64(18446744073709551615) - tk.MustExec("drop table if exists t") - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t(c1 bigint)") - tk.MustExec("create table t1(c1 bigint unsigned)") - tk.MustExec("insert into t values (-1)") - tk.MustExec("insert into t1 values (18446744073709551615)") - result = tk.MustQuery("select * from t , t1 where t.c1 = t1.c1") - result.Check(testkit.Rows()) - - // float(1) == double(1) - tk.MustExec("drop table if exists t") - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t(c1 float)") - tk.MustExec("create table t1(c1 double)") - tk.MustExec("insert into t values (1.0)") - tk.MustExec("insert into t1 values (1.00)") - result = tk.MustQuery("select t.c1 from t , t1 where t.c1 = t1.c1") - result.Check(testkit.Rows("1")) - - // varchar("x") == char("x") - tk.MustExec("drop table if exists t") - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t(c1 varchar(1))") - tk.MustExec("create table t1(c1 char(1))") - tk.MustExec(`insert into t values ("x")`) - tk.MustExec(`insert into t1 values ("x")`) - result = tk.MustQuery("select t.c1 from t , t1 where t.c1 = t1.c1") - result.Check(testkit.Rows("x")) - - // varchar("x") != char("y") - tk.MustExec("drop table if exists t") - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t(c1 varchar(1))") - tk.MustExec("create table t1(c1 char(1))") - tk.MustExec(`insert into t values ("x")`) - tk.MustExec(`insert into t1 values ("y")`) - result = tk.MustQuery("select t.c1 from t , t1 where t.c1 = t1.c1") - result.Check(testkit.Rows()) - - tk.MustExec("drop table if exists t") - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t(c1 int,c2 double)") - tk.MustExec("create table t1(c1 double,c2 int)") - tk.MustExec("insert into t values (1, 2), (1, NULL)") - tk.MustExec("insert into t1 values (1, 2), (1, NULL)") - result = tk.MustQuery("select * from t a , t1 b where (a.c1, a.c2) = (b.c1, b.c2);") - result.Check(testkit.Rows("1 2 1 2")) - - /* Issue 11895 */ - tk.MustExec("drop table if exists t;") - tk.MustExec("drop table if exists t1;") - tk.MustExec("create table t(c1 bigint unsigned);") - tk.MustExec("create table t1(c1 bit(64));") - tk.MustExec("insert into t value(18446744073709551615);") - tk.MustExec("insert into t1 value(-1);") - result = tk.MustQuery("select * from t, t1 where t.c1 = t1.c1;") - require.Len(t, result.Rows(), 1) - - /* Issues 11896 */ - tk.MustExec("drop table if exists t;") - tk.MustExec("drop table if exists t1;") - tk.MustExec("create table t(c1 bigint);") - tk.MustExec("create table t1(c1 bit(64));") - tk.MustExec("insert into t value(1);") - tk.MustExec("insert into t1 value(1);") - result = tk.MustQuery("select * from t, t1 where t.c1 = t1.c1;") - require.Len(t, result.Rows(), 1) - - tk.MustExec("drop table if exists t;") - tk.MustExec("drop table if exists t1;") - tk.MustExec("create table t(c1 bigint);") - tk.MustExec("create table t1(c1 bit(64));") - tk.MustExec("insert into t value(-1);") - tk.MustExec("insert into t1 value(18446744073709551615);") - result = tk.MustQuery("select * from t, t1 where t.c1 = t1.c1;") - // TODO: MySQL will return one row, because c1 in t1 is 0xffffffff, which equals to -1. - require.Len(t, result.Rows(), 0) - - tk.MustExec("drop table if exists t") - tk.MustExec("drop table if exists t1") - tk.MustExec("drop table if exists t2") - tk.MustExec("create table t(c1 bigint)") - tk.MustExec("create table t1(c1 bigint unsigned)") - tk.MustExec("create table t2(c1 Date)") - tk.MustExec("insert into t value(20191111)") - tk.MustExec("insert into t1 value(20191111)") - tk.MustExec("insert into t2 value('2019-11-11')") - result = tk.MustQuery("select * from t, t1, t2 where t.c1 = t2.c1 and t1.c1 = t2.c1") - result.Check(testkit.Rows("20191111 20191111 2019-11-11")) - - tk.MustExec("drop table if exists t;") - tk.MustExec("drop table if exists t1") - tk.MustExec("drop table if exists t2;") - tk.MustExec("create table t(c1 bigint);") - tk.MustExec("create table t1(c1 bigint unsigned);") - tk.MustExec("create table t2(c1 enum('a', 'b', 'c', 'd'));") - tk.MustExec("insert into t value(3);") - tk.MustExec("insert into t1 value(3);") - tk.MustExec("insert into t2 value('c');") - result = tk.MustQuery("select * from t, t1, t2 where t.c1 = t2.c1 and t1.c1 = t2.c1;") - result.Check(testkit.Rows("3 3 c")) - - tk.MustExec("drop table if exists t;") - tk.MustExec("drop table if exists t1;") - tk.MustExec("drop table if exists t2;") - tk.MustExec("create table t(c1 bigint);") - tk.MustExec("create table t1(c1 bigint unsigned);") - tk.MustExec("create table t2 (c1 SET('a', 'b', 'c', 'd'));") - tk.MustExec("insert into t value(9);") - tk.MustExec("insert into t1 value(9);") - tk.MustExec("insert into t2 value('a,d');") - result = tk.MustQuery("select * from t, t1, t2 where t.c1 = t2.c1 and t1.c1 = t2.c1;") - result.Check(testkit.Rows("9 9 a,d")) - - tk.MustExec("drop table if exists t") - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t(c1 int)") - tk.MustExec("create table t1(c1 decimal(4,2))") - tk.MustExec("insert into t values(0), (2)") - tk.MustExec("insert into t1 values(0), (9)") - result = tk.MustQuery("select * from t left join t1 on t1.c1 = t.c1") - result.Sort().Check(testkit.Rows("0 0.00", "2 ")) - - tk.MustExec("drop table if exists t") - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t(c1 decimal(4,1))") - tk.MustExec("create table t1(c1 decimal(4,2))") - tk.MustExec("insert into t values(0), (2)") - tk.MustExec("insert into t1 values(0), (9)") - result = tk.MustQuery("select * from t left join t1 on t1.c1 = t.c1") - result.Sort().Check(testkit.Rows("0.0 0.00", "2.0 ")) - - tk.MustExec("drop table if exists t") - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t(c1 decimal(4,1))") - tk.MustExec("create table t1(c1 decimal(4,2))") - tk.MustExec("create index k1 on t1(c1)") - tk.MustExec("insert into t values(0), (2)") - tk.MustExec("insert into t1 values(0), (9)") - result = tk.MustQuery("select /*+ INL_JOIN(t1) */ * from t left join t1 on t1.c1 = t.c1") - result.Sort().Check(testkit.Rows("0.0 0.00", "2.0 ")) - result = tk.MustQuery("select /*+ INL_HASH_JOIN(t1) */ * from t left join t1 on t1.c1 = t.c1") - result.Sort().Check(testkit.Rows("0.0 0.00", "2.0 ")) - result = tk.MustQuery("select /*+ INL_MERGE_JOIN(t1) */ * from t left join t1 on t1.c1 = t.c1") - result.Sort().Check(testkit.Rows("0.0 0.00", "2.0 ")) - - tk.MustExec("drop table if exists t") - tk.MustExec("drop table if exists t1") - tk.MustExec("drop table if exists t2") - tk.MustExec("create table t(c1 char(10))") - tk.MustExec("create table t1(c1 char(10))") - tk.MustExec("create table t2(c1 char(10))") - tk.MustExec("insert into t values('abd')") - tk.MustExec("insert into t1 values('abc')") - tk.MustExec("insert into t2 values('abc')") - result = tk.MustQuery("select * from (select * from t union all select * from t1) t1 join t2 on t1.c1 = t2.c1") - result.Sort().Check(testkit.Rows("abc abc")) - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a varchar(10), index idx(a))") - tk.MustExec("insert into t values('1'), ('2'), ('3')") - tk.MustExec("set @@tidb_init_chunk_size=1") - result = tk.MustQuery("select a from (select /*+ INL_JOIN(t1, t2) */ t1.a from t t1 join t t2 on t1.a=t2.a) t group by a") - result.Sort().Check(testkit.Rows("1", "2", "3")) - result = tk.MustQuery("select a from (select /*+ INL_HASH_JOIN(t1, t2) */ t1.a from t t1 join t t2 on t1.a=t2.a) t group by a") - result.Sort().Check(testkit.Rows("1", "2", "3")) - result = tk.MustQuery("select a from (select /*+ INL_MERGE_JOIN(t1, t2) */ t1.a from t t1 join t t2 on t1.a=t2.a) t group by a") - result.Sort().Check(testkit.Rows("1", "2", "3")) - tk.MustExec("set @@tidb_init_chunk_size=32") -} - -func TestUsing(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - - tk.MustExec("use test") - tk.MustExec("drop table if exists t1, t2, t3, t4") - tk.MustExec("create table t1 (a int, c int)") - tk.MustExec("create table t2 (a int, d int)") - tk.MustExec("create table t3 (a int)") - tk.MustExec("create table t4 (a int)") - tk.MustExec("insert t1 values (2, 4), (1, 3)") - tk.MustExec("insert t2 values (2, 5), (3, 6)") - tk.MustExec("insert t3 values (1)") - - tk.MustQuery("select * from t1 join t2 using (a)").Check(testkit.Rows("2 4 5")) - tk.MustQuery("select t1.a, t2.a from t1 join t2 using (a)").Check(testkit.Rows("2 2")) - - tk.MustQuery("select * from t1 right join t2 using (a) order by a").Check(testkit.Rows("2 5 4", "3 6 ")) - tk.MustQuery("select t1.a, t2.a from t1 right join t2 using (a) order by t2.a").Check(testkit.Rows("2 2", " 3")) - - tk.MustQuery("select * from t1 left join t2 using (a) order by a").Check(testkit.Rows("1 3 ", "2 4 5")) - tk.MustQuery("select t1.a, t2.a from t1 left join t2 using (a) order by t1.a").Check(testkit.Rows("1 ", "2 2")) - - tk.MustQuery("select * from t1 join t2 using (a) right join t3 using (a)").Check(testkit.Rows("1 ")) - tk.MustQuery("select * from t1 join t2 using (a) right join t3 on (t2.a = t3.a)").Check(testkit.Rows(" 1")) - tk.MustQuery("select t2.a from t1 join t2 using (a) right join t3 on (t1.a = t3.a)").Check(testkit.Rows("")) - tk.MustQuery("select t1.a, t2.a, t3.a from t1 join t2 using (a) right join t3 using (a)").Check(testkit.Rows(" 1")) - tk.MustQuery("select t1.c, t2.d from t1 join t2 using (a) right join t3 using (a)").Check(testkit.Rows(" ")) - - tk.MustExec("alter table t1 add column b int default 1 after a") - tk.MustExec("alter table t2 add column b int default 1 after a") - tk.MustQuery("select * from t1 join t2 using (b, a)").Check(testkit.Rows("2 1 4 5")) - - tk.MustExec("select * from (t1 join t2 using (a)) join (t3 join t4 using (a)) on (t2.a = t4.a and t1.a = t3.a)") - - tk.MustExec("drop table if exists t, tt") - tk.MustExec("create table t(a int, b int)") - tk.MustExec("create table tt(b int, a int)") - tk.MustExec("insert into t (a, b) values(1, 1)") - tk.MustExec("insert into tt (a, b) values(1, 2)") - tk.MustQuery("select * from t join tt using(a)").Check(testkit.Rows("1 1 2")) - - tk.MustExec("drop table if exists t, tt") - tk.MustExec("create table t(a float, b int)") - tk.MustExec("create table tt(b bigint, a int)") - // Check whether this sql can execute successfully. - tk.MustExec("select * from t join tt using(a)") - - tk.MustExec("drop table if exists t, s") - tk.MustExec("create table t(a int, b int)") - tk.MustExec("create table s(b int, a int)") - tk.MustExec("insert into t values(1,1), (2,2), (3,3), (null,null)") - tk.MustExec("insert into s values(1,1), (3,3), (null,null)") - - // For issue 20477 - tk.MustQuery("select t.*, s.* from t join s using(a)").Check(testkit.Rows("1 1 1 1", "3 3 3 3")) - tk.MustQuery("select s.a from t join s using(a)").Check(testkit.Rows("1", "3")) - tk.MustQuery("select s.a from t join s using(a) where s.a > 1").Check(testkit.Rows("3")) - tk.MustQuery("select s.a from t join s using(a) order by s.a").Check(testkit.Rows("1", "3")) - tk.MustQuery("select s.a from t join s using(a) where s.a > 1 order by s.a").Check(testkit.Rows("3")) - tk.MustQuery("select s.a from t join s using(a) where s.a > 1 order by s.a limit 2").Check(testkit.Rows("3")) - - // For issue 20441 - tk.MustExec(`DROP TABLE if exists t1, t2, t3`) - tk.MustExec(`create table t1 (i int)`) - tk.MustExec(`create table t2 (i int)`) - tk.MustExec(`create table t3 (i int)`) - tk.MustExec(`select * from t1,t2 natural left join t3 order by t1.i,t2.i,t3.i`) - tk.MustExec(`select t1.i,t2.i,t3.i from t2 natural left join t3,t1 order by t1.i,t2.i,t3.i`) - tk.MustExec(`select * from t1,t2 natural right join t3 order by t1.i,t2.i,t3.i`) - tk.MustExec(`select t1.i,t2.i,t3.i from t2 natural right join t3,t1 order by t1.i,t2.i,t3.i`) - - // For issue 15844 - tk.MustExec(`DROP TABLE if exists t0, t1`) - tk.MustExec(`CREATE TABLE t0(c0 INT)`) - tk.MustExec(`CREATE TABLE t1(c0 INT)`) - tk.MustExec(`SELECT t0.c0 FROM t0 NATURAL RIGHT JOIN t1 WHERE t1.c0`) - - // For issue 20958 - tk.MustExec(`DROP TABLE if exists t1, t2`) - tk.MustExec(`create table t1(id int, name varchar(20));`) - tk.MustExec(`create table t2(id int, address varchar(30));`) - tk.MustExec(`insert into t1 values(1,'gangshen');`) - tk.MustExec(`insert into t2 values(1,'HangZhou');`) - tk.MustQuery(`select t2.* from t1 inner join t2 using (id) limit 1;`).Check(testkit.Rows("1 HangZhou")) - tk.MustQuery(`select t2.* from t1 inner join t2 on t1.id = t2.id limit 1;`).Check(testkit.Rows("1 HangZhou")) - - // For issue 20476 - tk.MustExec("drop table if exists t1") - tk.MustExec("create table t1(a int)") - tk.MustExec("insert into t1 (a) values(1)") - tk.MustQuery("select t1.*, t2.* from t1 join t1 t2 using(a)").Check(testkit.Rows("1 1")) - tk.MustQuery("select * from t1 join t1 t2 using(a)").Check(testkit.Rows("1")) - - // For issue 18992 - tk.MustExec("drop table t") - tk.MustExec("CREATE TABLE t ( a varchar(55) NOT NULL, b varchar(55) NOT NULL, c int(11) DEFAULT NULL, d int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;") - tk.MustExec("update t t1 join t t2 using(a,b) set t1.c=t2.d;") - - // For issue 20467 - tk.MustExec(`DROP TABLE if exists t1,t2,t3,t4,t5`) - tk.MustExec(`CREATE TABLE t1 (a INT, b INT)`) - tk.MustExec(`CREATE TABLE t2 (a INT, b INT)`) - tk.MustExec(`CREATE TABLE t3 (a INT, b INT)`) - tk.MustExec(`INSERT INTO t1 VALUES (1,1)`) - tk.MustExec(`INSERT INTO t2 VALUES (1,1)`) - tk.MustExec(`INSERT INTO t3 VALUES (1,1)`) - tk.MustGetErrMsg(`SELECT * FROM t1 JOIN (t2 JOIN t3 USING (b)) USING (a)`, "[planner:1052]Column 'a' in from clause is ambiguous") - - // For issue 6712 - tk.MustExec("drop table if exists t1,t2") - tk.MustExec("create table t1 (t1 int , t0 int)") - tk.MustExec("create table t2 (t2 int, t0 int)") - tk.MustExec("insert into t1 select 11, 1") - tk.MustExec("insert into t2 select 22, 1") - tk.MustQuery("select t1.t0, t2.t0 from t1 join t2 using(t0) group by t1.t0").Check(testkit.Rows("1 1")) - tk.MustQuery("select t1.t0, t2.t0 from t1 join t2 using(t0) having t1.t0 > 0").Check(testkit.Rows("1 1")) -} - -func TestSubquery(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("set @@tidb_hash_join_concurrency=1") - tk.MustExec("set @@tidb_hashagg_partial_concurrency=1") - tk.MustExec("set @@tidb_hashagg_final_concurrency=1") - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t (c int, d int)") - tk.MustExec("insert t values (1, 1)") - tk.MustExec("insert t values (2, 2)") - tk.MustExec("insert t values (3, 4)") - tk.MustExec("commit") - - tk.MustExec("set sql_mode = 'STRICT_TRANS_TABLES'") - - result := tk.MustQuery("select * from t where exists(select * from t k where t.c = k.c having sum(c) = 1)") - result.Check(testkit.Rows("1 1")) - result = tk.MustQuery("select * from t where exists(select k.c, k.d from t k, t p where t.c = k.d)") - result.Check(testkit.Rows("1 1", "2 2")) - result = tk.MustQuery("select 1 = (select count(*) from t where t.c = k.d) from t k") - result.Check(testkit.Rows("1", "1", "0")) - result = tk.MustQuery("select 1 = (select count(*) from t where exists( select * from t m where t.c = k.d)) from t k") - result.Sort().Check(testkit.Rows("0", "1", "1")) - result = tk.MustQuery("select t.c = any (select count(*) from t) from t") - result.Sort().Check(testkit.Rows("0", "0", "1")) - result = tk.MustQuery("select * from t where (t.c, 6) = any (select count(*), sum(t.c) from t)") - result.Check(testkit.Rows("3 4")) - result = tk.MustQuery("select t.c from t where (t.c) < all (select count(*) from t)") - result.Check(testkit.Rows("1", "2")) - result = tk.MustQuery("select t.c from t where (t.c, t.d) = any (select * from t)") - result.Sort().Check(testkit.Rows("1", "2", "3")) - result = tk.MustQuery("select t.c from t where (t.c, t.d) != all (select * from t)") - result.Check(testkit.Rows()) - result = tk.MustQuery("select (select count(*) from t where t.c = k.d) from t k") - result.Sort().Check(testkit.Rows("0", "1", "1")) - result = tk.MustQuery("select t.c from t where (t.c, t.d) in (select * from t)") - result.Sort().Check(testkit.Rows("1", "2", "3")) - result = tk.MustQuery("select t.c from t where (t.c, t.d) not in (select * from t)") - result.Check(testkit.Rows()) - result = tk.MustQuery("select * from t A inner join t B on A.c = B.c and A.c > 100") - result.Check(testkit.Rows()) - // = all empty set is true - result = tk.MustQuery("select t.c from t where (t.c, t.d) != all (select * from t where d > 1000)") - result.Sort().Check(testkit.Rows("1", "2", "3")) - result = tk.MustQuery("select t.c from t where (t.c) < any (select c from t where d > 1000)") - result.Check(testkit.Rows()) - tk.MustExec("insert t values (NULL, NULL)") - result = tk.MustQuery("select (t.c) < any (select c from t) from t") - result.Sort().Check(testkit.Rows("1", "1", "", "")) - result = tk.MustQuery("select (10) > all (select c from t) from t") - result.Check(testkit.Rows("", "", "", "")) - result = tk.MustQuery("select (c) > all (select c from t) from t") - result.Check(testkit.Rows("0", "0", "0", "")) - - tk.MustExec("drop table if exists a") - tk.MustExec("create table a (c int, d int)") - tk.MustExec("insert a values (1, 2)") - tk.MustExec("drop table if exists b") - tk.MustExec("create table b (c int, d int)") - tk.MustExec("insert b values (2, 1)") - - result = tk.MustQuery("select * from a b where c = (select d from b a where a.c = 2 and b.c = 1)") - result.Check(testkit.Rows("1 2")) - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(c int)") - tk.MustExec("insert t values(10), (8), (7), (9), (11)") - result = tk.MustQuery("select * from t where 9 in (select c from t s where s.c < t.c limit 3)") - result.Check(testkit.Rows("10")) - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(id int, v int)") - tk.MustExec("insert into t values(1, 1), (2, 2), (3, 3)") - result = tk.MustQuery("select * from t where v=(select min(t1.v) from t t1, t t2, t t3 where t1.id=t2.id and t2.id=t3.id and t1.id=t.id)") - result.Check(testkit.Rows("1 1", "2 2", "3 3")) - - result = tk.MustQuery("select exists (select t.id from t where s.id < 2 and t.id = s.id) from t s") - result.Sort().Check(testkit.Rows("0", "0", "1")) - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(c int)") - result = tk.MustQuery("select exists(select count(*) from t)") - result.Check(testkit.Rows("1")) - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(id int primary key, v int)") - tk.MustExec("insert into t values(1, 1), (2, 2), (3, 3)") - result = tk.MustQuery("select (select t.id from t where s.id < 2 and t.id = s.id) from t s") - result.Sort().Check(testkit.Rows("1", "", "")) - rs, err := tk.Exec("select (select t.id from t where t.id = t.v and t.v != s.id) from t s") - require.NoError(t, err) - _, err = session.GetRows4Test(context.Background(), tk.Session(), rs) - require.Error(t, err) - require.NoError(t, rs.Close()) - - tk.MustExec("drop table if exists t") - tk.MustExec("drop table if exists s") - tk.MustExec("create table t(id int)") - tk.MustExec("create table s(id int)") - tk.MustExec("insert into t values(1), (2)") - tk.MustExec("insert into s values(2), (2)") - result = tk.MustQuery("select id from t where(select count(*) from s where s.id = t.id) > 0") - result.Check(testkit.Rows("2")) - result = tk.MustQuery("select *, (select count(*) from s where id = t.id limit 1, 1) from t") - result.Check(testkit.Rows("1 ", "2 ")) - - tk.MustExec("drop table if exists t") - tk.MustExec("drop table if exists s") - tk.MustExec("create table t(id int primary key)") - tk.MustExec("create table s(id int)") - tk.MustExec("insert into t values(1), (2)") - tk.MustExec("insert into s values(2), (2)") - result = tk.MustQuery("select *, (select count(id) from s where id = t.id) from t") - result.Check(testkit.Rows("1 0", "2 2")) - result = tk.MustQuery("select *, 0 < any (select count(id) from s where id = t.id) from t") - result.Check(testkit.Rows("1 0", "2 1")) - result = tk.MustQuery("select (select count(*) from t k where t.id = id) from s, t where t.id = s.id limit 1") - result.Check(testkit.Rows("1")) - - tk.MustExec("drop table if exists t, s") - tk.MustExec("create table t(id int primary key)") - tk.MustExec("create table s(id int, index k(id))") - tk.MustExec("insert into t values(1), (2)") - tk.MustExec("insert into s values(2), (2)") - result = tk.MustQuery("select (select id from s where s.id = t.id order by s.id limit 1) from t") - result.Check(testkit.Rows("", "2")) - - tk.MustExec("drop table if exists t, s") - tk.MustExec("create table t(id int)") - tk.MustExec("create table s(id int)") - tk.MustExec("insert into t values(2), (2)") - tk.MustExec("insert into s values(2)") - result = tk.MustQuery("select (select id from s where s.id = t.id order by s.id) from t") - result.Check(testkit.Rows("2", "2")) - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(dt datetime)") - result = tk.MustQuery("select (select 1 from t where DATE_FORMAT(o.dt,'%Y-%m')) from t o") - result.Check(testkit.Rows()) - - tk.MustExec("drop table if exists t1, t2") - tk.MustExec("create table t1(f1 int, f2 int)") - tk.MustExec("create table t2(fa int, fb int)") - tk.MustExec("insert into t1 values (1,1),(1,1),(1,2),(1,2),(1,2),(1,3)") - tk.MustExec("insert into t2 values (1,1),(1,2),(1,3)") - result = tk.MustQuery("select f1,f2 from t1 group by f1,f2 having count(1) >= all (select fb from t2 where fa = f1)") - result.Check(testkit.Rows("1 2")) - - tk.MustExec("DROP TABLE IF EXISTS t1, t2") - tk.MustExec("CREATE TABLE t1(a INT)") - tk.MustExec("CREATE TABLE t2 (d BINARY(2), PRIMARY KEY (d(1)), UNIQUE KEY (d))") - tk.MustExec("INSERT INTO t1 values(1)") - result = tk.MustQuery("SELECT 1 FROM test.t1, test.t2 WHERE 1 = (SELECT test.t2.d FROM test.t2 WHERE test.t1.a >= 1) and test.t2.d = 1;") - result.Check(testkit.Rows()) - - tk.MustExec("DROP TABLE IF EXISTS t1") - tk.MustExec("CREATE TABLE t1(a int, b int default 0)") - tk.MustExec("create index k1 on t1(a)") - tk.MustExec("INSERT INTO t1 (a) values(1), (2), (3), (4), (5)") - result = tk.MustQuery("select (select /*+ INL_JOIN(x2) */ x2.a from t1 x1, t1 x2 where x1.a = t1.a and x1.a = x2.a) from t1") - result.Check(testkit.Rows("1", "2", "3", "4", "5")) - result = tk.MustQuery("select (select /*+ INL_HASH_JOIN(x2) */ x2.a from t1 x1, t1 x2 where x1.a = t1.a and x1.a = x2.a) from t1") - result.Check(testkit.Rows("1", "2", "3", "4", "5")) - result = tk.MustQuery("select (select /*+ INL_MERGE_JOIN(x2) */ x2.a from t1 x1, t1 x2 where x1.a = t1.a and x1.a = x2.a) from t1") - result.Check(testkit.Rows("1", "2", "3", "4", "5")) - - // test left outer semi join & anti left outer semi join - tk.MustQuery("select 1 from (select t1.a in (select t1.a from t1) from t1) x;").Check(testkit.Rows("1", "1", "1", "1", "1")) - tk.MustQuery("select 1 from (select t1.a not in (select t1.a from t1) from t1) x;").Check(testkit.Rows("1", "1", "1", "1", "1")) - - tk.MustExec("drop table if exists t1, t2") - tk.MustExec("create table t1(a int)") - tk.MustExec("create table t2(b int)") - tk.MustExec("insert into t1 values(1)") - tk.MustExec("insert into t2 values(1)") - tk.MustQuery("select * from t1 where a in (select a from t2)").Check(testkit.Rows("1")) - - tk.MustExec("insert into t2 value(null)") - tk.MustQuery("select * from t1 where 1 in (select b from t2)").Check(testkit.Rows("1")) - tk.MustQuery("select * from t1 where 1 not in (select b from t2)").Check(testkit.Rows()) - tk.MustQuery("select * from t1 where 2 not in (select b from t2)").Check(testkit.Rows()) - tk.MustQuery("select * from t1 where 2 in (select b from t2)").Check(testkit.Rows()) - tk.MustQuery("select 1 in (select b from t2) from t1").Check(testkit.Rows("1")) - tk.MustQuery("select 1 in (select 1 from t2) from t1").Check(testkit.Rows("1")) - tk.MustQuery("select 1 not in (select b from t2) from t1").Check(testkit.Rows("0")) - tk.MustQuery("select 1 not in (select 1 from t2) from t1").Check(testkit.Rows("0")) - - tk.MustExec("delete from t2 where b=1") - tk.MustQuery("select 1 in (select b from t2) from t1").Check(testkit.Rows("")) - tk.MustQuery("select 1 not in (select b from t2) from t1").Check(testkit.Rows("")) - tk.MustQuery("select 1 not in (select 1 from t2) from t1").Check(testkit.Rows("0")) - tk.MustQuery("select 1 in (select 1 from t2) from t1").Check(testkit.Rows("1")) - tk.MustQuery("select 1 not in (select null from t1) from t2").Check(testkit.Rows("")) - tk.MustQuery("select 1 in (select null from t1) from t2").Check(testkit.Rows("")) - - tk.MustExec("drop table if exists s") - tk.MustExec("create table s(a int not null, b int)") - tk.MustExec("set sql_mode = ''") - tk.MustQuery("select (2,0) in (select s.a, min(s.b) from s) as f").Check(testkit.Rows("")) - tk.MustQuery("select (2,0) not in (select s.a, min(s.b) from s) as f").Check(testkit.Rows("")) - tk.MustQuery("select (2,0) = any (select s.a, min(s.b) from s) as f").Check(testkit.Rows("")) - tk.MustQuery("select (2,0) != all (select s.a, min(s.b) from s) as f").Check(testkit.Rows("")) - tk.MustQuery("select (2,0) in (select s.b, min(s.b) from s) as f").Check(testkit.Rows("")) - tk.MustQuery("select (2,0) not in (select s.b, min(s.b) from s) as f").Check(testkit.Rows("")) - tk.MustQuery("select (2,0) = any (select s.b, min(s.b) from s) as f").Check(testkit.Rows("")) - tk.MustQuery("select (2,0) != all (select s.b, min(s.b) from s) as f").Check(testkit.Rows("")) - tk.MustExec("insert into s values(1,null)") - tk.MustQuery("select 1 in (select b from s)").Check(testkit.Rows("")) - - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int)") - tk.MustExec("insert into t values(1),(null)") - tk.MustQuery("select a not in (select 1) from t").Sort().Check(testkit.Rows( - "0", - "", - )) - tk.MustQuery("select 1 not in (select null from t t1) from t").Check(testkit.Rows( - "", - "", - )) - tk.MustQuery("select 1 in (select null from t t1) from t").Check(testkit.Rows( - "", - "", - )) - tk.MustQuery("select a in (select 0) xx from (select null as a) x").Check(testkit.Rows("")) - - tk.MustExec("drop table t") - tk.MustExec("create table t(a int, b int)") - tk.MustExec("insert into t values(1,null),(null, null),(null, 2)") - tk.MustQuery("select * from t t1 where (2 in (select a from t t2 where (t2.b=t1.b) is null))").Check(testkit.Rows()) - tk.MustQuery("select (t2.a in (select t1.a from t t1)) is true from t t2").Sort().Check(testkit.Rows( - "0", - "0", - "1", - )) - - tk.MustExec("set @@tidb_hash_join_concurrency=5") -} - func TestJoinLeak(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) diff --git a/pkg/executor/test/writetest/BUILD.bazel b/pkg/executor/test/writetest/BUILD.bazel index 94e4812c42396..1080b392de576 100644 --- a/pkg/executor/test/writetest/BUILD.bazel +++ b/pkg/executor/test/writetest/BUILD.bazel @@ -8,7 +8,7 @@ go_test( "write_test.go", ], flaky = True, - shard_count = 30, + shard_count = 27, deps = [ "//br/pkg/lightning/mydump", "//pkg/config", diff --git a/pkg/executor/test/writetest/write_test.go b/pkg/executor/test/writetest/write_test.go index 5d7423a17e8be..c8bb54ef2cabb 100644 --- a/pkg/executor/test/writetest/write_test.go +++ b/pkg/executor/test/writetest/write_test.go @@ -18,7 +18,6 @@ import ( "context" "errors" "fmt" - "strconv" "testing" "github.com/pingcap/failpoint" @@ -1930,54 +1929,6 @@ func TestWriteListColumnsPartitionTable1(t *testing.T) { tk.MustQuery("select * from t").Check(testkit.Rows()) } -func TestListPartitionWithAutoRandom(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("set @@session.tidb_enable_list_partition = ON") - tk.MustExec("drop table if exists t") - tk.MustExec(`create table t (a bigint key auto_random (3), b int) partition by list (a%5) (partition p0 values in (0,1,2), partition p1 values in (3,4));`) - tk.MustExec("set @@allow_auto_random_explicit_insert = true") - tk.MustExec("replace into t values (1,1)") - result := []string{"1"} - for i := 2; i < 100; i++ { - sql := fmt.Sprintf("insert into t (b) values (%v)", i) - tk.MustExec(sql) - result = append(result, strconv.Itoa(i)) - } - tk.MustQuery("select b from t order by b").Check(testkit.Rows(result...)) - tk.MustExec("update t set b=b+1 where a=1") - tk.MustQuery("select b from t where a=1").Check(testkit.Rows("2")) - tk.MustExec("update t set b=b+1 where a<2") - tk.MustQuery("select b from t where a<2").Check(testkit.Rows("3")) - tk.MustExec("insert into t values (1, 1) on duplicate key update b=b+1") - tk.MustQuery("select b from t where a=1").Check(testkit.Rows("4")) -} - -func TestListPartitionWithAutoIncrement(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("set @@session.tidb_enable_list_partition = ON") - tk.MustExec("drop table if exists t") - tk.MustExec(`create table t (a bigint key auto_increment, b int) partition by list (a%5) (partition p0 values in (0,1,2), partition p1 values in (3,4));`) - tk.MustExec("set @@allow_auto_random_explicit_insert = true") - tk.MustExec("replace into t values (1,1)") - result := []string{"1"} - for i := 2; i < 100; i++ { - sql := fmt.Sprintf("insert into t (b) values (%v)", i) - tk.MustExec(sql) - result = append(result, strconv.Itoa(i)) - } - tk.MustQuery("select b from t order by b").Check(testkit.Rows(result...)) - tk.MustExec("update t set b=b+1 where a=1") - tk.MustQuery("select b from t where a=1").Check(testkit.Rows("2")) - tk.MustExec("update t set b=b+1 where a<2") - tk.MustQuery("select b from t where a<2").Check(testkit.Rows("3")) - tk.MustExec("insert into t values (1, 1) on duplicate key update b=b+1") - tk.MustQuery("select b from t where a=1").Check(testkit.Rows("4")) -} - func TestUpdate(t *testing.T) { failpoint.Enable("github.com/pingcap/tidb/pkg/planner/core/forceDynamicPrune", `return(true)`) defer failpoint.Disable("github.com/pingcap/tidb/pkg/planner/core/forceDynamicPrune") @@ -2293,23 +2244,3 @@ func TestListColumnsPartitionWithGlobalIndex(t *testing.T) { tk.MustQuery("select a from t partition (p1) order by a").Check(testkit.Rows("bbb", "bbc")) } } - -func TestMutipleReplaceAndInsertInOneSession(t *testing.T) { - store := testkit.CreateMockStore(t) - tk := testkit.NewTestKit(t, store) - tk.MustExec("use test") - tk.MustExec("create table t_securities(id bigint not null auto_increment primary key, security_id varchar(8), market_id smallint, security_type int, unique key uu(security_id, market_id))") - tk.MustExec(`insert into t_securities (security_id, market_id, security_type) values ("1", 2, 7), ("7", 1, 7) ON DUPLICATE KEY UPDATE security_type = VALUES(security_type)`) - tk.MustExec(`replace into t_securities (security_id, market_id, security_type) select security_id+1, 1, security_type from t_securities where security_id="7";`) - tk.MustExec(`INSERT INTO t_securities (security_id, market_id, security_type) values ("1", 2, 7), ("7", 1, 7) ON DUPLICATE KEY UPDATE security_type = VALUES(security_type)`) - - tk.MustQuery("select * from t_securities").Sort().Check(testkit.Rows("1 1 2 7", "2 7 1 7", "3 8 1 7")) - - tk2 := testkit.NewTestKit(t, store) - tk2.MustExec("use test") - tk2.MustExec(`insert into t_securities (security_id, market_id, security_type) values ("1", 2, 7), ("7", 1, 7) ON DUPLICATE KEY UPDATE security_type = VALUES(security_type)`) - tk2.MustExec(`insert into t_securities (security_id, market_id, security_type) select security_id+2, 1, security_type from t_securities where security_id="7";`) - tk2.MustExec(`INSERT INTO t_securities (security_id, market_id, security_type) values ("1", 2, 7), ("7", 1, 7) ON DUPLICATE KEY UPDATE security_type = VALUES(security_type)`) - - tk2.MustQuery("select * from t_securities").Sort().Check(testkit.Rows("1 1 2 7", "2 7 1 7", "3 8 1 7", "8 9 1 7")) -} diff --git a/tests/integrationtest/r/executor/ddl.result b/tests/integrationtest/r/executor/ddl.result index 2aa60d6014c39..a858f6eb72f6d 100644 --- a/tests/integrationtest/r/executor/ddl.result +++ b/tests/integrationtest/r/executor/ddl.result @@ -296,3 +296,295 @@ ALTER TABLE t_1 ADD FOREIGN KEY fk_t_id(t_id) references t(id); Error 8152 (HY000): Set TTL for a table referenced by foreign key is not allowed drop table t,t_1; set global tidb_enable_foreign_key=default; +drop table if exists source_table, t1, t2, test_v_nested; +drop view if exists view_t, v, v1, v2, v3, v4, v5, v6, v7, v_nested, v_nested2; +CREATE TABLE source_table (id INT NOT NULL DEFAULT 1, name varchar(255), PRIMARY KEY(id)); +CREATE VIEW view_t AS select id , name from source_table; +CREATE VIEW view_t AS select id , name from source_table; +Error 1050 (42S01): Table 'executor__ddl.view_t' already exists +create view v1 (c,d) as select a,b from t1; +Error 1146 (42S02): Table 'executor__ddl.t1' doesn't exist +create table t1 (a int ,b int); +insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10); +create view v1 (c) as select b+1 from t1; +create view v2 as select b+1 from t1; +create view v3 as select b+1 as c from t1; +create view v4 (c) as select b+1 as d from t1; +create view v5 as select * from t1; +create view v6 (c,d) as select * from t1; +create view v7 (c,d,e) as select * from t1; +Error 1353 (HY000): In definition of view, derived table or common table expression, SELECT list and column names list have different column counts +drop view v1,v2,v3,v4,v5,v6; +create view v1 (c,d) as select a,b+@@global.max_user_connections from t1; +create view v1 (c,d) as select a,b from t1 where a = @@global.max_user_connections; +Error 1050 (42S01): Table 'executor__ddl.v1' already exists +drop view v1; +create view v1 (c,d,e) as select a,b from t1 ; +Error 1353 (HY000): In definition of view, derived table or common table expression, SELECT list and column names list have different column counts +create view v1 (c) as select a,b from t1 ; +Error 1353 (HY000): In definition of view, derived table or common table expression, SELECT list and column names list have different column counts +drop view if exists v1; +create view v1 (c,d) as select a,b from t1; +create or replace view v1 (c,d) as select a,b from t1 ; +create table if not exists t1 (a int ,b int); +create or replace view t1 as select * from t1; +Error 1347 (HY000): 'executor__ddl.t1' is not VIEW +prepare stmt from "create view v10 (x) as select 1"; +execute stmt; + +drop table if exists t1, t2; +drop view if exists v; +create view v as select * from t1 union select * from t2; +Error 1146 (42S02): Table 'executor__ddl.t1' doesn't exist +create table t1(a int, b int); +create table t2(a int, b int); +insert into t1 values(1,2), (1,1), (1,2); +insert into t2 values(1,1),(1,3); +create definer='root'@'localhost' view v as select * from t1 union select * from t2; +select * from v; +a b +1 1 +1 2 +1 3 +alter table t1 drop column a; +select * from v; +Error 1356 (HY000): View 'executor__ddl.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them +alter table t1 add column a int; +select * from v; +a b +NULL 1 +NULL 2 +1 1 +1 3 +alter table t1 drop column a; +alter table t2 drop column b; +select * from v; +Error 1356 (HY000): View 'executor__ddl.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them +drop view v; +create view v as (select * from t1); +drop view v; +create view v as (select * from t1 union select * from t2); +drop view v; +drop view if exists v_if_exists; +show warnings; +Level Code Message +Note 1051 Unknown table 'executor__ddl.v_if_exists' +create view v1_if_exists as (select * from t1); +drop view if exists v1_if_exists,v2_if_exists,v3_if_exists; +show warnings; +Level Code Message +Note 1051 Unknown table 'executor__ddl.v2_if_exists' +Note 1051 Unknown table 'executor__ddl.v3_if_exists' +create table test_v_nested(a int); +create definer='root'@'localhost' view v_nested as select * from test_v_nested; +create definer='root'@'localhost' view v_nested2 as select * from v_nested; +create or replace definer='root'@'localhost' view v_nested as select * from v_nested2; +Error 1146 (42S02): Table 'executor__ddl.v_nested' doesn't exist +drop table test_v_nested; +drop view v_nested, v_nested2; +create view v_stale as select * from source_table as of timestamp current_timestamp(3); +Error 1356 (HY000): View 'executor__ddl.v_stale' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them +drop view if exists v1,v2; +drop table if exists t1; +CREATE TABLE t1(a INT, b INT); +CREATE DEFINER=1234567890abcdefGHIKL1234567890abcdefGHIKL@localhost VIEW v1 AS SELECT a FROM t1; +Error 1470 (HY000): String '1234567890abcdefGHIKL1234567890abcdefGHIKL' is too long for user name (should be no longer than 32) +CREATE DEFINER=some_user_name@host_1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890X VIEW v2 AS SELECT b FROM t1; +Error 1470 (HY000): String 'host_1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij12345' is too long for host name (should be no longer than 255) +DROP VIEW IF EXISTS view_t; +drop table if exists t; +drop view if exists v; +create table t(a int); +create view v as select distinct'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', max('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'), 'cccccccccc', 'ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'; +select * from v; +name_exp_1 name_exp_2 cccccccccc name_exp_4 +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccc ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd +select name_exp_1, name_exp_2, cccccccccc, name_exp_4 from v; +name_exp_1 name_exp_2 cccccccccc name_exp_4 +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb cccccccccc ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd +show create view v; +View Create View character_set_client collation_connection +v CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`%` SQL SECURITY DEFINER VIEW `v` (`name_exp_1`, `name_exp_2`, `cccccccccc`, `name_exp_4`) AS SELECT DISTINCT _UTF8MB4'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' AS `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa`,MAX(_UTF8MB4'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb') AS `max('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb')`,_UTF8MB4'cccccccccc' AS `cccccccccc`,_UTF8MB4'ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd' AS `ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd` utf8mb4 utf8mb4_general_ci +drop view v; +CREATE ALGORITHM=UNDEFINED DEFINER=``@`` SQL SECURITY DEFINER VIEW `v` (`name_exp_1`, `name_exp_2`, `cccccccccc`, `name_exp_4`) AS SELECT DISTINCT _UTF8MB4'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' AS `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa`,MAX(_UTF8MB4'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb') AS `max('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb')`,_UTF8MB4'cccccccccc' AS `cccccccccc`,_UTF8MB4'ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd' AS `ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd`; +drop view v ; +create definer='root'@'localhost' view v as select 'a', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' from t union select 'ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc', count(distinct 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'c'); +select * from v; +a name_exp_2 +ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc 1 +select a, name_exp_2 from v; +a name_exp_2 +ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc 1 +show create view v; +View Create View character_set_client collation_connection +v CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` (`a`, `name_exp_2`) AS SELECT _UTF8MB4'a' AS `a`,_UTF8MB4'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' AS `bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb` FROM `executor__ddl`.`t` UNION SELECT _UTF8MB4'ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc' AS `ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc`,COUNT(DISTINCT _UTF8MB4'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', _UTF8MB4'c') AS `count(distinct 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'c')` utf8mb4 utf8mb4_general_ci +drop view v; +CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` (`a`, `name_exp_2`) AS SELECT _UTF8MB4'a' AS `a`,_UTF8MB4'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' AS `bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb` FROM `executor__ddl`.`t` UNION SELECT _UTF8MB4'ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc' AS `ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc`,COUNT(DISTINCT _UTF8MB4'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', _UTF8MB4'c') AS `count(distinct 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'c')`; +drop view v ; +create definer='root'@'localhost' view v as select 'a' as 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' from t; +select * from v; +name_exp_1 +select name_exp_1 from v; +name_exp_1 +show create view v; +View Create View character_set_client collation_connection +v CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` (`name_exp_1`) AS SELECT _UTF8MB4'a' AS `bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb` FROM `executor__ddl`.`t` utf8mb4 utf8mb4_general_ci +drop view v; +CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` (`name_exp_1`) AS SELECT _UTF8MB4'a' AS `bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb` FROM `executor__ddl`.`t`; +drop view v ; +create view v(`bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb`) as select a from t; +Error 1059 (42000): Identifier name 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' is too long +drop table t; +drop table if exists drop_test; +create table if not exists drop_test (a int); +drop table if exists drop_test; +create table drop_test (a int); +drop table drop_test; +drop table mysql.gc_delete_range; +Error 1105 (HY000): Drop tidb system table 'mysql.gc_delete_range' is forbidden +drop table if exists t_v, t_v1, t_v2; +drop view if exists v; +create or replace view drop_test as select 1,2; +drop table drop_test; +Error 1051 (42S02): Unknown table 'executor__ddl.drop_test' +drop view if exists drop_test; +drop view mysql.gc_delete_range; +Error 1105 (HY000): Drop tidb system table 'mysql.gc_delete_range' is forbidden +drop view drop_test; +Error 1051 (42S02): Unknown table 'executor__ddl.drop_test' +create table t_v(a int); +drop view t_v; +Error 1347 (HY000): 'executor__ddl.t_v' is not VIEW +create table t_v1(a int, b int); +create table t_v2(a int, b int); +create view v as select * from t_v1; +create or replace view v as select * from t_v2; +select * from information_schema.views where table_name ='v' and table_schema='executor__ddl'; +TABLE_CATALOG TABLE_SCHEMA TABLE_NAME VIEW_DEFINITION CHECK_OPTION IS_UPDATABLE DEFINER SECURITY_TYPE CHARACTER_SET_CLIENT COLLATION_CONNECTION +def executor__ddl v SELECT `executor__ddl`.`t_v2`.`a` AS `a`,`executor__ddl`.`t_v2`.`b` AS `b` FROM `executor__ddl`.`t_v2` CASCADED NO root@% DEFINER utf8mb4 utf8mb4_general_ci +drop database if exists aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; +create database aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; +drop database aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; +create database aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; +Error 1059 (42000): Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long +drop table if exists bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; +create table bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(c int); +drop table bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; +create table bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(c int); +Error 1059 (42000): Identifier name 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' is too long +drop table if exists t; +create table t(cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc int); +drop table t; +create table t(ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc int); +Error 1059 (42000): Identifier name 'ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc' is too long +create table t(c int); +create index dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd on t(c); +drop index dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd on t; +create index ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd on t(c); +Error 1059 (42000): Identifier name 'ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd' is too long +drop table t; +create table t(c int, index ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd(c)); +Error 1059 (42000): Identifier name 'ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd' is too long +drop table if exists t1; +CREATE database test; +Error 1007 (HY000): Can't create database 'test'; database exists +create table t1 (b double generated always as (rand()) virtual); +Error 3102 (HY000): Expression of generated column 'b' contains a disallowed function. +create table t1 (a varchar(64), b varchar(1024) generated always as (load_file(a)) virtual); +Error 3102 (HY000): Expression of generated column 'b' contains a disallowed function. +create table t1 (a datetime generated always as (curdate()) virtual); +Error 3102 (HY000): Expression of generated column 'a' contains a disallowed function. +create table t1 (a datetime generated always as (current_time()) virtual); +Error 3102 (HY000): Expression of generated column 'a' contains a disallowed function. +create table t1 (a datetime generated always as (current_timestamp()) virtual); +Error 3102 (HY000): Expression of generated column 'a' contains a disallowed function. +create table t1 (a datetime, b varchar(10) generated always as (localtime()) virtual); +Error 3102 (HY000): Expression of generated column 'b' contains a disallowed function. +create table t1 (a varchar(1024) generated always as (uuid()) virtual); +Error 3102 (HY000): Expression of generated column 'a' contains a disallowed function. +create table t1 (a varchar(1024), b varchar(1024) generated always as (is_free_lock(a)) virtual); +Error 3102 (HY000): Expression of generated column 'b' contains a disallowed function. +create table t1 (a bigint not null primary key auto_increment, b bigint, c bigint as (b + 1)); +alter table t1 add column d varchar(1024) generated always as (database()); +Error 3102 (HY000): Expression of generated column 'd' contains a disallowed function. +alter table t1 add column d bigint generated always as (b + 1); +alter table t1 modify column d bigint generated always as (connection_id()); +Error 3102 (HY000): Expression of generated column 'd' contains a disallowed function. +alter table t1 change column c cc bigint generated always as (connection_id()); +Error 3102 (HY000): Expression of generated column 'cc' contains a disallowed function. +drop table if exists t1; +create table t1 (a bigint not null primary key auto_increment, b bigint as (a + 1)); +Error 3109 (HY000): Generated column 'b' cannot refer to auto-increment column. +create table t1 (a bigint not null primary key auto_increment, b bigint, c bigint as (b + 1)); +alter table t1 add column d bigint generated always as (a + 1); +Error 3109 (HY000): Generated column 'd' cannot refer to auto-increment column. +alter table t1 add column d bigint generated always as (b + 1); +alter table t1 modify column d bigint generated always as (a + 1); +Error 3109 (HY000): Generated column 'd' cannot refer to auto-increment column. +set session tidb_enable_auto_increment_in_generated = 1; +alter table t1 modify column d bigint generated always as (a + 1); +alter table t1 add column e bigint as (z + 1); +Error 1054 (42S22): Unknown column 'z' in 'generated column function' +drop table t1; +create table t1(a int, b int as (a+1), c int as (b+1)); +insert into t1 (a) values (1); +alter table t1 modify column c int as (b+1) first; +Error 3107 (HY000): Generated column can refer only to generated columns defined prior to it. +alter table t1 modify column b int as (a+1) after c; +Error 3107 (HY000): Generated column can refer only to generated columns defined prior to it. +select * from t1; +a b c +1 2 3 +set session tidb_enable_auto_increment_in_generated = default; +drop table if exists t1; +CREATE TABLE t1 (t1_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY); +CREATE INDEX idx1 ON t1 ((t1_id + t1_id)); +Error 3754 (HY000): Expression index 'idx1' cannot refer to an auto-increment column +SET SESSION tidb_enable_auto_increment_in_generated = 1; +CREATE INDEX idx1 ON t1 ((t1_id + t1_id)); +SET SESSION tidb_enable_auto_increment_in_generated = default; +set tidb_enable_clustered_index=on; +drop table if exists t1, t2, t3, t4, t11, t12, t13, t21, t22, t23; +create table t1(id float primary key, t timestamp) TTL=`t`+INTERVAL 1 DAY; +Error 8153 (HY000): Unsupported clustered primary key type FLOAT/DOUBLE for TTL +create table t1(id float(10,2) primary key, t timestamp) TTL=`t`+INTERVAL 1 DAY; +Error 8153 (HY000): Unsupported clustered primary key type FLOAT/DOUBLE for TTL +create table t1(id double primary key, t timestamp) TTL=`t`+INTERVAL 1 DAY; +Error 8153 (HY000): Unsupported clustered primary key type FLOAT/DOUBLE for TTL +create table t1(id float(10,2) primary key, t timestamp) TTL=`t`+INTERVAL 1 DAY; +Error 8153 (HY000): Unsupported clustered primary key type FLOAT/DOUBLE for TTL +create table t1(id1 int, id2 float, t timestamp, primary key(id1, id2)) TTL=`t`+INTERVAL 1 DAY; +Error 8153 (HY000): Unsupported clustered primary key type FLOAT/DOUBLE for TTL +create table t1(id1 int, id2 double, t timestamp, primary key(id1, id2)) TTL=`t`+INTERVAL 1 DAY; +Error 8153 (HY000): Unsupported clustered primary key type FLOAT/DOUBLE for TTL +create table t1(id float primary key, t timestamp); +create table t2(id double primary key, t timestamp); +create table t3(id1 int, id2 float, primary key(id1, id2), t timestamp); +create table t4(id1 int, id2 double, primary key(id1, id2), t timestamp); +alter table t1 TTL=`t`+INTERVAL 1 DAY; +Error 8153 (HY000): Unsupported clustered primary key type FLOAT/DOUBLE for TTL +alter table t2 TTL=`t`+INTERVAL 1 DAY; +Error 8153 (HY000): Unsupported clustered primary key type FLOAT/DOUBLE for TTL +alter table t3 TTL=`t`+INTERVAL 1 DAY; +Error 8153 (HY000): Unsupported clustered primary key type FLOAT/DOUBLE for TTL +alter table t4 TTL=`t`+INTERVAL 1 DAY; +Error 8153 (HY000): Unsupported clustered primary key type FLOAT/DOUBLE for TTL +create table t11(id float primary key nonclustered, t timestamp) TTL=`t`+INTERVAL 1 DAY; +create table t12(id double primary key nonclustered, t timestamp) TTL=`t`+INTERVAL 1 DAY; +create table t13(id1 int, id2 float, t timestamp, primary key(id1, id2) nonclustered) TTL=`t`+INTERVAL 1 DAY; +create table t21(id float primary key nonclustered, t timestamp); +create table t22(id double primary key nonclustered, t timestamp); +create table t23(id1 int, id2 float, t timestamp, primary key(id1, id2) nonclustered); +alter table t21 TTL=`t`+INTERVAL 1 DAY; +alter table t22 TTL=`t`+INTERVAL 1 DAY; +alter table t23 TTL=`t`+INTERVAL 1 DAY; +set tidb_enable_clustered_index=default; +drop table if exists t; +create table t (c_int int, c_str varchar(40)); +insert into t values (1, 'quizzical hofstadter'); +begin; +select c_int from t where c_str is not null for update; +c_int +1 +alter table t add index idx_4 (c_str); +rollback; diff --git a/tests/integrationtest/r/executor/issues.result b/tests/integrationtest/r/executor/issues.result index 4001bff307270..6285c9ab579f7 100644 --- a/tests/integrationtest/r/executor/issues.result +++ b/tests/integrationtest/r/executor/issues.result @@ -746,3 +746,78 @@ insert into F values (1, 8); select table1.`col_int` as field1, table1.`col_int` as field2 from V as table1 left join F as table2 on table1.`col_int` = table2.`col_int` order by field1, field2 desc limit 2; field1 field2 8 8 +set tidb_cost_model_version=2; +set @@session.tidb_enable_list_partition = ON; +drop table if exists t1, t2; +create table t1 (c_int int, c_str varchar(40), c_decimal decimal(12, 6), primary key (c_int) , key(c_str(2)) , key(c_decimal) ) partition by list (c_int) ( partition p0 values IN (1, 5, 9, 13, 17, 21, 25, 29, 33, 37), partition p1 values IN (2, 6, 10, 14, 18, 22, 26, 30, 34, 38), partition p2 values IN (3, 7, 11, 15, 19, 23, 27, 31, 35, 39), partition p3 values IN (4, 8, 12, 16, 20, 24, 28, 32, 36, 40)) ; +create table t2 (c_int int, c_str varchar(40), c_decimal decimal(12, 6), primary key (c_int) , key(c_str) , key(c_decimal) ) partition by hash (c_int) partitions 4; +insert into t1 values (6, 'musing mayer', 1.280), (7, 'wizardly heisenberg', 6.589), (8, 'optimistic swirles', 9.633), (9, 'hungry haslett', 2.659), (10, 'stupefied wiles', 2.336); +insert into t2 select * from t1 ; +analyze table t1; +analyze table t2; +begin; +select * from t1 where c_str <> any (select c_str from t2 where c_decimal < 5) for update; +c_int c_str c_decimal +10 stupefied wiles 2.336000 +6 musing mayer 1.280000 +7 wizardly heisenberg 6.589000 +8 optimistic swirles 9.633000 +9 hungry haslett 2.659000 +explain format = 'brief' select * from t1 where c_str <> any (select c_str from t2 where c_decimal < 5) for update; +id estRows task access object operator info +SelectLock 3.20 root for update 0 +└─HashJoin 3.20 root CARTESIAN inner join, other cond:or(gt(Column#8, 1), or(ne(executor__issues.t1.c_str, Column#7), if(ne(Column#9, 0), NULL, 0))) + ├─Selection(Build) 0.80 root ne(Column#10, 0) + │ └─StreamAgg 1.00 root funcs:max(Column#17)->Column#7, funcs:count(distinct Column#18)->Column#8, funcs:sum(Column#19)->Column#9, funcs:count(1)->Column#10 + │ └─Projection 3.00 root executor__issues.t2.c_str->Column#17, executor__issues.t2.c_str->Column#18, cast(isnull(executor__issues.t2.c_str), decimal(20,0) BINARY)->Column#19 + │ └─TableReader 3.00 root partition:all data:Selection + │ └─Selection 3.00 cop[tikv] lt(executor__issues.t2.c_decimal, 5) + │ └─TableFullScan 5.00 cop[tikv] table:t2 keep order:false + └─TableReader(Probe) 4.00 root partition:all data:Selection + └─Selection 4.00 cop[tikv] if(isnull(executor__issues.t1.c_str), NULL, 1) + └─TableFullScan 5.00 cop[tikv] table:t1 keep order:false +commit; +set tidb_cost_model_version=default; +set @@session.tidb_enable_list_partition = default; +drop table if exists trade, trade_history, status_type; +set @@foreign_key_checks=0; +CREATE TABLE trade ( +t_id bigint(16) NOT NULL AUTO_INCREMENT, +t_dts datetime NOT NULL, +t_st_id char(4) NOT NULL, +t_tt_id char(3) NOT NULL, +t_is_cash tinyint(1) NOT NULL, +t_s_symb char(15) NOT NULL, +t_qty mediumint(7) NOT NULL, +t_bid_price decimal(8,2) NOT NULL, +t_ca_id bigint(12) NOT NULL, +t_exec_name varchar(49) NOT NULL, +t_trade_price decimal(8,2) DEFAULT NULL, +t_chrg decimal(10,2) NOT NULL, +t_comm decimal(10,2) NOT NULL, +t_tax decimal(10,2) NOT NULL, +t_lifo tinyint(1) NOT NULL, +PRIMARY KEY (t_id) /*T![clustered_index] CLUSTERED */, +KEY i_t_ca_id_dts (t_ca_id,t_dts), +KEY i_t_s_symb_dts (t_s_symb,t_dts), +CONSTRAINT fk_trade_st FOREIGN KEY (t_st_id) REFERENCES status_type (st_id), +CONSTRAINT fk_trade_tt FOREIGN KEY (t_tt_id) REFERENCES trade_type (tt_id), +CONSTRAINT fk_trade_s FOREIGN KEY (t_s_symb) REFERENCES security (s_symb), +CONSTRAINT fk_trade_ca FOREIGN KEY (t_ca_id) REFERENCES customer_account (ca_id) +) ; +CREATE TABLE trade_history ( +th_t_id bigint(16) NOT NULL, +th_dts datetime NOT NULL, +th_st_id char(4) NOT NULL, +PRIMARY KEY (th_t_id,th_st_id) /*T![clustered_index] NONCLUSTERED */, +KEY i_th_t_id_dts (th_t_id,th_dts), +CONSTRAINT fk_trade_history_t FOREIGN KEY (th_t_id) REFERENCES trade (t_id), +CONSTRAINT fk_trade_history_st FOREIGN KEY (th_st_id) REFERENCES status_type (st_id) +); +CREATE TABLE status_type ( +st_id char(4) NOT NULL, +st_name char(10) NOT NULL, +PRIMARY KEY (st_id) /*T![clustered_index] NONCLUSTERED */ +); +trace plan SELECT T_ID, T_S_SYMB, T_QTY, ST_NAME, TH_DTS FROM ( SELECT T_ID AS ID FROM TRADE WHERE T_CA_ID = 43000014236 ORDER BY T_DTS DESC LIMIT 10 ) T, TRADE, TRADE_HISTORY, STATUS_TYPE WHERE TRADE.T_ID = ID AND TRADE_HISTORY.TH_T_ID = TRADE.T_ID AND STATUS_TYPE.ST_ID = TRADE_HISTORY.TH_ST_ID ORDER BY TH_DTS DESC LIMIT 30; +set @@foreign_key_checks=default; diff --git a/tests/integrationtest/r/executor/jointest/join.result b/tests/integrationtest/r/executor/jointest/join.result index ac36ba737e673..58d4bf830fdaf 100644 --- a/tests/integrationtest/r/executor/jointest/join.result +++ b/tests/integrationtest/r/executor/jointest/join.result @@ -878,3 +878,686 @@ a b a1 b1 select /*+ INL_JOIN(t3) */ * from t join t3 on t.b = t3.b1; a b a1 b1 1 A 1 A +drop table if exists t; +drop table if exists t1; +create table t(c1 int); +create table t1(c1 int unsigned); +insert into t values (1); +insert into t1 values (1); +select t.c1 from t , t1 where t.c1 = t1.c1; +c1 +1 +drop table if exists t; +drop table if exists t1; +create table t(c1 bigint); +create table t1(c1 bigint unsigned); +insert into t values (-1); +insert into t1 values (18446744073709551615); +select * from t , t1 where t.c1 = t1.c1; +c1 c1 +drop table if exists t; +drop table if exists t1; +create table t(c1 float); +create table t1(c1 double); +insert into t values (1.0); +insert into t1 values (1.00); +select t.c1 from t , t1 where t.c1 = t1.c1; +c1 +1 +drop table if exists t; +drop table if exists t1; +create table t(c1 varchar(1)); +create table t1(c1 char(1)); +insert into t values ("x"); +insert into t1 values ("x"); +select t.c1 from t , t1 where t.c1 = t1.c1; +c1 +x +drop table if exists t; +drop table if exists t1; +create table t(c1 varchar(1)); +create table t1(c1 char(1)); +insert into t values ("x"); +insert into t1 values ("y"); +select t.c1 from t , t1 where t.c1 = t1.c1; +c1 +drop table if exists t; +drop table if exists t1; +create table t(c1 int,c2 double); +create table t1(c1 double,c2 int); +insert into t values (1, 2), (1, NULL); +insert into t1 values (1, 2), (1, NULL); +select * from t a , t1 b where (a.c1, a.c2) = (b.c1, b.c2); +c1 c2 c1 c2 +1 2 1 2 +drop table if exists t; +drop table if exists t1; +create table t(c1 bigint unsigned); +create table t1(c1 bit(64)); +insert into t value(18446744073709551615); +insert into t1 value(-1); +select * from t, t1 where t.c1 = t1.c1; +c1 c1 +18446744073709551615 ÿÿÿÿÿÿÿÿ +drop table if exists t; +drop table if exists t1; +create table t(c1 bigint); +create table t1(c1 bit(64)); +insert into t value(1); +insert into t1 value(1); +select * from t, t1 where t.c1 = t1.c1; +c1 c1 +1  +drop table if exists t; +drop table if exists t1; +create table t(c1 bigint); +create table t1(c1 bit(64)); +insert into t value(-1); +insert into t1 value(18446744073709551615); +select * from t, t1 where t.c1 = t1.c1; +c1 c1 +drop table if exists t; +drop table if exists t1; +drop table if exists t2; +create table t(c1 bigint); +create table t1(c1 bigint unsigned); +create table t2(c1 Date); +insert into t value(20191111); +insert into t1 value(20191111); +insert into t2 value('2019-11-11'); +select * from t, t1, t2 where t.c1 = t2.c1 and t1.c1 = t2.c1; +c1 c1 c1 +20191111 20191111 2019-11-11 +drop table if exists t; +drop table if exists t1; +drop table if exists t2; +create table t(c1 bigint); +create table t1(c1 bigint unsigned); +create table t2(c1 enum('a', 'b', 'c', 'd')); +insert into t value(3); +insert into t1 value(3); +insert into t2 value('c'); +select * from t, t1, t2 where t.c1 = t2.c1 and t1.c1 = t2.c1; +c1 c1 c1 +3 3 c +drop table if exists t; +drop table if exists t1; +drop table if exists t2; +create table t(c1 bigint); +create table t1(c1 bigint unsigned); +create table t2 (c1 SET('a', 'b', 'c', 'd')); +insert into t value(9); +insert into t1 value(9); +insert into t2 value('a,d'); +select * from t, t1, t2 where t.c1 = t2.c1 and t1.c1 = t2.c1; +c1 c1 c1 +9 9 a,d +drop table if exists t; +drop table if exists t1; +create table t(c1 int); +create table t1(c1 decimal(4,2)); +insert into t values(0), (2); +insert into t1 values(0), (9); +select * from t left join t1 on t1.c1 = t.c1; +c1 c1 +0 0.00 +2 NULL +drop table if exists t; +drop table if exists t1; +create table t(c1 decimal(4,1)); +create table t1(c1 decimal(4,2)); +insert into t values(0), (2); +insert into t1 values(0), (9); +select * from t left join t1 on t1.c1 = t.c1; +c1 c1 +0.0 0.00 +2.0 NULL +drop table if exists t; +drop table if exists t1; +create table t(c1 decimal(4,1)); +create table t1(c1 decimal(4,2)); +create index k1 on t1(c1); +insert into t values(0), (2); +insert into t1 values(0), (9); +select /*+ INL_JOIN(t1) */ * from t left join t1 on t1.c1 = t.c1; +c1 c1 +0.0 0.00 +2.0 NULL +select /*+ INL_HASH_JOIN(t1) */ * from t left join t1 on t1.c1 = t.c1; +c1 c1 +0.0 0.00 +2.0 NULL +select /*+ INL_MERGE_JOIN(t1) */ * from t left join t1 on t1.c1 = t.c1; +c1 c1 +0.0 0.00 +2.0 NULL +drop table if exists t; +drop table if exists t1; +drop table if exists t2; +create table t(c1 char(10)); +create table t1(c1 char(10)); +create table t2(c1 char(10)); +insert into t values('abd'); +insert into t1 values('abc'); +insert into t2 values('abc'); +select * from (select * from t union all select * from t1) t1 join t2 on t1.c1 = t2.c1; +c1 c1 +abc abc +drop table if exists t; +create table t(a varchar(10), index idx(a)); +insert into t values('1'), ('2'), ('3'); +set @@tidb_init_chunk_size=1; +select a from (select /*+ INL_JOIN(t1, t2) */ t1.a from t t1 join t t2 on t1.a=t2.a) t group by a; +a +1 +2 +3 +select a from (select /*+ INL_HASH_JOIN(t1, t2) */ t1.a from t t1 join t t2 on t1.a=t2.a) t group by a; +a +1 +2 +3 +select a from (select /*+ INL_MERGE_JOIN(t1, t2) */ t1.a from t t1 join t t2 on t1.a=t2.a) t group by a; +a +1 +2 +3 +set @@tidb_init_chunk_size=default; +drop table if exists t1, t2, t3, t4; +create table t1 (a int, c int); +create table t2 (a int, d int); +create table t3 (a int); +create table t4 (a int); +insert t1 values (2, 4), (1, 3); +insert t2 values (2, 5), (3, 6); +insert t3 values (1); +select * from t1 join t2 using (a); +a c d +2 4 5 +select t1.a, t2.a from t1 join t2 using (a); +a a +2 2 +select * from t1 right join t2 using (a) order by a; +a d c +2 5 4 +3 6 NULL +select t1.a, t2.a from t1 right join t2 using (a) order by t2.a; +a a +2 2 +NULL 3 +select * from t1 left join t2 using (a) order by a; +a c d +1 3 NULL +2 4 5 +select t1.a, t2.a from t1 left join t2 using (a) order by t1.a; +a a +1 NULL +2 2 +select * from t1 join t2 using (a) right join t3 using (a); +a c d +1 NULL NULL +select * from t1 join t2 using (a) right join t3 on (t2.a = t3.a); +a c d a +NULL NULL NULL 1 +select t2.a from t1 join t2 using (a) right join t3 on (t1.a = t3.a); +a +NULL +select t1.a, t2.a, t3.a from t1 join t2 using (a) right join t3 using (a); +a a a +NULL NULL 1 +select t1.c, t2.d from t1 join t2 using (a) right join t3 using (a); +c d +NULL NULL +alter table t1 add column b int default 1 after a; +alter table t2 add column b int default 1 after a; +select * from t1 join t2 using (b, a); +a b c d +2 1 4 5 +select * from (t1 join t2 using (a)) join (t3 join t4 using (a)) on (t2.a = t4.a and t1.a = t3.a); +a b c b d a +drop table if exists t, tt; +create table t(a int, b int); +create table tt(b int, a int); +insert into t (a, b) values(1, 1); +insert into tt (a, b) values(1, 2); +select * from t join tt using(a); +a b b +1 1 2 +drop table if exists t, tt; +create table t(a float, b int); +create table tt(b bigint, a int); +select * from t join tt using(a); +a b b +drop table if exists t, s; +create table t(a int, b int); +create table s(b int, a int); +insert into t values(1,1), (2,2), (3,3), (null,null); +insert into s values(1,1), (3,3), (null,null); +select t.*, s.* from t join s using(a); +a b b a +1 1 1 1 +3 3 3 3 +select s.a from t join s using(a); +a +1 +3 +select s.a from t join s using(a) where s.a > 1; +a +3 +select s.a from t join s using(a) order by s.a; +a +1 +3 +select s.a from t join s using(a) where s.a > 1 order by s.a; +a +3 +select s.a from t join s using(a) where s.a > 1 order by s.a limit 2; +a +3 +DROP TABLE if exists t1, t2, t3; +create table t1 (i int); +create table t2 (i int); +create table t3 (i int); +select * from t1,t2 natural left join t3 order by t1.i,t2.i,t3.i; +i i +select t1.i,t2.i,t3.i from t2 natural left join t3,t1 order by t1.i,t2.i,t3.i; +i i i +select * from t1,t2 natural right join t3 order by t1.i,t2.i,t3.i; +i i +select t1.i,t2.i,t3.i from t2 natural right join t3,t1 order by t1.i,t2.i,t3.i; +i i i +DROP TABLE if exists t0, t1; +CREATE TABLE t0(c0 INT); +CREATE TABLE t1(c0 INT); +SELECT t0.c0 FROM t0 NATURAL RIGHT JOIN t1 WHERE t1.c0; +c0 +DROP TABLE if exists t1, t2; +create table t1(id int, name varchar(20)); +create table t2(id int, address varchar(30)); +insert into t1 values(1,'gangshen'); +insert into t2 values(1,'HangZhou'); +select t2.* from t1 inner join t2 using (id) limit 1; +id address +1 HangZhou +select t2.* from t1 inner join t2 on t1.id = t2.id limit 1; +id address +1 HangZhou +drop table if exists t1; +create table t1(a int); +insert into t1 (a) values(1); +select t1.*, t2.* from t1 join t1 t2 using(a); +a a +1 1 +select * from t1 join t1 t2 using(a); +a +1 +drop table t; +CREATE TABLE t ( a varchar(55) NOT NULL, b varchar(55) NOT NULL, c int(11) DEFAULT NULL, d int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +update t t1 join t t2 using(a,b) set t1.c=t2.d; +DROP TABLE if exists t1,t2,t3,t4,t5; +CREATE TABLE t1 (a INT, b INT); +CREATE TABLE t2 (a INT, b INT); +CREATE TABLE t3 (a INT, b INT); +INSERT INTO t1 VALUES (1,1); +INSERT INTO t2 VALUES (1,1); +INSERT INTO t3 VALUES (1,1); +SELECT * FROM t1 JOIN (t2 JOIN t3 USING (b)) USING (a); +Error 1052 (23000): Column 'a' in from clause is ambiguous +drop table if exists t1,t2; +create table t1 (t1 int , t0 int); +create table t2 (t2 int, t0 int); +insert into t1 select 11, 1; +insert into t2 select 22, 1; +select t1.t0, t2.t0 from t1 join t2 using(t0) group by t1.t0; +t0 t0 +1 1 +select t1.t0, t2.t0 from t1 join t2 using(t0) having t1.t0 > 0; +t0 t0 +1 1 +set @@tidb_hash_join_concurrency=1; +set @@tidb_hashagg_partial_concurrency=1; +set @@tidb_hashagg_final_concurrency=1; +drop table if exists t; +create table t (c int, d int); +begin; +insert t values (1, 1); +insert t values (2, 2); +insert t values (3, 4); +commit; +set sql_mode = 'STRICT_TRANS_TABLES'; +select * from t where exists(select * from t k where t.c = k.c having sum(c) = 1); +c d +1 1 +select * from t where exists(select k.c, k.d from t k, t p where t.c = k.d); +c d +1 1 +2 2 +select 1 = (select count(*) from t where t.c = k.d) from t k; +1 = (select count(*) from t where t.c = k.d) +1 +1 +0 +select 1 = (select count(*) from t where exists( select * from t m where t.c = k.d)) from t k; +1 = (select count(*) from t where exists( select * from t m where t.c = k.d)) +0 +1 +1 +select t.c = any (select count(*) from t) from t; +t.c = any (select count(*) from t) +0 +0 +1 +select * from t where (t.c, 6) = any (select count(*), sum(t.c) from t); +c d +3 4 +select t.c from t where (t.c) < all (select count(*) from t); +c +1 +2 +select t.c from t where (t.c, t.d) = any (select * from t); +c +1 +2 +3 +select t.c from t where (t.c, t.d) != all (select * from t); +c +select (select count(*) from t where t.c = k.d) from t k; +(select count(*) from t where t.c = k.d) +0 +1 +1 +select t.c from t where (t.c, t.d) in (select * from t); +c +1 +2 +3 +select t.c from t where (t.c, t.d) not in (select * from t); +c +select * from t A inner join t B on A.c = B.c and A.c > 100; +c d c d +select t.c from t where (t.c, t.d) != all (select * from t where d > 1000); +c +1 +2 +3 +select t.c from t where (t.c) < any (select c from t where d > 1000); +c +insert t values (NULL, NULL); +select (t.c) < any (select c from t) from t; +(t.c) < any (select c from t) +NULL +NULL +1 +1 +select (10) > all (select c from t) from t; +(10) > all (select c from t) +NULL +NULL +NULL +NULL +select (c) > all (select c from t) from t; +(c) > all (select c from t) +0 +0 +0 +NULL +drop table if exists a; +create table a (c int, d int); +insert a values (1, 2); +drop table if exists b; +create table b (c int, d int); +insert b values (2, 1); +select * from a b where c = (select d from b a where a.c = 2 and b.c = 1); +c d +1 2 +drop table if exists t; +create table t(c int); +insert t values(10), (8), (7), (9), (11); +select * from t where 9 in (select c from t s where s.c < t.c limit 3); +c +10 +drop table if exists t; +create table t(id int, v int); +insert into t values(1, 1), (2, 2), (3, 3); +select * from t where v=(select min(t1.v) from t t1, t t2, t t3 where t1.id=t2.id and t2.id=t3.id and t1.id=t.id); +id v +1 1 +2 2 +3 3 +select exists (select t.id from t where s.id < 2 and t.id = s.id) from t s; +exists (select t.id from t where s.id < 2 and t.id = s.id) +1 +0 +0 +drop table if exists t; +create table t(c int); +select exists(select count(*) from t); +exists(select count(*) from t) +1 +drop table if exists t; +create table t(id int primary key, v int); +insert into t values(1, 1), (2, 2), (3, 3); +select (select t.id from t where s.id < 2 and t.id = s.id) from t s; +(select t.id from t where s.id < 2 and t.id = s.id) +NULL +NULL +1 +select (select t.id from t where t.id = t.v and t.v != s.id) from t s; +Error 1242 (21000): Subquery returns more than 1 row +drop table if exists t; +drop table if exists s; +create table t(id int); +create table s(id int); +insert into t values(1), (2); +insert into s values(2), (2); +select id from t where(select count(*) from s where s.id = t.id) > 0; +id +2 +select *, (select count(*) from s where id = t.id limit 1, 1) from t; +id (select count(*) from s where id = t.id limit 1, 1) +1 NULL +2 NULL +drop table if exists t; +drop table if exists s; +create table t(id int primary key); +create table s(id int); +insert into t values(1), (2); +insert into s values(2), (2); +select *, (select count(id) from s where id = t.id) from t; +id (select count(id) from s where id = t.id) +1 0 +2 2 +select *, 0 < any (select count(id) from s where id = t.id) from t; +id 0 < any (select count(id) from s where id = t.id) +1 0 +2 1 +select (select count(*) from t k where t.id = id) from s, t where t.id = s.id limit 1; +(select count(*) from t k where t.id = id) +1 +drop table if exists t, s; +create table t(id int primary key); +create table s(id int, index k(id)); +insert into t values(1), (2); +insert into s values(2), (2); +select (select id from s where s.id = t.id order by s.id limit 1) from t; +(select id from s where s.id = t.id order by s.id limit 1) +NULL +2 +drop table if exists t, s; +create table t(id int); +create table s(id int); +insert into t values(2), (2); +insert into s values(2); +select (select id from s where s.id = t.id order by s.id) from t; +(select id from s where s.id = t.id order by s.id) +2 +2 +drop table if exists t; +create table t(dt datetime); +select (select 1 from t where DATE_FORMAT(o.dt,'%Y-%m')) from t o; +(select 1 from t where DATE_FORMAT(o.dt,'%Y-%m')) +drop table if exists t1, t2; +create table t1(f1 int, f2 int); +create table t2(fa int, fb int); +insert into t1 values (1,1),(1,1),(1,2),(1,2),(1,2),(1,3); +insert into t2 values (1,1),(1,2),(1,3); +select f1,f2 from t1 group by f1,f2 having count(1) >= all (select fb from t2 where fa = f1); +f1 f2 +1 2 +DROP TABLE IF EXISTS t1, t2; +CREATE TABLE t1(a INT); +CREATE TABLE t2 (d BINARY(2), PRIMARY KEY (d(1)), UNIQUE KEY (d)); +INSERT INTO t1 values(1); +SELECT 1 FROM executor__jointest__join.t1, executor__jointest__join.t2 WHERE 1 = (SELECT executor__jointest__join.t2.d FROM executor__jointest__join.t2 WHERE executor__jointest__join.t1.a >= 1) and executor__jointest__join.t2.d = 1; +1 +DROP TABLE IF EXISTS t1; +CREATE TABLE t1(a int, b int default 0); +create index k1 on t1(a); +INSERT INTO t1 (a) values(1), (2), (3), (4), (5); +select (select /*+ INL_JOIN(x2) */ x2.a from t1 x1, t1 x2 where x1.a = t1.a and x1.a = x2.a) from t1; +(select /*+ INL_JOIN(x2) x2.a from t1 x1, t1 x2 where x1.a = t1.a and x1.a = x2.a) +1 +2 +3 +4 +5 +select (select /*+ INL_HASH_JOIN(x2) */ x2.a from t1 x1, t1 x2 where x1.a = t1.a and x1.a = x2.a) from t1; +(select /*+ INL_HASH_JOIN(x2) x2.a from t1 x1, t1 x2 where x1.a = t1.a and x1.a = x2.a) +1 +2 +3 +4 +5 +select (select /*+ INL_MERGE_JOIN(x2) */ x2.a from t1 x1, t1 x2 where x1.a = t1.a and x1.a = x2.a) from t1; +(select /*+ INL_MERGE_JOIN(x2) x2.a from t1 x1, t1 x2 where x1.a = t1.a and x1.a = x2.a) +1 +2 +3 +4 +5 +select 1 from (select t1.a in (select t1.a from t1) from t1) x; +1 +1 +1 +1 +1 +1 +select 1 from (select t1.a not in (select t1.a from t1) from t1) x; +1 +1 +1 +1 +1 +1 +drop table if exists t1, t2; +create table t1(a int); +create table t2(b int); +insert into t1 values(1); +insert into t2 values(1); +select * from t1 where a in (select a from t2); +a +1 +insert into t2 value(null); +select * from t1 where 1 in (select b from t2); +a +1 +select * from t1 where 1 not in (select b from t2); +a +select * from t1 where 2 not in (select b from t2); +a +select * from t1 where 2 in (select b from t2); +a +select 1 in (select b from t2) from t1; +1 in (select b from t2) +1 +select 1 in (select 1 from t2) from t1; +1 in (select 1 from t2) +1 +select 1 not in (select b from t2) from t1; +1 not in (select b from t2) +0 +select 1 not in (select 1 from t2) from t1; +1 not in (select 1 from t2) +0 +delete from t2 where b=1; +select 1 in (select b from t2) from t1; +1 in (select b from t2) +NULL +select 1 not in (select b from t2) from t1; +1 not in (select b from t2) +NULL +select 1 not in (select 1 from t2) from t1; +1 not in (select 1 from t2) +0 +select 1 in (select 1 from t2) from t1; +1 in (select 1 from t2) +1 +select 1 not in (select null from t1) from t2; +1 not in (select null from t1) +NULL +select 1 in (select null from t1) from t2; +1 in (select null from t1) +NULL +drop table if exists s; +create table s(a int not null, b int); +set sql_mode = ''; +select (2,0) in (select s.a, min(s.b) from s) as f; +f +NULL +select (2,0) not in (select s.a, min(s.b) from s) as f; +f +NULL +select (2,0) = any (select s.a, min(s.b) from s) as f; +f +NULL +select (2,0) != all (select s.a, min(s.b) from s) as f; +f +NULL +select (2,0) in (select s.b, min(s.b) from s) as f; +f +NULL +select (2,0) not in (select s.b, min(s.b) from s) as f; +f +NULL +select (2,0) = any (select s.b, min(s.b) from s) as f; +f +NULL +select (2,0) != all (select s.b, min(s.b) from s) as f; +f +NULL +insert into s values(1,null); +select 1 in (select b from s); +1 in (select b from s) +NULL +drop table if exists t; +create table t(a int); +insert into t values(1),(null); +select a not in (select 1) from t; +a not in (select 1) +0 +NULL +select 1 not in (select null from t t1) from t; +1 not in (select null from t t1) +NULL +NULL +select 1 in (select null from t t1) from t; +1 in (select null from t t1) +NULL +NULL +select a in (select 0) xx from (select null as a) x; +xx +NULL +drop table t; +create table t(a int, b int); +insert into t values(1,null),(null, null),(null, 2); +select * from t t1 where (2 in (select a from t t2 where (t2.b=t1.b) is null)); +a b +select (t2.a in (select t1.a from t t1)) is true from t t2; +(t2.a in (select t1.a from t t1)) is true +0 +0 +1 +set sql_mode=default; +set @@tidb_hash_join_concurrency=default; +set @@tidb_hashagg_partial_concurrency=default; +set @@tidb_hashagg_final_concurrency=default; diff --git a/tests/integrationtest/r/executor/set.result b/tests/integrationtest/r/executor/set.result index 1482cac01daa4..8f7242b177866 100644 --- a/tests/integrationtest/r/executor/set.result +++ b/tests/integrationtest/r/executor/set.result @@ -19,3 +19,449 @@ select @@global.tidb_max_delta_schema_count; @@global.tidb_max_delta_schema_count 2048 set @@global.tidb_max_delta_schema_count= default; +SELECT @@query_cache_type; +@@query_cache_type +OFF +SHOW VARIABLES LIKE 'query_cache_type'; +Variable_name Value +query_cache_type OFF +SET query_cache_type=2; +SELECT @@query_cache_type; +@@query_cache_type +DEMAND +SET GLOBAL tidb_enable_noop_variables = OFF; +SELECT @@global.tidb_enable_noop_variables; +@@global.tidb_enable_noop_variables +OFF +SELECT @@query_cache_type; +@@query_cache_type +DEMAND +SHOW WARNINGS; +Level Code Message +Warning 8145 variable query_cache_type has no effect in TiDB +SHOW VARIABLES LIKE 'query_cache_type'; +Variable_name Value +SET query_cache_type = OFF; +SHOW WARNINGS; +Level Code Message +Warning 8144 setting query_cache_type has no effect in TiDB +SELECT @@query_cache_type; +@@query_cache_type +OFF +SET GLOBAL tidb_enable_noop_variables = 2; +Error 1231 (42000): Variable 'tidb_enable_noop_variables' can't be set to the value of '2' +SET GLOBAL tidb_enable_noop_variables = 'warn'; +Error 1231 (42000): Variable 'tidb_enable_noop_variables' can't be set to the value of 'warn' +SET GLOBAL tidb_enable_noop_variables = ON; +SET GLOBAL tidb_enable_noop_variables = default; +SET query_cache_type = default; +show VARIABLES like 'character_set_%'; +Variable_name Value +character_set_client utf8mb4 +character_set_connection utf8mb4 +character_set_database utf8mb4 +character_set_filesystem binary +character_set_results utf8mb4 +character_set_server utf8mb4 +character_set_system utf8 +character_sets_dir /usr/local/mysql-5.6.25-osx10.8-x86_64/share/charsets/ +SET NAMES latin1; +show VARIABLES like 'character_set_%'; +Variable_name Value +character_set_client latin1 +character_set_connection latin1 +character_set_database utf8mb4 +character_set_filesystem binary +character_set_results latin1 +character_set_server utf8mb4 +character_set_system utf8 +character_sets_dir /usr/local/mysql-5.6.25-osx10.8-x86_64/share/charsets/ +SET NAMES default; +show VARIABLES like 'character_set_%'; +Variable_name Value +character_set_client utf8mb4 +character_set_connection utf8mb4 +character_set_database utf8mb4 +character_set_filesystem binary +character_set_results utf8mb4 +character_set_server utf8mb4 +character_set_system utf8 +character_sets_dir /usr/local/mysql-5.6.25-osx10.8-x86_64/share/charsets/ +SET NAMES binary; +show VARIABLES like 'character_set_%'; +Variable_name Value +character_set_client binary +character_set_connection binary +character_set_database utf8mb4 +character_set_filesystem binary +character_set_results binary +character_set_server utf8mb4 +character_set_system utf8 +character_sets_dir /usr/local/mysql-5.6.25-osx10.8-x86_64/share/charsets/ +SET NAMES utf8; +show VARIABLES like 'character_set_%'; +Variable_name Value +character_set_client utf8 +character_set_connection utf8 +character_set_database utf8mb4 +character_set_filesystem binary +character_set_results utf8 +character_set_server utf8mb4 +character_set_system utf8 +character_sets_dir /usr/local/mysql-5.6.25-osx10.8-x86_64/share/charsets/ +SET CHARACTER SET latin1; +show VARIABLES like 'character_set_%'; +Variable_name Value +character_set_client latin1 +character_set_connection utf8mb4 +character_set_database utf8mb4 +character_set_filesystem binary +character_set_results latin1 +character_set_server utf8mb4 +character_set_system utf8 +character_sets_dir /usr/local/mysql-5.6.25-osx10.8-x86_64/share/charsets/ +SET CHARACTER SET default; +show VARIABLES like 'character_set_%'; +Variable_name Value +character_set_client utf8mb4 +character_set_connection utf8mb4 +character_set_database utf8mb4 +character_set_filesystem binary +character_set_results utf8mb4 +character_set_server utf8mb4 +character_set_system utf8 +character_sets_dir /usr/local/mysql-5.6.25-osx10.8-x86_64/share/charsets/ +set names default; +select @@global.max_connections; +@@global.max_connections +0 +select @@max_connections; +@@max_connections +0 +set @@global.max_connections=100; +select @@global.max_connections; +@@global.max_connections +100 +select @@max_connections; +@@max_connections +100 +set @@global.max_connections=0; +select @@invalid; +Error 1193 (HY000): Unknown system variable 'invalid' +select @@global.invalid; +Error 1193 (HY000): Unknown system variable 'invalid' +set @@global.max_connections=default; +SELECT @@default_storage_engine; +@@default_storage_engine +InnoDB +SET GLOBAL default_storage_engine = 'somethingweird'; +SET default_storage_engine = 'MyISAM'; +SELECT @@default_storage_engine; +@@default_storage_engine +MyISAM +SET default_storage_engine = DEFAULT; +SELECT @@default_storage_engine; +@@default_storage_engine +somethingweird +SET @@SESSION.default_storage_engine = @@GLOBAL.default_storage_engine; +SELECT @@default_storage_engine; +@@default_storage_engine +somethingweird +SET GLOBAL default_storage_engine = 'somethingweird2'; +SET default_storage_engine = @@GLOBAL.default_storage_engine; +SELECT @@default_storage_engine; +@@default_storage_engine +somethingweird2 +SET default_storage_engine = DEFAULT; +SET GLOBAL default_storage_engine = DEFAULT; +SELECT @@SESSION.default_storage_engine, @@GLOBAL.default_storage_engine; +@@SESSION.default_storage_engine @@GLOBAL.default_storage_engine +somethingweird2 InnoDB +SET GLOBAL sql_mode = 'DEFAULT'; +Error 1105 (HY000): ERROR 1231 (42000): Variable 'sql_mode' can't be set to the value of 'DEFAULT' +SET GLOBAL sql_mode = DEFAULT; +set @@SESSION.default_storage_engine=default; +SET GLOBAL default_storage_engine=default; +SET GLOBAL tidb_restricted_read_only = ON; +SELECT @@GLOBAL.tidb_super_read_only; +@@GLOBAL.tidb_super_read_only +1 +SET GLOBAL tidb_super_read_only = OFF; +Error 1105 (HY000): can't turn off tidb_super_read_only when tidb_restricted_read_only is on +SET GLOBAL tidb_restricted_read_only = OFF; +SELECT @@GLOBAL.tidb_restricted_read_only; +@@GLOBAL.tidb_restricted_read_only +0 +SELECT @@GLOBAL.tidb_super_read_only; +@@GLOBAL.tidb_super_read_only +1 +SET GLOBAL tidb_super_read_only = OFF; +SELECT @@GLOBAL.tidb_super_read_only; +@@GLOBAL.tidb_super_read_only +0 +SET GLOBAL tidb_super_read_only = default; +SET GLOBAL tidb_restricted_read_only = default; +SET tidb_enable_global_temporary_table = 1; +SET tidb_slow_log_masking = 1; +SET GLOBAL tidb_enable_global_temporary_table = 1; +SET GLOBAL tidb_slow_log_masking = 1; +SELECT @@tidb_slow_log_masking; +Error 8136 (HY000): option 'tidb_slow_log_masking' is no longer supported. Reason: use tidb_redact_log instead +SELECT @@tidb_enable_global_temporary_table; +Error 8136 (HY000): option 'tidb_enable_global_temporary_table' is no longer supported. Reason: temporary table support is now always enabled +SET tidb_enable_global_temporary_table = default; +SET tidb_slow_log_masking = default; +SET GLOBAL tidb_enable_global_temporary_table = default; +SET GLOBAL tidb_slow_log_masking = default; +select @@global.tidb_session_plan_cache_size; +@@global.tidb_session_plan_cache_size +100 +SET GLOBAL tidb_session_plan_cache_size = 0; +show warnings; +Level Code Message +Warning 1292 Truncated incorrect tidb_session_plan_cache_size value: '0' +select @@global.tidb_session_plan_cache_size; +@@global.tidb_session_plan_cache_size +1 +SET GLOBAL tidb_session_plan_cache_size = 2; +select @@global.tidb_session_plan_cache_size; +@@global.tidb_session_plan_cache_size +2 +select @@session.tidb_session_plan_cache_size; +@@session.tidb_session_plan_cache_size +100 +SET SESSION tidb_session_plan_cache_size = 0; +show warnings; +Level Code Message +Warning 1292 Truncated incorrect tidb_session_plan_cache_size value: '0' +select @@session.tidb_session_plan_cache_size; +@@session.tidb_session_plan_cache_size +1 +SET SESSION tidb_session_plan_cache_size = 2; +select @@session.tidb_session_plan_cache_size; +@@session.tidb_session_plan_cache_size +2 +SET GLOBAL tidb_prepared_plan_cache_memory_guard_ratio = -0.1; +show warnings; +Level Code Message +Warning 1292 Truncated incorrect tidb_prepared_plan_cache_memory_guard_ratio value: '-0.1' +select @@global.tidb_prepared_plan_cache_memory_guard_ratio; +@@global.tidb_prepared_plan_cache_memory_guard_ratio +0 +SET GLOBAL tidb_prepared_plan_cache_memory_guard_ratio = 2.2; +show warnings; +Level Code Message +Warning 1292 Truncated incorrect tidb_prepared_plan_cache_memory_guard_ratio value: '2.2' +select @@global.tidb_prepared_plan_cache_memory_guard_ratio; +@@global.tidb_prepared_plan_cache_memory_guard_ratio +1 +SET GLOBAL tidb_prepared_plan_cache_memory_guard_ratio = 0.5; +select @@global.tidb_prepared_plan_cache_memory_guard_ratio; +@@global.tidb_prepared_plan_cache_memory_guard_ratio +0.5 +SET GLOBAL tidb_enable_prepared_plan_cache = 0; +select @@global.tidb_enable_prepared_plan_cache; +@@global.tidb_enable_prepared_plan_cache +0 +SET GLOBAL tidb_enable_prepared_plan_cache = 1; +select @@global.tidb_enable_prepared_plan_cache; +@@global.tidb_enable_prepared_plan_cache +1 +SET GLOBAL tidb_enable_prepared_plan_cache = 0; +select @@global.tidb_enable_prepared_plan_cache; +@@global.tidb_enable_prepared_plan_cache +0 +SET GLOBAL tidb_enable_prepared_plan_cache = default; +SET GLOBAL tidb_prepared_plan_cache_memory_guard_ratio = default; +SET SESSION tidb_session_plan_cache_size = default; +SET GLOBAL tidb_session_plan_cache_size = default; +set tidb_enable_legacy_instance_scope = 1; +set tidb_general_log = 1; +show warnings; +Level Code Message +Warning 8142 modifying tidb_general_log will require SET GLOBAL in a future version of TiDB +set tidb_enable_legacy_instance_scope = 0; +set tidb_general_log = 1; +Error 1229 (HY000): Variable 'tidb_general_log' is a GLOBAL variable and should be set with SET GLOBAL +set tidb_enable_legacy_instance_scope = default; +set tidb_general_log = default; +set global tidb_gc_max_wait_time = 1000; +set global tidb_gc_life_time = "72h"; +set global tidb_gc_life_time = "24h"; +set global tidb_gc_life_time = "10m"; +set global tidb_gc_max_wait_time = 86400; +set global tidb_gc_life_time = "72h"; +set global tidb_gc_max_wait_time = 1000; +set global tidb_gc_life_time = default; +set global tidb_gc_max_wait_time = default; +select @@tiflash_fine_grained_shuffle_stream_count; +@@tiflash_fine_grained_shuffle_stream_count +0 +set @@tiflash_fine_grained_shuffle_stream_count = 0; +select @@tiflash_fine_grained_shuffle_stream_count; +@@tiflash_fine_grained_shuffle_stream_count +0 +set @@tiflash_fine_grained_shuffle_stream_count = -2; +select @@tiflash_fine_grained_shuffle_stream_count; +@@tiflash_fine_grained_shuffle_stream_count +-1 +set @@tiflash_fine_grained_shuffle_stream_count = 0; +select @@tiflash_fine_grained_shuffle_stream_count; +@@tiflash_fine_grained_shuffle_stream_count +0 +set @@tiflash_fine_grained_shuffle_stream_count = 1024; +select @@tiflash_fine_grained_shuffle_stream_count; +@@tiflash_fine_grained_shuffle_stream_count +1024 +set @@tiflash_fine_grained_shuffle_stream_count = 1025; +select @@tiflash_fine_grained_shuffle_stream_count; +@@tiflash_fine_grained_shuffle_stream_count +1024 +select @@tiflash_fine_grained_shuffle_batch_size; +@@tiflash_fine_grained_shuffle_batch_size +8192 +set @@tiflash_fine_grained_shuffle_batch_size = 0; +select @@tiflash_fine_grained_shuffle_batch_size; +@@tiflash_fine_grained_shuffle_batch_size +1 +set @@tiflash_fine_grained_shuffle_batch_size = -1; +select @@tiflash_fine_grained_shuffle_batch_size; +@@tiflash_fine_grained_shuffle_batch_size +1 +set @@tiflash_fine_grained_shuffle_batch_size = 18446744073709551615; +select @@tiflash_fine_grained_shuffle_batch_size; +@@tiflash_fine_grained_shuffle_batch_size +18446744073709551615 +set global tiflash_fine_grained_shuffle_stream_count = -1; +set global tiflash_fine_grained_shuffle_batch_size = 8192; +set @@tiflash_fine_grained_shuffle_batch_size = default; +set @@tiflash_fine_grained_shuffle_stream_count = default; +set global tiflash_fine_grained_shuffle_stream_count = default; +set global tiflash_fine_grained_shuffle_batch_size = default; +drop table if exists t; +create table t(a int); +insert into t values(1); +select @@session.tiflash_fastscan; +@@session.tiflash_fastscan +0 +select @@global.tiflash_fastscan; +@@global.tiflash_fastscan +0 +set @@tiflash_fastscan=ON; +select @@session.tiflash_fastscan; +@@session.tiflash_fastscan +1 +set global tiflash_fastscan=OFF; +select @@global.tiflash_fastscan; +@@global.tiflash_fastscan +0 +set global tiflash_fastscan=default; +set @@tiflash_fastscan=default; +select @@session.tidb_enable_prepared_plan_cache_memory_monitor; +@@session.tidb_enable_prepared_plan_cache_memory_monitor +1 +select @@global.tidb_enable_prepared_plan_cache_memory_monitor; +@@global.tidb_enable_prepared_plan_cache_memory_monitor +1 +set @@session.tidb_enable_prepared_plan_cache_memory_monitor=OFF; +select @@session.tidb_enable_prepared_plan_cache_memory_monitor; +@@session.tidb_enable_prepared_plan_cache_memory_monitor +0 +set @@session.tidb_enable_prepared_plan_cache_memory_monitor=1; +select @@session.tidb_enable_prepared_plan_cache_memory_monitor; +@@session.tidb_enable_prepared_plan_cache_memory_monitor +1 +set @@global.tidb_enable_prepared_plan_cache_memory_monitor=off; +select @@global.tidb_enable_prepared_plan_cache_memory_monitor; +@@global.tidb_enable_prepared_plan_cache_memory_monitor +0 +set @@session.tidb_enable_prepared_plan_cache_memory_monitor=default; +set @@global.tidb_enable_prepared_plan_cache_memory_monitor=default; +set @@tidb_enable_reuse_chunk=ON; +select @@session.tidb_enable_reuse_chunk; +@@session.tidb_enable_reuse_chunk +1 +set GLOBAL tidb_enable_reuse_chunk=ON; +select @@global.tidb_enable_reuse_chunk; +@@global.tidb_enable_reuse_chunk +1 +set @@tidb_enable_reuse_chunk=OFF; +select @@session.tidb_enable_reuse_chunk; +@@session.tidb_enable_reuse_chunk +0 +set GLOBAL tidb_enable_reuse_chunk=OFF; +select @@global.tidb_enable_reuse_chunk; +@@global.tidb_enable_reuse_chunk +0 +set @@tidb_enable_reuse_chunk=s; +Error 1231 (42000): Variable 'tidb_enable_reuse_chunk' can't be set to the value of 's' +set @@tidb_enable_reuse_chunk=default; +set GLOBAL tidb_enable_reuse_chunk=default; +select @@session.mpp_version; +@@session.mpp_version +UNSPECIFIED +SET SESSION mpp_version = -1; +select @@session.mpp_version; +@@session.mpp_version +-1 +SET SESSION mpp_version = 0; +select @@session.mpp_version; +@@session.mpp_version +0 +SET SESSION mpp_version = 1; +select @@session.mpp_version; +@@session.mpp_version +1 +SET SESSION mpp_version = 2; +select @@session.mpp_version; +@@session.mpp_version +2 +SET SESSION mpp_version = unspecified; +select @@session.mpp_version; +@@session.mpp_version +unspecified +SET SESSION mpp_version = 3; +Error 1105 (HY000): incorrect value: 3. mpp_version options: -1 (unspecified), 0, 1, 2 +SET GLOBAL mpp_version = 1; +select @@global.mpp_version; +@@global.mpp_version +1 +SET GLOBAL mpp_version = -1; +select @@global.mpp_version; +@@global.mpp_version +-1 +SET SESSION mpp_version = default; +set global mpp_version = default; +SET SESSION mpp_exchange_compression_mode = 123; +Error 1105 (HY000): incorrect value: `123`. mpp_exchange_compression_mode options: NONE, FAST, HIGH_COMPRESSION, UNSPECIFIED +select @@session.mpp_exchange_compression_mode; +@@session.mpp_exchange_compression_mode +UNSPECIFIED +SET SESSION mpp_exchange_compression_mode = none; +select @@session.mpp_exchange_compression_mode; +@@session.mpp_exchange_compression_mode +none +SET SESSION mpp_exchange_compression_mode = fast; +select @@session.mpp_exchange_compression_mode; +@@session.mpp_exchange_compression_mode +fast +SET SESSION mpp_exchange_compression_mode = HIGH_COMPRESSION; +select @@session.mpp_exchange_compression_mode; +@@session.mpp_exchange_compression_mode +HIGH_COMPRESSION +SET GLOBAL mpp_exchange_compression_mode = none; +select @@global.mpp_exchange_compression_mode; +@@global.mpp_exchange_compression_mode +none +SET mpp_version = 0; +SET mpp_exchange_compression_mode = unspecified; +SET mpp_version = 0; +SET mpp_exchange_compression_mode = HIGH_COMPRESSION; +SET mpp_version = default; +SET mpp_exchange_compression_mode = default; +set @@global.mpp_exchange_compression_mode = default; +set @@global.tidb_enable_tiflash_pipeline_model = 1; +show warnings; +Level Code Message +Warning 1681 tidb_enable_tiflash_pipeline_model is deprecated and will be removed in a future release. +set @@global.tidb_enable_tiflash_pipeline_model = default; diff --git a/tests/integrationtest/r/executor/write.result b/tests/integrationtest/r/executor/write.result index 9916eff8e9f64..8b29d6f07b1ef 100644 --- a/tests/integrationtest/r/executor/write.result +++ b/tests/integrationtest/r/executor/write.result @@ -1888,3 +1888,98 @@ update t force index(primary) set b = 10 where a = '2023-06-11 10:00:00'; admin check table t; drop table if exists t; +drop table if exists t_securities; +create table t_securities(id bigint not null auto_increment primary key, security_id varchar(8), market_id smallint, security_type int, unique key uu(security_id, market_id)); +insert into t_securities (security_id, market_id, security_type) values ("1", 2, 7), ("7", 1, 7) ON DUPLICATE KEY UPDATE security_type = VALUES(security_type); +replace into t_securities (security_id, market_id, security_type) select security_id+1, 1, security_type from t_securities where security_id="7"; +INSERT INTO t_securities (security_id, market_id, security_type) values ("1", 2, 7), ("7", 1, 7) ON DUPLICATE KEY UPDATE security_type = VALUES(security_type); +select * from t_securities; +id security_id market_id security_type +1 1 2 7 +2 7 1 7 +3 8 1 7 +insert into t_securities (security_id, market_id, security_type) values ("1", 2, 7), ("7", 1, 7) ON DUPLICATE KEY UPDATE security_type = VALUES(security_type); +insert into t_securities (security_id, market_id, security_type) select security_id+2, 1, security_type from t_securities where security_id="7"; +INSERT INTO t_securities (security_id, market_id, security_type) values ("1", 2, 7), ("7", 1, 7) ON DUPLICATE KEY UPDATE security_type = VALUES(security_type); +select * from t_securities; +id security_id market_id security_type +1 1 2 7 +2 7 1 7 +3 8 1 7 +8 9 1 7 +set @@session.tidb_enable_list_partition = ON; +drop table if exists t; +create table t (a bigint key auto_random (3), b int) partition by list (a%5) (partition p0 values in (0,1,2), partition p1 values in (3,4)); +set @@allow_auto_random_explicit_insert = true; +replace into t values (1,1); +insert into t (b) values (2); +insert into t (b) values (3); +insert into t (b) values (4); +insert into t (b) values (5); +insert into t (b) values (6); +insert into t (b) values (7); +insert into t (b) values (8); +insert into t (b) values (9); +select b from t order by b; +b +1 +2 +3 +4 +5 +6 +7 +8 +9 +update t set b=b+1 where a=1; +select b from t where a=1; +b +2 +update t set b=b+1 where a<2; +select b from t where a<2; +b +3 +insert into t values (1, 1) on duplicate key update b=b+1; +select b from t where a=1; +b +4 +set @@session.tidb_enable_list_partition = default; +set @@allow_auto_random_explicit_insert = default; +set @@session.tidb_enable_list_partition = ON; +drop table if exists t; +create table t (a bigint key auto_increment, b int) partition by list (a%5) (partition p0 values in (0,1,2), partition p1 values in (3,4)); +set @@allow_auto_random_explicit_insert = true; +replace into t values (1,1); +insert into t (b) values (2); +insert into t (b) values (3); +insert into t (b) values (4); +insert into t (b) values (5); +insert into t (b) values (6); +insert into t (b) values (7); +insert into t (b) values (8); +insert into t (b) values (9); +select b from t order by b; +b +1 +2 +3 +4 +5 +6 +7 +8 +9 +update t set b=b+1 where a=1; +select b from t where a=1; +b +2 +update t set b=b+1 where a<2; +select b from t where a<2; +b +3 +insert into t values (1, 1) on duplicate key update b=b+1; +select b from t where a=1; +b +4 +set @@session.tidb_enable_list_partition = default; +set @@allow_auto_random_explicit_insert = default; diff --git a/tests/integrationtest/t/executor/ddl.test b/tests/integrationtest/t/executor/ddl.test index eaf74e6c96767..c3c3ac8169b7c 100644 --- a/tests/integrationtest/t/executor/ddl.test +++ b/tests/integrationtest/t/executor/ddl.test @@ -237,3 +237,299 @@ CREATE TABLE t_1 (t_id int); ALTER TABLE t_1 ADD FOREIGN KEY fk_t_id(t_id) references t(id); drop table t,t_1; set global tidb_enable_foreign_key=default; + +# TestCreateView +drop table if exists source_table, t1, t2, test_v_nested; +drop view if exists view_t, v, v1, v2, v3, v4, v5, v6, v7, v_nested, v_nested2; +CREATE TABLE source_table (id INT NOT NULL DEFAULT 1, name varchar(255), PRIMARY KEY(id)); +CREATE VIEW view_t AS select id , name from source_table; +-- error 1050 +CREATE VIEW view_t AS select id , name from source_table; +-- error 1146 +create view v1 (c,d) as select a,b from t1; +create table t1 (a int ,b int); +insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10); +create view v1 (c) as select b+1 from t1; +create view v2 as select b+1 from t1; +create view v3 as select b+1 as c from t1; +create view v4 (c) as select b+1 as d from t1; +create view v5 as select * from t1; +create view v6 (c,d) as select * from t1; +-- error 1353 +create view v7 (c,d,e) as select * from t1; +drop view v1,v2,v3,v4,v5,v6; +create view v1 (c,d) as select a,b+@@global.max_user_connections from t1; +-- error 1050 +create view v1 (c,d) as select a,b from t1 where a = @@global.max_user_connections; +drop view v1; +-- error 1353 +create view v1 (c,d,e) as select a,b from t1 ; +-- error 1353 +create view v1 (c) as select a,b from t1 ; +drop view if exists v1; +create view v1 (c,d) as select a,b from t1; +create or replace view v1 (c,d) as select a,b from t1 ; +create table if not exists t1 (a int ,b int); +-- error 1347 +create or replace view t1 as select * from t1; +prepare stmt from "create view v10 (x) as select 1"; +execute stmt; +drop table if exists t1, t2; +drop view if exists v; +-- error 1146 +create view v as select * from t1 union select * from t2; +create table t1(a int, b int); +create table t2(a int, b int); +insert into t1 values(1,2), (1,1), (1,2); +insert into t2 values(1,1),(1,3); +create definer='root'@'localhost' view v as select * from t1 union select * from t2; +--sorted_result +select * from v; +alter table t1 drop column a; +-- error 1356 +select * from v; +alter table t1 add column a int; +--sorted_result +select * from v; +alter table t1 drop column a; +alter table t2 drop column b; +-- error 1356 +select * from v; +drop view v; +create view v as (select * from t1); +drop view v; +create view v as (select * from t1 union select * from t2); +drop view v; +drop view if exists v_if_exists; +show warnings; +create view v1_if_exists as (select * from t1); +drop view if exists v1_if_exists,v2_if_exists,v3_if_exists; +show warnings; +create table test_v_nested(a int); +create definer='root'@'localhost' view v_nested as select * from test_v_nested; +create definer='root'@'localhost' view v_nested2 as select * from v_nested; +-- error 1146 +create or replace definer='root'@'localhost' view v_nested as select * from v_nested2; +drop table test_v_nested; +drop view v_nested, v_nested2; +## Refer https://github.com/pingcap/tidb/issues/25876 +-- error 1356 +create view v_stale as select * from source_table as of timestamp current_timestamp(3); +## Refer https://github.com/pingcap/tidb/issues/32682 +drop view if exists v1,v2; +drop table if exists t1; +CREATE TABLE t1(a INT, b INT); +-- error 1470 +CREATE DEFINER=1234567890abcdefGHIKL1234567890abcdefGHIKL@localhost VIEW v1 AS SELECT a FROM t1; +-- error 1470 +CREATE DEFINER=some_user_name@host_1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890abcdefghij1234567890X VIEW v2 AS SELECT b FROM t1; +DROP VIEW IF EXISTS view_t; + +# TestCreateViewWithOverlongColName +drop table if exists t; +drop view if exists v; +create table t(a int); +create view v as select distinct'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', max('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'), 'cccccccccc', 'ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'; +select * from v; +select name_exp_1, name_exp_2, cccccccccc, name_exp_4 from v; +show create view v; +drop view v; +CREATE ALGORITHM=UNDEFINED DEFINER=``@`` SQL SECURITY DEFINER VIEW `v` (`name_exp_1`, `name_exp_2`, `cccccccccc`, `name_exp_4`) AS SELECT DISTINCT _UTF8MB4'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' AS `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa`,MAX(_UTF8MB4'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb') AS `max('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb')`,_UTF8MB4'cccccccccc' AS `cccccccccc`,_UTF8MB4'ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd' AS `ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd`; +drop view v ; +create definer='root'@'localhost' view v as select 'a', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' from t union select 'ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc', count(distinct 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'c'); +select * from v; +select a, name_exp_2 from v; +show create view v; +drop view v; +CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` (`a`, `name_exp_2`) AS SELECT _UTF8MB4'a' AS `a`,_UTF8MB4'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' AS `bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb` FROM `executor__ddl`.`t` UNION SELECT _UTF8MB4'ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc' AS `ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc`,COUNT(DISTINCT _UTF8MB4'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', _UTF8MB4'c') AS `count(distinct 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', 'c')`; +drop view v ; +create definer='root'@'localhost' view v as select 'a' as 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' from t; +select * from v; +select name_exp_1 from v; +show create view v; +drop view v; +CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` (`name_exp_1`) AS SELECT _UTF8MB4'a' AS `bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb` FROM `executor__ddl`.`t`; +drop view v ; +-- error 1059 +create view v(`bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb`) as select a from t; +drop table t; + +# TestCreateDropTable +drop table if exists drop_test; +create table if not exists drop_test (a int); +drop table if exists drop_test; +create table drop_test (a int); +drop table drop_test; +-- error 1105 +drop table mysql.gc_delete_range; + +# TestCreateDropView +drop table if exists t_v, t_v1, t_v2; +drop view if exists v; +create or replace view drop_test as select 1,2; +-- error 1051 +drop table drop_test; +drop view if exists drop_test; +-- error 1105 +drop view mysql.gc_delete_range; +-- error 1051 +drop view drop_test; +create table t_v(a int); +-- error 1347 +drop view t_v; +create table t_v1(a int, b int); +create table t_v2(a int, b int); +create view v as select * from t_v1; +create or replace view v as select * from t_v2; +select * from information_schema.views where table_name ='v' and table_schema='executor__ddl'; + +# TestTooLargeIdentifierLength +drop database if exists aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; +create database aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; +drop database aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; +-- error 1059 +create database aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; + +drop table if exists bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; +create table bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(c int); +drop table bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; +-- error 1059 +create table bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(c int); + +drop table if exists t; +create table t(cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc int); +drop table t; +-- error 1059 +create table t(ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc int); + +create table t(c int); +create index dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd on t(c); +drop index dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd on t; +-- error 1059 +create index ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd on t(c); +drop table t; +-- error 1059 +create table t(c int, index ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd(c)); + +# TestIllegalFunctionCall4GeneratedColumns +drop table if exists t1; +-- error 1007 +CREATE database test; +-- error 3102 +create table t1 (b double generated always as (rand()) virtual); +-- error 3102 +create table t1 (a varchar(64), b varchar(1024) generated always as (load_file(a)) virtual); +-- error 3102 +create table t1 (a datetime generated always as (curdate()) virtual); +-- error 3102 +create table t1 (a datetime generated always as (current_time()) virtual); +-- error 3102 +create table t1 (a datetime generated always as (current_timestamp()) virtual); +-- error 3102 +create table t1 (a datetime, b varchar(10) generated always as (localtime()) virtual); +-- error 3102 +create table t1 (a varchar(1024) generated always as (uuid()) virtual); +-- error 3102 +create table t1 (a varchar(1024), b varchar(1024) generated always as (is_free_lock(a)) virtual); +create table t1 (a bigint not null primary key auto_increment, b bigint, c bigint as (b + 1)); +-- error 3102 +alter table t1 add column d varchar(1024) generated always as (database()); +alter table t1 add column d bigint generated always as (b + 1); ; +-- error 3102 +alter table t1 modify column d bigint generated always as (connection_id()); +-- error 3102 +alter table t1 change column c cc bigint generated always as (connection_id()); + +# TestGeneratedColumnRelatedDDL +drop table if exists t1; +-- error 3109 +create table t1 (a bigint not null primary key auto_increment, b bigint as (a + 1)); +create table t1 (a bigint not null primary key auto_increment, b bigint, c bigint as (b + 1)); +-- error 3109 +alter table t1 add column d bigint generated always as (a + 1); +alter table t1 add column d bigint generated always as (b + 1); +-- error 3109 +alter table t1 modify column d bigint generated always as (a + 1); + +## This mysql compatibility check can be disabled using tidb_enable_auto_increment_in_generated +set session tidb_enable_auto_increment_in_generated = 1; +alter table t1 modify column d bigint generated always as (a + 1); +-- error 1054 +alter table t1 add column e bigint as (z + 1); +drop table t1; +create table t1(a int, b int as (a+1), c int as (b+1)); +insert into t1 (a) values (1); +-- error 3107 +alter table t1 modify column c int as (b+1) first; +-- error 3107 +alter table t1 modify column b int as (a+1) after c; +select * from t1; +set session tidb_enable_auto_increment_in_generated = default; + +# TestAutoIncrementColumnErrorMessage +drop table if exists t1; +CREATE TABLE t1 (t1_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY); +-- error 3754 +CREATE INDEX idx1 ON t1 ((t1_id + t1_id)); + +## This mysql compatibility check can be disabled using tidb_enable_auto_increment_in_generated +SET SESSION tidb_enable_auto_increment_in_generated = 1; +CREATE INDEX idx1 ON t1 ((t1_id + t1_id)); +SET SESSION tidb_enable_auto_increment_in_generated = default; + +# TestCheckPrimaryKeyForTTLTable +set tidb_enable_clustered_index=on; +drop table if exists t1, t2, t3, t4, t11, t12, t13, t21, t22, t23; + +## create table should fail when pk contains double/float +-- error 8153 +create table t1(id float primary key, t timestamp) TTL=`t`+INTERVAL 1 DAY; +-- error 8153 +create table t1(id float(10,2) primary key, t timestamp) TTL=`t`+INTERVAL 1 DAY; +-- error 8153 +create table t1(id double primary key, t timestamp) TTL=`t`+INTERVAL 1 DAY; +-- error 8153 +create table t1(id float(10,2) primary key, t timestamp) TTL=`t`+INTERVAL 1 DAY; +-- error 8153 +create table t1(id1 int, id2 float, t timestamp, primary key(id1, id2)) TTL=`t`+INTERVAL 1 DAY; +-- error 8153 +create table t1(id1 int, id2 double, t timestamp, primary key(id1, id2)) TTL=`t`+INTERVAL 1 DAY; + +## alter table should fail when pk contains double/float +create table t1(id float primary key, t timestamp); +create table t2(id double primary key, t timestamp); +create table t3(id1 int, id2 float, primary key(id1, id2), t timestamp); +create table t4(id1 int, id2 double, primary key(id1, id2), t timestamp); +-- error 8153 +alter table t1 TTL=`t`+INTERVAL 1 DAY; +-- error 8153 +alter table t2 TTL=`t`+INTERVAL 1 DAY; +-- error 8153 +alter table t3 TTL=`t`+INTERVAL 1 DAY; +-- error 8153 +alter table t4 TTL=`t`+INTERVAL 1 DAY; + +## create table should not fail when the pk is not clustered +create table t11(id float primary key nonclustered, t timestamp) TTL=`t`+INTERVAL 1 DAY; +create table t12(id double primary key nonclustered, t timestamp) TTL=`t`+INTERVAL 1 DAY; +create table t13(id1 int, id2 float, t timestamp, primary key(id1, id2) nonclustered) TTL=`t`+INTERVAL 1 DAY; + +## alter table should not fail when the pk is not clustered +create table t21(id float primary key nonclustered, t timestamp); +create table t22(id double primary key nonclustered, t timestamp); +create table t23(id1 int, id2 float, t timestamp, primary key(id1, id2) nonclustered); +alter table t21 TTL=`t`+INTERVAL 1 DAY; +alter table t22 TTL=`t`+INTERVAL 1 DAY; +alter table t23 TTL=`t`+INTERVAL 1 DAY; + +set tidb_enable_clustered_index=default; + +# TestInTxnExecDDLInvalid +drop table if exists t; +create table t (c_int int, c_str varchar(40)); +insert into t values (1, 'quizzical hofstadter'); +begin; +select c_int from t where c_str is not null for update; +alter table t add index idx_4 (c_str); +rollback; + diff --git a/tests/integrationtest/t/executor/issues.test b/tests/integrationtest/t/executor/issues.test index 2b078a52e45e5..6b2d1b0d69677 100644 --- a/tests/integrationtest/t/executor/issues.test +++ b/tests/integrationtest/t/executor/issues.test @@ -557,3 +557,67 @@ create table F (id int primary key, col_int int); insert into F values (1, 8); select table1.`col_int` as field1, table1.`col_int` as field2 from V as table1 left join F as table2 on table1.`col_int` = table2.`col_int` order by field1, field2 desc limit 2; +# TestIssue30382 +set tidb_cost_model_version=2; +set @@session.tidb_enable_list_partition = ON; +drop table if exists t1, t2; +create table t1 (c_int int, c_str varchar(40), c_decimal decimal(12, 6), primary key (c_int) , key(c_str(2)) , key(c_decimal) ) partition by list (c_int) ( partition p0 values IN (1, 5, 9, 13, 17, 21, 25, 29, 33, 37), partition p1 values IN (2, 6, 10, 14, 18, 22, 26, 30, 34, 38), partition p2 values IN (3, 7, 11, 15, 19, 23, 27, 31, 35, 39), partition p3 values IN (4, 8, 12, 16, 20, 24, 28, 32, 36, 40)) ; +create table t2 (c_int int, c_str varchar(40), c_decimal decimal(12, 6), primary key (c_int) , key(c_str) , key(c_decimal) ) partition by hash (c_int) partitions 4; +insert into t1 values (6, 'musing mayer', 1.280), (7, 'wizardly heisenberg', 6.589), (8, 'optimistic swirles', 9.633), (9, 'hungry haslett', 2.659), (10, 'stupefied wiles', 2.336); +insert into t2 select * from t1 ; +analyze table t1; +analyze table t2; +begin; +--sorted_result +select * from t1 where c_str <> any (select c_str from t2 where c_decimal < 5) for update; +explain format = 'brief' select * from t1 where c_str <> any (select c_str from t2 where c_decimal < 5) for update; +commit; +set tidb_cost_model_version=default; +set @@session.tidb_enable_list_partition = default; + +# TestFix31537 +drop table if exists trade, trade_history, status_type; +set @@foreign_key_checks=0; +CREATE TABLE trade ( + t_id bigint(16) NOT NULL AUTO_INCREMENT, + t_dts datetime NOT NULL, + t_st_id char(4) NOT NULL, + t_tt_id char(3) NOT NULL, + t_is_cash tinyint(1) NOT NULL, + t_s_symb char(15) NOT NULL, + t_qty mediumint(7) NOT NULL, + t_bid_price decimal(8,2) NOT NULL, + t_ca_id bigint(12) NOT NULL, + t_exec_name varchar(49) NOT NULL, + t_trade_price decimal(8,2) DEFAULT NULL, + t_chrg decimal(10,2) NOT NULL, + t_comm decimal(10,2) NOT NULL, + t_tax decimal(10,2) NOT NULL, + t_lifo tinyint(1) NOT NULL, + PRIMARY KEY (t_id) /*T![clustered_index] CLUSTERED */, + KEY i_t_ca_id_dts (t_ca_id,t_dts), + KEY i_t_s_symb_dts (t_s_symb,t_dts), + CONSTRAINT fk_trade_st FOREIGN KEY (t_st_id) REFERENCES status_type (st_id), + CONSTRAINT fk_trade_tt FOREIGN KEY (t_tt_id) REFERENCES trade_type (tt_id), + CONSTRAINT fk_trade_s FOREIGN KEY (t_s_symb) REFERENCES security (s_symb), + CONSTRAINT fk_trade_ca FOREIGN KEY (t_ca_id) REFERENCES customer_account (ca_id) +) ; +CREATE TABLE trade_history ( + th_t_id bigint(16) NOT NULL, + th_dts datetime NOT NULL, + th_st_id char(4) NOT NULL, + PRIMARY KEY (th_t_id,th_st_id) /*T![clustered_index] NONCLUSTERED */, + KEY i_th_t_id_dts (th_t_id,th_dts), + CONSTRAINT fk_trade_history_t FOREIGN KEY (th_t_id) REFERENCES trade (t_id), + CONSTRAINT fk_trade_history_st FOREIGN KEY (th_st_id) REFERENCES status_type (st_id) +); +; +CREATE TABLE status_type ( + st_id char(4) NOT NULL, + st_name char(10) NOT NULL, + PRIMARY KEY (st_id) /*T![clustered_index] NONCLUSTERED */ +); +--disable_result_log +trace plan SELECT T_ID, T_S_SYMB, T_QTY, ST_NAME, TH_DTS FROM ( SELECT T_ID AS ID FROM TRADE WHERE T_CA_ID = 43000014236 ORDER BY T_DTS DESC LIMIT 10 ) T, TRADE, TRADE_HISTORY, STATUS_TYPE WHERE TRADE.T_ID = ID AND TRADE_HISTORY.TH_T_ID = TRADE.T_ID AND STATUS_TYPE.ST_ID = TRADE_HISTORY.TH_ST_ID ORDER BY TH_DTS DESC LIMIT 30; +--enable_result_log +set @@foreign_key_checks=default; diff --git a/tests/integrationtest/t/executor/jointest/join.test b/tests/integrationtest/t/executor/jointest/join.test index e94d4207335b8..f3a87fe7d9fc0 100644 --- a/tests/integrationtest/t/executor/jointest/join.test +++ b/tests/integrationtest/t/executor/jointest/join.test @@ -586,3 +586,473 @@ insert into t3 values (1, 'A'); select /*+ INL_HASH_JOIN(t3) */ * from t join t3 on t.b = t3.b1; select /*+ INL_JOIN(t3) */ * from t join t3 on t.b = t3.b1; +# TestJoinCast +drop table if exists t; +drop table if exists t1; +create table t(c1 int); +create table t1(c1 int unsigned); +insert into t values (1); +insert into t1 values (1); +select t.c1 from t , t1 where t.c1 = t1.c1; + +## int64(-1) != uint64(18446744073709551615) +drop table if exists t; +drop table if exists t1; +create table t(c1 bigint); +create table t1(c1 bigint unsigned); +insert into t values (-1); +insert into t1 values (18446744073709551615); +select * from t , t1 where t.c1 = t1.c1; + +## float(1) == double(1) +drop table if exists t; +drop table if exists t1; +create table t(c1 float); +create table t1(c1 double); +insert into t values (1.0); +insert into t1 values (1.00); +select t.c1 from t , t1 where t.c1 = t1.c1; + +## varchar("x") == char("x") +drop table if exists t; +drop table if exists t1; +create table t(c1 varchar(1)); +create table t1(c1 char(1)); +insert into t values ("x"); +insert into t1 values ("x"); +select t.c1 from t , t1 where t.c1 = t1.c1; + +## varchar("x") != char("y") +drop table if exists t; +drop table if exists t1; +create table t(c1 varchar(1)); +create table t1(c1 char(1)); +insert into t values ("x"); +insert into t1 values ("y"); +select t.c1 from t , t1 where t.c1 = t1.c1; +drop table if exists t; +drop table if exists t1; +create table t(c1 int,c2 double); +create table t1(c1 double,c2 int); +insert into t values (1, 2), (1, NULL); +insert into t1 values (1, 2), (1, NULL); +select * from t a , t1 b where (a.c1, a.c2) = (b.c1, b.c2); + +## Issue 11895 +drop table if exists t; +drop table if exists t1; +create table t(c1 bigint unsigned); +create table t1(c1 bit(64)); +insert into t value(18446744073709551615); +insert into t1 value(-1); +select * from t, t1 where t.c1 = t1.c1; + +## Issues 11896 +drop table if exists t; +drop table if exists t1; +create table t(c1 bigint); +create table t1(c1 bit(64)); +insert into t value(1); +insert into t1 value(1); +select * from t, t1 where t.c1 = t1.c1; +drop table if exists t; +drop table if exists t1; +create table t(c1 bigint); +create table t1(c1 bit(64)); +insert into t value(-1); +insert into t1 value(18446744073709551615); +## TODO: MySQL will return one row, because c1 in t1 is 0xffffffff, which equals to -1. +select * from t, t1 where t.c1 = t1.c1; + +drop table if exists t; +drop table if exists t1; +drop table if exists t2; +create table t(c1 bigint); +create table t1(c1 bigint unsigned); +create table t2(c1 Date); +insert into t value(20191111); +insert into t1 value(20191111); +insert into t2 value('2019-11-11'); +select * from t, t1, t2 where t.c1 = t2.c1 and t1.c1 = t2.c1; + +drop table if exists t; +drop table if exists t1; +drop table if exists t2; +create table t(c1 bigint); +create table t1(c1 bigint unsigned); +create table t2(c1 enum('a', 'b', 'c', 'd')); +insert into t value(3); +insert into t1 value(3); +insert into t2 value('c'); +select * from t, t1, t2 where t.c1 = t2.c1 and t1.c1 = t2.c1; + +drop table if exists t; +drop table if exists t1; +drop table if exists t2; +create table t(c1 bigint); +create table t1(c1 bigint unsigned); +create table t2 (c1 SET('a', 'b', 'c', 'd')); +insert into t value(9); +insert into t1 value(9); +insert into t2 value('a,d'); +select * from t, t1, t2 where t.c1 = t2.c1 and t1.c1 = t2.c1; + +drop table if exists t; +drop table if exists t1; +create table t(c1 int); +create table t1(c1 decimal(4,2)); +insert into t values(0), (2); +insert into t1 values(0), (9); +select * from t left join t1 on t1.c1 = t.c1; + +drop table if exists t; +drop table if exists t1; +create table t(c1 decimal(4,1)); +create table t1(c1 decimal(4,2)); +insert into t values(0), (2); +insert into t1 values(0), (9); +select * from t left join t1 on t1.c1 = t.c1; + +drop table if exists t; +drop table if exists t1; +create table t(c1 decimal(4,1)); +create table t1(c1 decimal(4,2)); +create index k1 on t1(c1); +insert into t values(0), (2); +insert into t1 values(0), (9); +--sorted_result +select /*+ INL_JOIN(t1) */ * from t left join t1 on t1.c1 = t.c1; +--sorted_result +select /*+ INL_HASH_JOIN(t1) */ * from t left join t1 on t1.c1 = t.c1; +--sorted_result +select /*+ INL_MERGE_JOIN(t1) */ * from t left join t1 on t1.c1 = t.c1; + +drop table if exists t; +drop table if exists t1; +drop table if exists t2; +create table t(c1 char(10)); +create table t1(c1 char(10)); +create table t2(c1 char(10)); +insert into t values('abd'); +insert into t1 values('abc'); +insert into t2 values('abc'); +--sorted_result +select * from (select * from t union all select * from t1) t1 join t2 on t1.c1 = t2.c1; + +drop table if exists t; +create table t(a varchar(10), index idx(a)); +insert into t values('1'), ('2'), ('3'); +set @@tidb_init_chunk_size=1; +--sorted_result +select a from (select /*+ INL_JOIN(t1, t2) */ t1.a from t t1 join t t2 on t1.a=t2.a) t group by a; +--sorted_result +select a from (select /*+ INL_HASH_JOIN(t1, t2) */ t1.a from t t1 join t t2 on t1.a=t2.a) t group by a; +--sorted_result +select a from (select /*+ INL_MERGE_JOIN(t1, t2) */ t1.a from t t1 join t t2 on t1.a=t2.a) t group by a; +set @@tidb_init_chunk_size=default; + +# TestUsing +drop table if exists t1, t2, t3, t4; +create table t1 (a int, c int); +create table t2 (a int, d int); +create table t3 (a int); +create table t4 (a int); +insert t1 values (2, 4), (1, 3); +insert t2 values (2, 5), (3, 6); +insert t3 values (1); +select * from t1 join t2 using (a); +select t1.a, t2.a from t1 join t2 using (a); +select * from t1 right join t2 using (a) order by a; +select t1.a, t2.a from t1 right join t2 using (a) order by t2.a; +select * from t1 left join t2 using (a) order by a; +select t1.a, t2.a from t1 left join t2 using (a) order by t1.a; +select * from t1 join t2 using (a) right join t3 using (a); +select * from t1 join t2 using (a) right join t3 on (t2.a = t3.a); +select t2.a from t1 join t2 using (a) right join t3 on (t1.a = t3.a); +select t1.a, t2.a, t3.a from t1 join t2 using (a) right join t3 using (a); +select t1.c, t2.d from t1 join t2 using (a) right join t3 using (a); +alter table t1 add column b int default 1 after a; +alter table t2 add column b int default 1 after a; +select * from t1 join t2 using (b, a); +select * from (t1 join t2 using (a)) join (t3 join t4 using (a)) on (t2.a = t4.a and t1.a = t3.a); + +drop table if exists t, tt; +create table t(a int, b int); +create table tt(b int, a int); +insert into t (a, b) values(1, 1); +insert into tt (a, b) values(1, 2); +## Check whether this sql can execute successfully. +select * from t join tt using(a); + +drop table if exists t, tt; +create table t(a float, b int); +create table tt(b bigint, a int); +select * from t join tt using(a); + +drop table if exists t, s; +create table t(a int, b int); +create table s(b int, a int); +insert into t values(1,1), (2,2), (3,3), (null,null); +insert into s values(1,1), (3,3), (null,null); + +## For issue 20477 +select t.*, s.* from t join s using(a); +select s.a from t join s using(a); +select s.a from t join s using(a) where s.a > 1; +select s.a from t join s using(a) order by s.a; +select s.a from t join s using(a) where s.a > 1 order by s.a; +select s.a from t join s using(a) where s.a > 1 order by s.a limit 2; + +## For issue 20441 +DROP TABLE if exists t1, t2, t3; +create table t1 (i int); +create table t2 (i int); +create table t3 (i int); +select * from t1,t2 natural left join t3 order by t1.i,t2.i,t3.i; +select t1.i,t2.i,t3.i from t2 natural left join t3,t1 order by t1.i,t2.i,t3.i; +select * from t1,t2 natural right join t3 order by t1.i,t2.i,t3.i; +select t1.i,t2.i,t3.i from t2 natural right join t3,t1 order by t1.i,t2.i,t3.i; + +## For issue 15844 +DROP TABLE if exists t0, t1; +CREATE TABLE t0(c0 INT); +CREATE TABLE t1(c0 INT); +SELECT t0.c0 FROM t0 NATURAL RIGHT JOIN t1 WHERE t1.c0; + +## For issue 20958 +DROP TABLE if exists t1, t2; +create table t1(id int, name varchar(20)); +create table t2(id int, address varchar(30)); +insert into t1 values(1,'gangshen'); +insert into t2 values(1,'HangZhou'); +select t2.* from t1 inner join t2 using (id) limit 1; +select t2.* from t1 inner join t2 on t1.id = t2.id limit 1; + +## For issue 20476 +drop table if exists t1; +create table t1(a int); +insert into t1 (a) values(1); +select t1.*, t2.* from t1 join t1 t2 using(a); +select * from t1 join t1 t2 using(a); + +## For issue 18992 +drop table t; +CREATE TABLE t ( a varchar(55) NOT NULL, b varchar(55) NOT NULL, c int(11) DEFAULT NULL, d int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +update t t1 join t t2 using(a,b) set t1.c=t2.d; + +## For issue 20467 +DROP TABLE if exists t1,t2,t3,t4,t5; +CREATE TABLE t1 (a INT, b INT); +CREATE TABLE t2 (a INT, b INT); +CREATE TABLE t3 (a INT, b INT); +INSERT INTO t1 VALUES (1,1); +INSERT INTO t2 VALUES (1,1); +INSERT INTO t3 VALUES (1,1); +-- error 1052 +SELECT * FROM t1 JOIN (t2 JOIN t3 USING (b)) USING (a); + +## For issue 6712 +drop table if exists t1,t2; +create table t1 (t1 int , t0 int); +create table t2 (t2 int, t0 int); +insert into t1 select 11, 1; +insert into t2 select 22, 1; +select t1.t0, t2.t0 from t1 join t2 using(t0) group by t1.t0; +select t1.t0, t2.t0 from t1 join t2 using(t0) having t1.t0 > 0; + +# TestSubquery +set @@tidb_hash_join_concurrency=1; +set @@tidb_hashagg_partial_concurrency=1; +set @@tidb_hashagg_final_concurrency=1; +drop table if exists t; +create table t (c int, d int); +begin; +insert t values (1, 1); +insert t values (2, 2); +insert t values (3, 4); +commit; + +set sql_mode = 'STRICT_TRANS_TABLES'; + +select * from t where exists(select * from t k where t.c = k.c having sum(c) = 1); +select * from t where exists(select k.c, k.d from t k, t p where t.c = k.d); +select 1 = (select count(*) from t where t.c = k.d) from t k; +--sorted_result +select 1 = (select count(*) from t where exists( select * from t m where t.c = k.d)) from t k; +--sorted_result +select t.c = any (select count(*) from t) from t; +select * from t where (t.c, 6) = any (select count(*), sum(t.c) from t); +--sorted_result +select t.c from t where (t.c) < all (select count(*) from t); +--sorted_result +select t.c from t where (t.c, t.d) = any (select * from t); +select t.c from t where (t.c, t.d) != all (select * from t); +--sorted_result +select (select count(*) from t where t.c = k.d) from t k; +--sorted_result +select t.c from t where (t.c, t.d) in (select * from t); +select t.c from t where (t.c, t.d) not in (select * from t); +select * from t A inner join t B on A.c = B.c and A.c > 100; +## = all empty set is true +--sorted_result +select t.c from t where (t.c, t.d) != all (select * from t where d > 1000); +select t.c from t where (t.c) < any (select c from t where d > 1000); +insert t values (NULL, NULL); +--sorted_result +select (t.c) < any (select c from t) from t; +select (10) > all (select c from t) from t; +select (c) > all (select c from t) from t; + +drop table if exists a; +create table a (c int, d int); +insert a values (1, 2); +drop table if exists b; +create table b (c int, d int); +insert b values (2, 1); + +select * from a b where c = (select d from b a where a.c = 2 and b.c = 1); + +drop table if exists t; +create table t(c int); +insert t values(10), (8), (7), (9), (11); +select * from t where 9 in (select c from t s where s.c < t.c limit 3); + +drop table if exists t; +create table t(id int, v int); +insert into t values(1, 1), (2, 2), (3, 3); +select * from t where v=(select min(t1.v) from t t1, t t2, t t3 where t1.id=t2.id and t2.id=t3.id and t1.id=t.id); + +select exists (select t.id from t where s.id < 2 and t.id = s.id) from t s; + +drop table if exists t; +create table t(c int); +select exists(select count(*) from t); + +drop table if exists t; +create table t(id int primary key, v int); +insert into t values(1, 1), (2, 2), (3, 3); +--sorted_result +select (select t.id from t where s.id < 2 and t.id = s.id) from t s; +--error 1242 +select (select t.id from t where t.id = t.v and t.v != s.id) from t s; + +drop table if exists t; +drop table if exists s; +create table t(id int); +create table s(id int); +insert into t values(1), (2); +insert into s values(2), (2); +select id from t where(select count(*) from s where s.id = t.id) > 0; +select *, (select count(*) from s where id = t.id limit 1, 1) from t; + +drop table if exists t; +drop table if exists s; +create table t(id int primary key); +create table s(id int); +insert into t values(1), (2); +insert into s values(2), (2); +select *, (select count(id) from s where id = t.id) from t; +select *, 0 < any (select count(id) from s where id = t.id) from t; +select (select count(*) from t k where t.id = id) from s, t where t.id = s.id limit 1; + +drop table if exists t, s; +create table t(id int primary key); +create table s(id int, index k(id)); +insert into t values(1), (2); +insert into s values(2), (2); +select (select id from s where s.id = t.id order by s.id limit 1) from t; + +drop table if exists t, s; +create table t(id int); +create table s(id int); +insert into t values(2), (2); +insert into s values(2); +select (select id from s where s.id = t.id order by s.id) from t; + +drop table if exists t; +create table t(dt datetime); +select (select 1 from t where DATE_FORMAT(o.dt,'%Y-%m')) from t o; + +drop table if exists t1, t2; +create table t1(f1 int, f2 int); +create table t2(fa int, fb int); +insert into t1 values (1,1),(1,1),(1,2),(1,2),(1,2),(1,3); +insert into t2 values (1,1),(1,2),(1,3); +select f1,f2 from t1 group by f1,f2 having count(1) >= all (select fb from t2 where fa = f1); + +DROP TABLE IF EXISTS t1, t2; +CREATE TABLE t1(a INT); +CREATE TABLE t2 (d BINARY(2), PRIMARY KEY (d(1)), UNIQUE KEY (d)); +INSERT INTO t1 values(1); +SELECT 1 FROM executor__jointest__join.t1, executor__jointest__join.t2 WHERE 1 = (SELECT executor__jointest__join.t2.d FROM executor__jointest__join.t2 WHERE executor__jointest__join.t1.a >= 1) and executor__jointest__join.t2.d = 1; + +DROP TABLE IF EXISTS t1; +CREATE TABLE t1(a int, b int default 0); +create index k1 on t1(a); +INSERT INTO t1 (a) values(1), (2), (3), (4), (5); +select (select /*+ INL_JOIN(x2) */ x2.a from t1 x1, t1 x2 where x1.a = t1.a and x1.a = x2.a) from t1; +select (select /*+ INL_HASH_JOIN(x2) */ x2.a from t1 x1, t1 x2 where x1.a = t1.a and x1.a = x2.a) from t1; +select (select /*+ INL_MERGE_JOIN(x2) */ x2.a from t1 x1, t1 x2 where x1.a = t1.a and x1.a = x2.a) from t1; + +select 1 from (select t1.a in (select t1.a from t1) from t1) x; +select 1 from (select t1.a not in (select t1.a from t1) from t1) x; + +drop table if exists t1, t2; +create table t1(a int); +create table t2(b int); +insert into t1 values(1); +insert into t2 values(1); +select * from t1 where a in (select a from t2); + +insert into t2 value(null); +select * from t1 where 1 in (select b from t2); +select * from t1 where 1 not in (select b from t2); +select * from t1 where 2 not in (select b from t2); +select * from t1 where 2 in (select b from t2); +select 1 in (select b from t2) from t1; +select 1 in (select 1 from t2) from t1; +select 1 not in (select b from t2) from t1; +select 1 not in (select 1 from t2) from t1; + +delete from t2 where b=1; +select 1 in (select b from t2) from t1; +select 1 not in (select b from t2) from t1; +select 1 not in (select 1 from t2) from t1; +select 1 in (select 1 from t2) from t1; +select 1 not in (select null from t1) from t2; +select 1 in (select null from t1) from t2; + +drop table if exists s; +create table s(a int not null, b int); +set sql_mode = ''; +select (2,0) in (select s.a, min(s.b) from s) as f; +select (2,0) not in (select s.a, min(s.b) from s) as f; +select (2,0) = any (select s.a, min(s.b) from s) as f; +select (2,0) != all (select s.a, min(s.b) from s) as f; +select (2,0) in (select s.b, min(s.b) from s) as f; +select (2,0) not in (select s.b, min(s.b) from s) as f; +select (2,0) = any (select s.b, min(s.b) from s) as f; +select (2,0) != all (select s.b, min(s.b) from s) as f; +insert into s values(1,null); +select 1 in (select b from s); + +drop table if exists t; +create table t(a int); +insert into t values(1),(null); +select a not in (select 1) from t; +select 1 not in (select null from t t1) from t; +select 1 in (select null from t t1) from t; +select a in (select 0) xx from (select null as a) x; + +drop table t; +create table t(a int, b int); +insert into t values(1,null),(null, null),(null, 2); +select * from t t1 where (2 in (select a from t t2 where (t2.b=t1.b) is null)); +--sorted_result +select (t2.a in (select t1.a from t t1)) is true from t t2; + +set sql_mode=default; +set @@tidb_hash_join_concurrency=default; +set @@tidb_hashagg_partial_concurrency=default; +set @@tidb_hashagg_final_concurrency=default; + diff --git a/tests/integrationtest/t/executor/set.test b/tests/integrationtest/t/executor/set.test index 112926aaf67d4..9fda121c7613d 100644 --- a/tests/integrationtest/t/executor/set.test +++ b/tests/integrationtest/t/executor/set.test @@ -11,3 +11,282 @@ set @@global.tidb_max_delta_schema_count= 2048; select @@global.tidb_max_delta_schema_count; set @@global.tidb_max_delta_schema_count= default; +# TestGetSetNoopVars +SELECT @@query_cache_type; +SHOW VARIABLES LIKE 'query_cache_type'; +SET query_cache_type=2; +SELECT @@query_cache_type; +SET GLOBAL tidb_enable_noop_variables = OFF; +SELECT @@global.tidb_enable_noop_variables; +SELECT @@query_cache_type; +SHOW WARNINGS; +SHOW VARIABLES LIKE 'query_cache_type'; +SET query_cache_type = OFF; +SHOW WARNINGS; +SELECT @@query_cache_type; +-- error 1231 +SET GLOBAL tidb_enable_noop_variables = 2; +-- error 1231 +SET GLOBAL tidb_enable_noop_variables = 'warn'; +SET GLOBAL tidb_enable_noop_variables = ON; + +SET GLOBAL tidb_enable_noop_variables = default; +SET query_cache_type = default; + +# TestSetCharset +show VARIABLES like 'character_set_%'; +SET NAMES latin1; +show VARIABLES like 'character_set_%'; +SET NAMES default; +show VARIABLES like 'character_set_%'; +SET NAMES binary; +show VARIABLES like 'character_set_%'; +SET NAMES utf8; +show VARIABLES like 'character_set_%'; +SET CHARACTER SET latin1; +show VARIABLES like 'character_set_%'; +SET CHARACTER SET default; +show VARIABLES like 'character_set_%'; + +set names default; + +# TestSelectGlobalVar +select @@global.max_connections; +select @@max_connections; +set @@global.max_connections=100; +select @@global.max_connections; +select @@max_connections; +set @@global.max_connections=0; +-- error 1193 +select @@invalid; +-- error 1193 +select @@global.invalid; + +set @@global.max_connections=default; + +# TestDefaultBehavior +# https://github.com/pingcap/tidb/issues/29670 +SELECT @@default_storage_engine; +SET GLOBAL default_storage_engine = 'somethingweird'; +SET default_storage_engine = 'MyISAM'; +SELECT @@default_storage_engine; +SET default_storage_engine = DEFAULT; +SELECT @@default_storage_engine; +SET @@SESSION.default_storage_engine = @@GLOBAL.default_storage_engine; +SELECT @@default_storage_engine; +SET GLOBAL default_storage_engine = 'somethingweird2'; +SET default_storage_engine = @@GLOBAL.default_storage_engine; +SELECT @@default_storage_engine; +SET default_storage_engine = DEFAULT; +SET GLOBAL default_storage_engine = DEFAULT; +SELECT @@SESSION.default_storage_engine, @@GLOBAL.default_storage_engine; +-- error 1105 +SET GLOBAL sql_mode = 'DEFAULT'; +SET GLOBAL sql_mode = DEFAULT; + +set @@SESSION.default_storage_engine=default; +SET GLOBAL default_storage_engine=default; + +# TestTiDBReadOnly +SET GLOBAL tidb_restricted_read_only = ON; +SELECT @@GLOBAL.tidb_super_read_only; +-- error 1105 +SET GLOBAL tidb_super_read_only = OFF; +SET GLOBAL tidb_restricted_read_only = OFF; +SELECT @@GLOBAL.tidb_restricted_read_only; +SELECT @@GLOBAL.tidb_super_read_only; +SET GLOBAL tidb_super_read_only = OFF; +SELECT @@GLOBAL.tidb_super_read_only; + +SET GLOBAL tidb_super_read_only = default; +SET GLOBAL tidb_restricted_read_only = default; + +# TestRemovedSysVars +SET tidb_enable_global_temporary_table = 1; +SET tidb_slow_log_masking = 1; +SET GLOBAL tidb_enable_global_temporary_table = 1; +SET GLOBAL tidb_slow_log_masking = 1; +-- error 8136 +SELECT @@tidb_slow_log_masking; +-- error 8136 +SELECT @@tidb_enable_global_temporary_table; + +SET tidb_enable_global_temporary_table = default; +SET tidb_slow_log_masking = default; +SET GLOBAL tidb_enable_global_temporary_table = default; +SET GLOBAL tidb_slow_log_masking = default; + +# TestPreparePlanCacheValid +select @@global.tidb_session_plan_cache_size; +SET GLOBAL tidb_session_plan_cache_size = 0; +show warnings; +select @@global.tidb_session_plan_cache_size; +SET GLOBAL tidb_session_plan_cache_size = 2; +select @@global.tidb_session_plan_cache_size; +select @@session.tidb_session_plan_cache_size; +SET SESSION tidb_session_plan_cache_size = 0; +show warnings; +select @@session.tidb_session_plan_cache_size; +SET SESSION tidb_session_plan_cache_size = 2; +select @@session.tidb_session_plan_cache_size; +SET GLOBAL tidb_prepared_plan_cache_memory_guard_ratio = -0.1; +show warnings; +select @@global.tidb_prepared_plan_cache_memory_guard_ratio; +SET GLOBAL tidb_prepared_plan_cache_memory_guard_ratio = 2.2; +show warnings; +select @@global.tidb_prepared_plan_cache_memory_guard_ratio; +SET GLOBAL tidb_prepared_plan_cache_memory_guard_ratio = 0.5; +select @@global.tidb_prepared_plan_cache_memory_guard_ratio; +SET GLOBAL tidb_enable_prepared_plan_cache = 0; +select @@global.tidb_enable_prepared_plan_cache; +SET GLOBAL tidb_enable_prepared_plan_cache = 1; +select @@global.tidb_enable_prepared_plan_cache; +SET GLOBAL tidb_enable_prepared_plan_cache = 0; +select @@global.tidb_enable_prepared_plan_cache; + +SET GLOBAL tidb_enable_prepared_plan_cache = default; +SET GLOBAL tidb_prepared_plan_cache_memory_guard_ratio = default; +SET SESSION tidb_session_plan_cache_size = default; +SET GLOBAL tidb_session_plan_cache_size = default; + +# TestInstanceScopeSwitching +set tidb_enable_legacy_instance_scope = 1; +set tidb_general_log = 1; +show warnings; +set tidb_enable_legacy_instance_scope = 0; +-- error 1229 +set tidb_general_log = 1; + +set tidb_enable_legacy_instance_scope = default; +set tidb_general_log = default; + +# TestGcMaxWaitTime +set global tidb_gc_max_wait_time = 1000; +set global tidb_gc_life_time = "72h"; +set global tidb_gc_life_time = "24h"; +set global tidb_gc_life_time = "10m"; +set global tidb_gc_max_wait_time = 86400; +set global tidb_gc_life_time = "72h"; +set global tidb_gc_max_wait_time = 1000; + +set global tidb_gc_life_time = default; +set global tidb_gc_max_wait_time = default; + +# TestTiFlashFineGrainedShuffle +select @@tiflash_fine_grained_shuffle_stream_count; +set @@tiflash_fine_grained_shuffle_stream_count = 0; +select @@tiflash_fine_grained_shuffle_stream_count; +set @@tiflash_fine_grained_shuffle_stream_count = -2; +select @@tiflash_fine_grained_shuffle_stream_count; +set @@tiflash_fine_grained_shuffle_stream_count = 0; +select @@tiflash_fine_grained_shuffle_stream_count; +set @@tiflash_fine_grained_shuffle_stream_count = 1024; +select @@tiflash_fine_grained_shuffle_stream_count; +set @@tiflash_fine_grained_shuffle_stream_count = 1025; +select @@tiflash_fine_grained_shuffle_stream_count; +select @@tiflash_fine_grained_shuffle_batch_size; +set @@tiflash_fine_grained_shuffle_batch_size = 0; +select @@tiflash_fine_grained_shuffle_batch_size; +set @@tiflash_fine_grained_shuffle_batch_size = -1; +select @@tiflash_fine_grained_shuffle_batch_size; +set @@tiflash_fine_grained_shuffle_batch_size = 18446744073709551615; +select @@tiflash_fine_grained_shuffle_batch_size; +set global tiflash_fine_grained_shuffle_stream_count = -1; +set global tiflash_fine_grained_shuffle_batch_size = 8192; + +set @@tiflash_fine_grained_shuffle_batch_size = default; +set @@tiflash_fine_grained_shuffle_stream_count = default; +set global tiflash_fine_grained_shuffle_stream_count = default; +set global tiflash_fine_grained_shuffle_batch_size = default; + +# TestSetTiFlashFastScanVariable +drop table if exists t; +create table t(a int); +insert into t values(1); +select @@session.tiflash_fastscan; +select @@global.tiflash_fastscan; +set @@tiflash_fastscan=ON; +select @@session.tiflash_fastscan; +set global tiflash_fastscan=OFF; +select @@global.tiflash_fastscan; + +set global tiflash_fastscan=default; +set @@tiflash_fastscan=default; + +# TestSetPlanCacheMemoryMonitor +select @@session.tidb_enable_prepared_plan_cache_memory_monitor; +select @@global.tidb_enable_prepared_plan_cache_memory_monitor; +set @@session.tidb_enable_prepared_plan_cache_memory_monitor=OFF; +select @@session.tidb_enable_prepared_plan_cache_memory_monitor; +set @@session.tidb_enable_prepared_plan_cache_memory_monitor=1; +select @@session.tidb_enable_prepared_plan_cache_memory_monitor; +set @@global.tidb_enable_prepared_plan_cache_memory_monitor=off; +select @@global.tidb_enable_prepared_plan_cache_memory_monitor; + +set @@session.tidb_enable_prepared_plan_cache_memory_monitor=default; +set @@global.tidb_enable_prepared_plan_cache_memory_monitor=default; + +# TestSetChunkReuseVariable +set @@tidb_enable_reuse_chunk=ON; +select @@session.tidb_enable_reuse_chunk; +set GLOBAL tidb_enable_reuse_chunk=ON; +select @@global.tidb_enable_reuse_chunk; +set @@tidb_enable_reuse_chunk=OFF; +select @@session.tidb_enable_reuse_chunk; +set GLOBAL tidb_enable_reuse_chunk=OFF; +select @@global.tidb_enable_reuse_chunk; +-- error 1231 +set @@tidb_enable_reuse_chunk=s; + +set @@tidb_enable_reuse_chunk=default; +set GLOBAL tidb_enable_reuse_chunk=default; + +# TestSetMppVersionVariable +select @@session.mpp_version; +SET SESSION mpp_version = -1; +select @@session.mpp_version; +SET SESSION mpp_version = 0; +select @@session.mpp_version; +SET SESSION mpp_version = 1; +select @@session.mpp_version; +SET SESSION mpp_version = 2; +select @@session.mpp_version; +SET SESSION mpp_version = unspecified; +select @@session.mpp_version; +-- error 1105 +SET SESSION mpp_version = 3; +SET GLOBAL mpp_version = 1; +select @@global.mpp_version; +SET GLOBAL mpp_version = -1; +select @@global.mpp_version; + +SET SESSION mpp_version = default; +set global mpp_version = default; + +# TestSetMppExchangeCompressionModeVariable +-- error 1105 +SET SESSION mpp_exchange_compression_mode = 123; +select @@session.mpp_exchange_compression_mode; +SET SESSION mpp_exchange_compression_mode = none; +select @@session.mpp_exchange_compression_mode; +SET SESSION mpp_exchange_compression_mode = fast; +select @@session.mpp_exchange_compression_mode; +SET SESSION mpp_exchange_compression_mode = HIGH_COMPRESSION; +select @@session.mpp_exchange_compression_mode; +SET GLOBAL mpp_exchange_compression_mode = none; +select @@global.mpp_exchange_compression_mode; +SET mpp_version = 0; +SET mpp_exchange_compression_mode = unspecified; +SET mpp_version = 0; +SET mpp_exchange_compression_mode = HIGH_COMPRESSION; + +SET mpp_version = default; +SET mpp_exchange_compression_mode = default; +set @@global.mpp_exchange_compression_mode = default; + +# TestDeprecateEnableTiFlashPipelineModel +set @@global.tidb_enable_tiflash_pipeline_model = 1; +show warnings; + +set @@global.tidb_enable_tiflash_pipeline_model = default; + diff --git a/tests/integrationtest/t/executor/write.test b/tests/integrationtest/t/executor/write.test index 8c3ac8c33bfe5..6ff53470eb9ff 100644 --- a/tests/integrationtest/t/executor/write.test +++ b/tests/integrationtest/t/executor/write.test @@ -1147,3 +1147,72 @@ insert into t values ('2023-06-11 10:00:00', 1); update t force index(primary) set b = 10 where a = '2023-06-11 10:00:00'; admin check table t; drop table if exists t; + +# TestMutipleReplaceAndInsertInOneSession +drop table if exists t_securities; +create table t_securities(id bigint not null auto_increment primary key, security_id varchar(8), market_id smallint, security_type int, unique key uu(security_id, market_id)); +insert into t_securities (security_id, market_id, security_type) values ("1", 2, 7), ("7", 1, 7) ON DUPLICATE KEY UPDATE security_type = VALUES(security_type); +replace into t_securities (security_id, market_id, security_type) select security_id+1, 1, security_type from t_securities where security_id="7"; +INSERT INTO t_securities (security_id, market_id, security_type) values ("1", 2, 7), ("7", 1, 7) ON DUPLICATE KEY UPDATE security_type = VALUES(security_type); +--sorted_result +select * from t_securities; + +connect (conn1, localhost, root,,executor__write); +insert into t_securities (security_id, market_id, security_type) values ("1", 2, 7), ("7", 1, 7) ON DUPLICATE KEY UPDATE security_type = VALUES(security_type); +insert into t_securities (security_id, market_id, security_type) select security_id+2, 1, security_type from t_securities where security_id="7"; +INSERT INTO t_securities (security_id, market_id, security_type) values ("1", 2, 7), ("7", 1, 7) ON DUPLICATE KEY UPDATE security_type = VALUES(security_type); +--sorted_result +select * from t_securities; + +connection default; +disconnect conn1; + +# TestListPartitionWithAutoRandom +set @@session.tidb_enable_list_partition = ON; +drop table if exists t; +create table t (a bigint key auto_random (3), b int) partition by list (a%5) (partition p0 values in (0,1,2), partition p1 values in (3,4)); +set @@allow_auto_random_explicit_insert = true; +replace into t values (1,1); +insert into t (b) values (2); +insert into t (b) values (3); +insert into t (b) values (4); +insert into t (b) values (5); +insert into t (b) values (6); +insert into t (b) values (7); +insert into t (b) values (8); +insert into t (b) values (9); +select b from t order by b; +update t set b=b+1 where a=1; +select b from t where a=1; +update t set b=b+1 where a<2; +select b from t where a<2; +insert into t values (1, 1) on duplicate key update b=b+1; +select b from t where a=1; + +set @@session.tidb_enable_list_partition = default; +set @@allow_auto_random_explicit_insert = default; + +# TestListPartitionWithAutoIncrement +set @@session.tidb_enable_list_partition = ON; +drop table if exists t; +create table t (a bigint key auto_increment, b int) partition by list (a%5) (partition p0 values in (0,1,2), partition p1 values in (3,4)); +set @@allow_auto_random_explicit_insert = true; +replace into t values (1,1); +insert into t (b) values (2); +insert into t (b) values (3); +insert into t (b) values (4); +insert into t (b) values (5); +insert into t (b) values (6); +insert into t (b) values (7); +insert into t (b) values (8); +insert into t (b) values (9); +select b from t order by b; +update t set b=b+1 where a=1; +select b from t where a=1; +update t set b=b+1 where a<2; +select b from t where a<2; +insert into t values (1, 1) on duplicate key update b=b+1; +select b from t where a=1; + +set @@session.tidb_enable_list_partition = default; +set @@allow_auto_random_explicit_insert = default;