diff --git a/pkg/ddl/create_table.go b/pkg/ddl/create_table.go index f8ac8e6df7..a9aeb01116 100644 --- a/pkg/ddl/create_table.go +++ b/pkg/ddl/create_table.go @@ -769,9 +769,19 @@ func BuildSessionTemporaryTableInfo(ctx *metabuild.Context, store kv.Storage, is } tbInfo, err = BuildTableInfoWithLike(ident, referTbl.Meta(), s) } else { - tbInfo, err = buildTableInfoWithCheck(ctx, store, s, dbCharset, dbCollate, placementPolicyRef) + tbInfo, err = BuildTableInfoWithStmt(ctx, s, dbCharset, dbCollate, placementPolicyRef) } - return tbInfo, err + + if err != nil { + return nil, err + } + if err = checkTableInfoValidWithStmt(ctx, tbInfo, s); err != nil { + return nil, err + } + if err = checkTableInfoValidExtra(ctx.GetExprCtx().GetEvalCtx().ErrCtx(), store, s.Table.Schema, tbInfo); err != nil { + return nil, err + } + return tbInfo, nil } // BuildTableInfoWithStmt builds model.TableInfo from a SQL statement without validity check @@ -1268,7 +1278,10 @@ func BuildTableInfoWithLike(ident ast.Ident, referTblInfo *model.TableInfo, s *a tblInfo.Partition = &pi } - if referTblInfo.TTLInfo != nil { + // for issue #64948, temporary table does not support TLL, we should remove it + if s.TemporaryKeyword != ast.TemporaryNone { + tblInfo.TTLInfo = nil + } else if referTblInfo.TTLInfo != nil { tblInfo.TTLInfo = referTblInfo.TTLInfo.Clone() } diff --git a/tests/integrationtest/r/executor/ddl.result b/tests/integrationtest/r/executor/ddl.result index 41aa4e0567..2b45c0d3c1 100644 --- a/tests/integrationtest/r/executor/ddl.result +++ b/tests/integrationtest/r/executor/ddl.result @@ -588,3 +588,24 @@ c_int 1 alter table t add index idx_4 (c_str); rollback; +DROP TABLE IF EXISTS ttl_src, temp_local, temp_global, normal_copy; +CREATE TABLE ttl_src (created_at TIMESTAMP) TTL = `created_at` + INTERVAL 1 HOUR; +CREATE TEMPORARY TABLE temp_local LIKE ttl_src; +SHOW CREATE TABLE temp_local; +Table Create Table +temp_local CREATE TEMPORARY TABLE `temp_local` ( + `created_at` timestamp NULL DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin +CREATE GLOBAL TEMPORARY TABLE temp_global LIKE ttl_src ON COMMIT DELETE ROWS; +SHOW CREATE TABLE temp_global; +Table Create Table +temp_global CREATE GLOBAL TEMPORARY TABLE `temp_global` ( + `created_at` timestamp NULL DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ON COMMIT DELETE ROWS +CREATE TABLE normal_copy LIKE ttl_src; +SHOW CREATE TABLE normal_copy; +Table Create Table +normal_copy CREATE TABLE `normal_copy` ( + `created_at` timestamp NULL DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T![ttl] TTL=`created_at` + INTERVAL 1 HOUR */ /*T![ttl] TTL_ENABLE='ON' */ /*T![ttl] TTL_JOB_INTERVAL='24h' */ +DROP TABLE IF EXISTS ttl_src, temp_local, temp_global, normal_copy; diff --git a/tests/integrationtest/t/executor/ddl.test b/tests/integrationtest/t/executor/ddl.test index 97df2bd3e8..7006418b66 100644 --- a/tests/integrationtest/t/executor/ddl.test +++ b/tests/integrationtest/t/executor/ddl.test @@ -534,3 +534,13 @@ select c_int from t where c_str is not null for update; alter table t add index idx_4 (c_str); rollback; +# TestIssue64948 +DROP TABLE IF EXISTS ttl_src, temp_local, temp_global, normal_copy; +CREATE TABLE ttl_src (created_at TIMESTAMP) TTL = `created_at` + INTERVAL 1 HOUR; +CREATE TEMPORARY TABLE temp_local LIKE ttl_src; +SHOW CREATE TABLE temp_local; +CREATE GLOBAL TEMPORARY TABLE temp_global LIKE ttl_src ON COMMIT DELETE ROWS; +SHOW CREATE TABLE temp_global; +CREATE TABLE normal_copy LIKE ttl_src; +SHOW CREATE TABLE normal_copy; +DROP TABLE IF EXISTS ttl_src, temp_local, temp_global, normal_copy; \ No newline at end of file