ddl: check TTL constraints for temporary tables (#65246)
close pingcap/tidb#64948
This commit is contained in:
@ -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()
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
Reference in New Issue
Block a user