-
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
parser: support index name in FOREIGN KEY clause; Online DDL to reject FK clauses #8058
parser: support index name in FOREIGN KEY clause; Online DDL to reject FK clauses #8058
Conversation
OnlineDDL: explicit error when foreign key clause found Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
go/vt/schema/online_ddl.go
Outdated
} | ||
|
||
fk := &fkContraint{} | ||
_ = sqlparser.Walk(fk.FkWalk, ddlStmt) |
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.
nit: You can return the error from fk.FkWalk
directly, which would also abort the traversal of the AST.
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.
done!
go/vt/schema/online_ddl.go
Outdated
*sqlparser.TableSpec, *sqlparser.AddConstraintDefinition, *sqlparser.ConstraintDefinition: | ||
return true, nil | ||
case *sqlparser.ForeignKeyDefinition: | ||
fk.found = true |
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.
nit: here you could return an error
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.
Oh I like this! Updated code.
Signed-off-by: Shlomi Noach <[email protected]>
@@ -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)) |
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.
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))
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.
done
Signed-off-by: Shlomi Noach <[email protected]>
Description
Fixes the specific comment #8055 (comment)
The parser now supports queries of the form:
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
Deployment Notes