-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
schemadiff: normalize index option value (string) #11675
Conversation
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
If a new flag is being introduced:
If a workflow is added or modified:
Bug fixes
Non-trivial changes
New/Existing features
Backward compatibility
|
@@ -482,6 +482,7 @@ func (c *CreateTableEntity) normalizeIndexOptions() { | |||
idx.Info.Type = strings.ToLower(idx.Info.Type) | |||
for _, opt := range idx.Options { | |||
opt.Name = strings.ToLower(opt.Name) | |||
opt.String = strings.ToLower(opt.String) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, would this always lowercase things if you have for example a comment set? It seems like we should not normalize that then. I wonder if we should make this specific only to WITH PARSER
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per our parser:
Lines 2299 to 2332 in 1ace3b4
index_option: | |
using_index_type | |
{ | |
$$ = $1 | |
} | |
| KEY_BLOCK_SIZE equal_opt INTEGRAL | |
{ | |
// should not be string | |
$$ = &IndexOption{Name: string($1), Value: NewIntLiteral($3)} | |
} | |
| COMMENT_KEYWORD STRING | |
{ | |
$$ = &IndexOption{Name: string($1), Value: NewStrLiteral($2)} | |
} | |
| VISIBLE | |
{ | |
$$ = &IndexOption{Name: string($1) } | |
} | |
| INVISIBLE | |
{ | |
$$ = &IndexOption{Name: string($1) } | |
} | |
| WITH PARSER ci_identifier | |
{ | |
$$ = &IndexOption{Name: string($1) + " " + string($2), String: $3.String()} | |
} | |
| ENGINE_ATTRIBUTE equal_opt STRING | |
{ | |
$$ = &IndexOption{Name: string($1), Value: NewStrLiteral($3)} | |
} | |
| SECONDARY_ENGINE_ATTRIBUTE equal_opt STRING | |
{ | |
$$ = &IndexOption{Name: string($1), Value: NewStrLiteral($3)} | |
} |
It looks like the String
value is only ever used (at this time?) in a WITH PARSER
clause. No other index clause/option utilizes it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm also here:
Lines 7240 to 7244 in 1ace3b4
using_index_type: | |
USING sql_id | |
{ | |
$$ = &IndexOption{Name: string($1), String: string($2.String())} | |
} |
USING ...
, so this affects e.g. USING HASH
-> USING hash
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any issues with lower-casing USING
or WITH PARSER
values
go/vt/schemadiff/table_test.go
Outdated
from: "create table t1 (id int primary key, name tinytext not null)", | ||
to: "create table t1 (id int primary key, name tinytext not null, fulltext key name_ft(name) with parser ngram)", | ||
diff: "alter table t1 add fulltext key name_ft (`name`) with parser ngram", | ||
cdiff: "ALTER TABLE `t1` ADD FULLTEXT KEY `name_ft` (`name`) WITH PARSER NGRAM", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we also want to / need to change the canonical output format of this. It looks like the parser formatter always upcases this. I think we should add something like the following as well:
diff --git i/go/vt/sqlparser/ast_format.go w/go/vt/sqlparser/ast_format.go
index e94a1b24ab..65756a46a9 100644
--- i/go/vt/sqlparser/ast_format.go
+++ w/go/vt/sqlparser/ast_format.go
@@ -826,7 +826,7 @@ func (idx *IndexDefinition) Format(buf *TrackedBuffer) {
for _, opt := range idx.Options {
buf.astPrintf(idx, " %s", opt.Name)
if opt.String != "" {
- buf.astPrintf(idx, " %s", opt.String)
+ buf.astPrintf(idx, " %#s", opt.String)
} else if opt.Value != nil {
buf.astPrintf(idx, " %v", opt.Value)
}
diff --git i/go/vt/sqlparser/tracked_buffer_test.go w/go/vt/sqlparser/tracked_buffer_test.go
index 02ea192a5d..614a215c0e 100644
--- i/go/vt/sqlparser/tracked_buffer_test.go
+++ w/go/vt/sqlparser/tracked_buffer_test.go
@@ -220,6 +220,10 @@ func TestCanonicalOutput(t *testing.T) {
"select char(77, 121, 83, 81, '76' using utf8mb4) from dual",
"SELECT CHAR(77, 121, 83, 81, '76' USING utf8mb4) FROM `dual`",
},
+ {
+ "create table t1 (id int primary key, name tinytext not null, fulltext key name_ft(name) with parser ngram)",
+ "CREATE TABLE `t1` (\n\t`id` int PRIMARY KEY,\n\t`name` tinytext NOT NULL,\n\tFULLTEXT KEY `name_ft` (`name`) WITH PARSER ngram\n)",
+ },
}
for _, tc := range testcases {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Normalization now takes place in both
|
Description
With this PR
schemadiff
normalizes (to lower case) the value of an index option. For example:fulltext key name_ft(name) WITH PARSER NGRAM
is normalized intofulltext key name_ft(name) WITH PARSER ngram
Related Issue(s)
Tracking: #10203
Checklist
Deployment Notes