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

parser: support index name in FOREIGN KEY clause; Online DDL to reject FK clauses #8058

Merged
merged 6 commits into from
May 10, 2021

Conversation

shlomi-noach
Copy link
Contributor

Description

Fixes the specific comment #8055 (comment)
The parser now supports queries of the form:

alter table corder add FOREIGN KEY my_fk (customer_id) references customer(customer_id);
  • we have added support for the index_name part of the clause (my_fk) in the above.

Online DDL now outright rejects any query that has to do with foreign keys.

Related Issue(s)

Checklist

  • Tests were added or are not required
  • Documentation was added or is not required

Deployment Notes

OnlineDDL: explicit error when foreign key clause found

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>
@shlomi-noach
Copy link
Contributor Author

shlomi-noach commented May 9, 2021

Meanwhile, f6d9ca7 adds a bit of sanity to prevent some cases of invalid ALTER TABLE queries, presented in #8057

@shlomi-noach shlomi-noach requested a review from a team May 10, 2021 04:57
go/vt/sqlparser/parse_test.go Outdated Show resolved Hide resolved
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
}

fk := &fkContraint{}
_ = sqlparser.Walk(fk.FkWalk, ddlStmt)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: You can return the error from fk.FkWalk directly, which would also abort the traversal of the AST.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

*sqlparser.TableSpec, *sqlparser.AddConstraintDefinition, *sqlparser.ConstraintDefinition:
return true, nil
case *sqlparser.ForeignKeyDefinition:
fk.found = true
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: here you could return an error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I like this! Updated code.

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@@ -216,7 +250,7 @@ func NewOnlineDDL(keyspace string, table string, sql string, ddlStrategySetting
switch stmt := stmt.(type) {
case sqlparser.DDLStatement:
if !stmt.IsFullyParsed() {
return nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "NewOnlineDDL: cannot fully parse statement %v", sqlparser.String(stmt))
return nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "NewOnlineDDL: cannot parse statement: %v", sqlparser.String(stmt))
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: To get a nice looking error message:

return nil, vterrors.NewErrorf(vtrpcpb.Code_INVALID_ARGUMENT, vterrors.SyntaxError, "NewOnlineDDL: cannot parse statement: %s", sqlparser.String(stmt))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants