From efa7010853b029f8e2d12c0d1a8afe8e7229276c Mon Sep 17 00:00:00 2001 From: crazycs Date: Mon, 14 Nov 2022 15:47:54 +0800 Subject: [PATCH] executor: fix issue of show create table with foreign key comment (#39129) --- executor/fktest/foreign_key_test.go | 6 ++++-- executor/show.go | 2 +- executor/showtest/show_test.go | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/executor/fktest/foreign_key_test.go b/executor/fktest/foreign_key_test.go index c704494ffb7f5..558c033b89621 100644 --- a/executor/fktest/foreign_key_test.go +++ b/executor/fktest/foreign_key_test.go @@ -1964,7 +1964,7 @@ func TestShowCreateTableWithForeignKey(t *testing.T) { " `leader2` int(11) DEFAULT NULL,\n" + " PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */,\n" + " KEY `leader` (`leader`),\n KEY `leader2` (`leader2`),\n" + - " CONSTRAINT `fk` FOREIGN KEY (`leader`) REFERENCES `test`.`t1` (`id`) ON DELETE CASCADE ON UPDATE SET NULL /*T![FOREIGN KEY] INVALID */\n" + + " CONSTRAINT `fk` FOREIGN KEY (`leader`) REFERENCES `test`.`t1` (`id`) ON DELETE CASCADE ON UPDATE SET NULL /* FOREIGN KEY INVALID */\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")) tk.MustExec("set @@global.tidb_enable_foreign_key=1") tk.MustExec("alter table t1 add constraint fk2 foreign key (leader2) references t1 (id)") @@ -1974,9 +1974,11 @@ func TestShowCreateTableWithForeignKey(t *testing.T) { " `leader2` int(11) DEFAULT NULL,\n" + " PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */,\n" + " KEY `leader` (`leader`),\n KEY `leader2` (`leader2`),\n" + - " CONSTRAINT `fk` FOREIGN KEY (`leader`) REFERENCES `test`.`t1` (`id`) ON DELETE CASCADE ON UPDATE SET NULL /*T![FOREIGN KEY] INVALID */,\n" + + " CONSTRAINT `fk` FOREIGN KEY (`leader`) REFERENCES `test`.`t1` (`id`) ON DELETE CASCADE ON UPDATE SET NULL /* FOREIGN KEY INVALID */,\n" + " CONSTRAINT `fk2` FOREIGN KEY (`leader2`) REFERENCES `test`.`t1` (`id`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")) + tk.MustExec("drop table t1") + tk.MustExec("create table t1 (id int key, leader int, leader2 int, index(leader), index(leader2), constraint fk foreign key (leader) references t1(id) /* FOREIGN KEY INVALID */);") } func TestDMLExplainAnalyzeFKInfo(t *testing.T) { diff --git a/executor/show.go b/executor/show.go index 8ec62eac26c08..72bd63a785623 100644 --- a/executor/show.go +++ b/executor/show.go @@ -1142,7 +1142,7 @@ func ConstructResultOfShowCreateTable(ctx sessionctx.Context, tableInfo *model.T buf.WriteString(fmt.Sprintf(" ON UPDATE %s", model.ReferOptionType(fk.OnUpdate).String())) } if fk.Version < model.FKVersion1 { - buf.WriteString(" /*T![FOREIGN KEY] INVALID */") + buf.WriteString(" /* FOREIGN KEY INVALID */") } } diff --git a/executor/showtest/show_test.go b/executor/showtest/show_test.go index 11fa95dc0bb8c..3566b1589a271 100644 --- a/executor/showtest/show_test.go +++ b/executor/showtest/show_test.go @@ -330,7 +330,7 @@ func TestShowCreateTable(t *testing.T) { " `parent_id` int(11) NOT NULL,\n"+ " PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */,\n"+ " KEY `par_ind` (`parent_id`),\n"+ - " CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `test`.`parent` (`id`) /*T![FOREIGN KEY] INVALID */\n"+ + " CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `test`.`parent` (`id`) /* FOREIGN KEY INVALID */\n"+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", )) @@ -344,7 +344,7 @@ func TestShowCreateTable(t *testing.T) { " `parent_id` int(11) NOT NULL,\n"+ " PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */,\n"+ " KEY `par_ind` (`parent_id`),\n"+ - " CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `test`.`parent` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE /*T![FOREIGN KEY] INVALID */\n"+ + " CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `test`.`parent` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE /* FOREIGN KEY INVALID */\n"+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin", )) @@ -357,7 +357,7 @@ func TestShowCreateTable(t *testing.T) { " `id` int(11) NOT NULL,\n" + " `b` int(11) DEFAULT NULL,\n" + " PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */,\n" + - " CONSTRAINT `fk` FOREIGN KEY (`b`) REFERENCES `test1`.`t1` (`id`) /*T![FOREIGN KEY] INVALID */\n" + + " CONSTRAINT `fk` FOREIGN KEY (`b`) REFERENCES `test1`.`t1` (`id`) /* FOREIGN KEY INVALID */\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin")) // Test issue #20327