Skip to content
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

Fix parsing of the foreign key constraint actions in different order #10224

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go/vt/schemadiff/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func NewSchemaFromStatements(statements []sqlparser.Statement) (*Schema, error)
func NewSchemaFromQueries(queries []string) (*Schema, error) {
statements := []sqlparser.Statement{}
for _, q := range queries {
stmt, err := sqlparser.Parse(q)
stmt, err := sqlparser.ParseStrictDDL(q)
if err != nil {
return nil, err
}
Expand All @@ -102,7 +102,7 @@ func NewSchemaFromSQL(sql string) (*Schema, error) {
statements := []sqlparser.Statement{}
tokenizer := sqlparser.NewStringTokenizer(sql)
for {
stmt, err := sqlparser.ParseNext(tokenizer)
stmt, err := sqlparser.ParseNextStrictDDL(tokenizer)
if err != nil {
if errors.Is(err, io.EOF) {
break
Expand Down
36 changes: 36 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3902,6 +3902,9 @@ func TestCreateTable(t *testing.T) {
newCol int references simple (a) on delete cascade on update set default,
newCol int references simple (a) on delete set default on update set null,
newCol int references simple (a) on delete set null on update restrict,
newCol int references simple (a) on update set default on delete cascade,
newCol int references simple (a) on update set null on delete set default,
newCol int references simple (a) on update restrict on delete set null,
newCol int references simple (a) on update no action,
newCol int references simple (a) on update cascade,
primary key (id, username),
Expand All @@ -3912,6 +3915,39 @@ func TestCreateTable(t *testing.T) {
constraint second_ibfk_1 foreign key (k, j) references simple (a, b) on delete cascade on update set default,
constraint second_ibfk_1 foreign key (k, j) references simple (a, b) on delete set default on update set null,
constraint second_ibfk_1 foreign key (k, j) references simple (a, b) on delete set null on update restrict,
constraint second_ibfk_1 foreign key (k, j) references simple (a, b) on update set default on delete cascade ,
constraint second_ibfk_1 foreign key (k, j) references simple (a, b) on update set null on delete set default,
constraint second_ibfk_1 foreign key (k, j) references simple (a, b) on update restrict on delete set null,
constraint second_ibfk_1 foreign key (k, j) references simple (a, b) on update no action,
constraint second_ibfk_1 foreign key (k, j) references simple (a, b) on update cascade
)`,
output: `create table t (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This specific output was needed since the parser parses the actions into a struct so the ordering specifically of this is lost.

We have verified though that MySQL doesn't accidentally allows a list of these items, just only both orders so there's no potential semantic difference due to the different order.

id int auto_increment,
username varchar,
k int,
Z int,
newCol int references simple (a),
newCol int references simple (a) on delete restrict,
newCol int references simple (a) on delete no action,
newCol int references simple (a) on delete cascade on update set default,
newCol int references simple (a) on delete set default on update set null,
newCol int references simple (a) on delete set null on update restrict,
newCol int references simple (a) on delete cascade on update set default,
newCol int references simple (a) on delete set default on update set null,
newCol int references simple (a) on delete set null on update restrict,
newCol int references simple (a) on update no action,
newCol int references simple (a) on update cascade,
primary key (id, username),
key by_email (email(10), username),
constraint second_ibfk_1 foreign key (k, j) references simple (a, b),
constraint second_ibfk_1 foreign key (k, j) references simple (a, b) on delete restrict,
constraint second_ibfk_1 foreign key (k, j) references simple (a, b) on delete no action,
constraint second_ibfk_1 foreign key (k, j) references simple (a, b) on delete cascade on update set default,
constraint second_ibfk_1 foreign key (k, j) references simple (a, b) on delete set default on update set null,
constraint second_ibfk_1 foreign key (k, j) references simple (a, b) on delete set null on update restrict,
constraint second_ibfk_1 foreign key (k, j) references simple (a, b) on delete cascade on update set default,
constraint second_ibfk_1 foreign key (k, j) references simple (a, b) on delete set default on update set null,
constraint second_ibfk_1 foreign key (k, j) references simple (a, b) on delete set null on update restrict,
constraint second_ibfk_1 foreign key (k, j) references simple (a, b) on update no action,
constraint second_ibfk_1 foreign key (k, j) references simple (a, b) on update cascade
)`,
Expand Down
Loading