-
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
Improve dealing with check constraints #10268
Improve dealing with check constraints #10268
Conversation
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Bug fixes
Non-trivial changes
New/Existing features
Backward compatibility
|
There's one specific diffing optimization for check constraints that isn't implemented yet that I wanted to look at separately, which is for enabling / disabling the |
// now let's see if that name is taken; if it is, enumerate new news until we find a free name | ||
for enumerate := 2; constraintNameExists[suggestedCheckName]; enumerate++ { | ||
suggestedCheckName = fmt.Sprintf(nameFormat, c.CreateTable.Table.Name.String(), enumerate) | ||
} |
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.
is there a maxlength handling? We've seen in normal keys, that the name for key#2 and onwards is a 30 characters prefix, then padded with _2
... etc.
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.
@shlomi-noach Not yet, but since you were looking at it for regular indexes, I was wondering if it makes more sense to do that together with that one?
Let me try this out though and see what it looks like.
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, haha, I think we can ignore this case as MySQL errors on it?
mysql> create table Y3PbHeDlyEgHtCKXmLlt8mC6Oe07UadTl1o75KQmZ3eWWkpZQlKw6WN0dSBtXSEt (id int primary key, i int, foreign key (i) references parent(id));
ERROR 1059 (42000): Identifier name 'y3pbhedlyeghtckxmllt8mc6oe07uadtl1o75kqmz3ewwkpzqlkw6wn0dsbtxset_ibfk_1' is too long
So we'd fail to create the table with the normalized name in the same way then when running this against the underlying MySQL.
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.
@dbussink sounds good.
This fixes a number of issues for check constaints. First it allows parsing both `DROP CONSTRAINT` and `DROP CHECK` in the parser so we can correctly drop an existing constraint. This was missing so far and only a foreign key constraint could be dropped. Secondly, we improve dealing with constraints in schemadiff as well. Normalization there needs to generate names for constraints much like how we generate names for keys as well. We also need to teach the diffing logic then how to create the proper `DROP` statements instead of a `DROP FOREIGN KEY` for all constraints that get dropped. Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
dbd6b07
to
6b5d736
Compare
This is implemented in the follow up in #10269 |
This fixes a number of issues for check constaints. First it allows parsing both
DROP CONSTRAINT
andDROP CHECK
in the parser so we can correctly drop an existing constraint. This was missing so far and only a foreign key constraint could be dropped.Secondly, we improve dealing with constraints in schemadiff as well. Normalization there needs to generate names for constraints much like how we generate names for keys as well.
We also need to teach the diffing logic then how to create the proper
DROP
statements instead of aDROP FOREIGN KEY
for all constraints that get dropped.Related Issue(s)
Part of #10203
Checklist