From e0eaefc8beb1bd72e290b23a16a630728614f4d7 Mon Sep 17 00:00:00 2001 From: h3n4l Date: Mon, 10 Oct 2022 19:37:49 +0800 Subject: [PATCH] fix(parser): restore table option INSERT_METHOD should use WriteKeyWord (#38355) close pingcap/tidb#38368 --- parser/ast/ddl.go | 2 +- parser/parser_test.go | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/parser/ast/ddl.go b/parser/ast/ddl.go index b51ebedfd729f..0c0090e353f77 100644 --- a/parser/ast/ddl.go +++ b/parser/ast/ddl.go @@ -2298,7 +2298,7 @@ func (n *TableOption) Restore(ctx *format.RestoreCtx) error { case TableOptionInsertMethod: ctx.WriteKeyWord("INSERT_METHOD ") ctx.WritePlain("= ") - ctx.WriteString(n.StrValue) + ctx.WriteKeyWord(n.StrValue) case TableOptionTableCheckSum: ctx.WriteKeyWord("TABLE_CHECKSUM ") ctx.WritePlain("= ") diff --git a/parser/parser_test.go b/parser/parser_test.go index 4604ec9c33e99..db8286dba834b 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -2983,8 +2983,8 @@ func TestDDL(t *testing.T) { {"ALTER TABLE t ENGINE = 'innodb'", true, "ALTER TABLE `t` ENGINE = innodb"}, {"ALTER TABLE t ENGINE = innodb", true, "ALTER TABLE `t` ENGINE = innodb"}, {"ALTER TABLE `db`.`t` ENGINE = ``", true, "ALTER TABLE `db`.`t` ENGINE = ''"}, - {"ALTER TABLE t INSERT_METHOD = FIRST", true, "ALTER TABLE `t` INSERT_METHOD = 'FIRST'"}, - {"ALTER TABLE t INSERT_METHOD LAST", true, "ALTER TABLE `t` INSERT_METHOD = 'LAST'"}, + {"ALTER TABLE t INSERT_METHOD = FIRST", true, "ALTER TABLE `t` INSERT_METHOD = FIRST"}, + {"ALTER TABLE t INSERT_METHOD LAST", true, "ALTER TABLE `t` INSERT_METHOD = LAST"}, {"ALTER TABLE t ADD COLUMN a SMALLINT UNSIGNED, ADD COLUMN a SMALLINT", true, "ALTER TABLE `t` ADD COLUMN `a` SMALLINT UNSIGNED, ADD COLUMN `a` SMALLINT"}, {"ALTER TABLE t ADD COLUMN a SMALLINT, ENGINE = '', default COLLATE = UTF8_GENERAL_CI", true, "ALTER TABLE `t` ADD COLUMN `a` SMALLINT, ENGINE = '', DEFAULT COLLATE = UTF8_GENERAL_CI"}, {"ALTER TABLE t ENGINE = '', COMMENT='', default COLLATE = UTF8_GENERAL_CI", true, "ALTER TABLE `t` ENGINE = '', COMMENT = '', DEFAULT COLLATE = UTF8_GENERAL_CI"}, @@ -3629,6 +3629,9 @@ func TestDDL(t *testing.T) { {"ALTER TABLE t STATS_OPTIONS=default", true, "ALTER TABLE `t` STATS_OPTIONS=DEFAULT"}, {"ALTER TABLE t STATS_OPTIONS=DeFaUlT", true, "ALTER TABLE `t` STATS_OPTIONS=DEFAULT"}, {"ALTER TABLE t STATS_OPTIONS", false, ""}, + + // Restore INSERT_METHOD table option + {"CREATE TABLE t (a int) INSERT_METHOD=FIRST", true, "CREATE TABLE `t` (`a` INT) INSERT_METHOD = FIRST"}, } RunTest(t, table, false) }