From 30b2b8fbf55e7a787c24199ee04ad697b8f67064 Mon Sep 17 00:00:00 2001 From: tangenta Date: Wed, 27 Dec 2023 20:07:58 +0800 Subject: [PATCH] executor: display `pre_split_regions` for auto_random tables in `SHOW CREATE` (#49781) close pingcap/tidb#49839 --- pkg/executor/show.go | 4 ++++ tests/integrationtest/r/executor/show.result | 9 +++++++++ tests/integrationtest/t/executor/show.test | 5 +++++ 3 files changed, 18 insertions(+) diff --git a/pkg/executor/show.go b/pkg/executor/show.go index 21367c03b57ea..6d522d9710611 100644 --- a/pkg/executor/show.go +++ b/pkg/executor/show.go @@ -1294,6 +1294,10 @@ func constructResultOfShowCreateTable(ctx sessionctx.Context, dbName *model.CISt buf.WriteString("*/") } + if tableInfo.AutoRandomBits > 0 && tableInfo.PreSplitRegions > 0 { + fmt.Fprintf(buf, " /*T! PRE_SPLIT_REGIONS=%d */", tableInfo.PreSplitRegions) + } + if len(tableInfo.Comment) > 0 { fmt.Fprintf(buf, " COMMENT='%s'", format.OutputFormat(tableInfo.Comment)) } diff --git a/tests/integrationtest/r/executor/show.result b/tests/integrationtest/r/executor/show.result index b76ab526b3387..c82e21e5302d2 100644 --- a/tests/integrationtest/r/executor/show.result +++ b/tests/integrationtest/r/executor/show.result @@ -1123,3 +1123,12 @@ select * from information_schema.COLLATIONS where IS_DEFAULT='Yes' and CHARACTER COLLATION_NAME CHARACTER_SET_NAME ID IS_DEFAULT IS_COMPILED SORTLEN utf8mb4_bin utf8mb4 46 Yes Yes 1 set @@session.default_collation_for_utf8mb4=default; +DROP TABLE IF EXISTS `t`; +CREATE TABLE `t` (a BIGINT PRIMARY KEY AUTO_RANDOM(2), b INT) PRE_SPLIT_REGIONS=4; +SHOW CREATE TABLE `t`; +Table Create Table +t CREATE TABLE `t` ( + `a` bigint(20) NOT NULL /*T![auto_rand] AUTO_RANDOM(2) */, + `b` int(11) DEFAULT NULL, + PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */ +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T! PRE_SPLIT_REGIONS=2 */ diff --git a/tests/integrationtest/t/executor/show.test b/tests/integrationtest/t/executor/show.test index ef88ad76614eb..b490834323beb 100644 --- a/tests/integrationtest/t/executor/show.test +++ b/tests/integrationtest/t/executor/show.test @@ -427,3 +427,8 @@ select * from information_schema.COLLATIONS; show character set like '%utf8mb4%'; select * from information_schema.COLLATIONS where IS_DEFAULT='Yes' and CHARACTER_SET_NAME='utf8mb4'; set @@session.default_collation_for_utf8mb4=default; + +# TestShowPreSplitRegionsForAutoRandomTables +DROP TABLE IF EXISTS `t`; +CREATE TABLE `t` (a BIGINT PRIMARY KEY AUTO_RANDOM(2), b INT) PRE_SPLIT_REGIONS=4; +SHOW CREATE TABLE `t`;