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

NativeDDL: analyzing added&removed unique keys #8495

Merged

Conversation

shlomi-noach
Copy link
Contributor

Description

First, we're unofficially adopting the term "NativeDDL" for OnlineDDL/VReplication based migrations.
In this PR we add an analysis: does the migration introduce any new unique key constraints? Does it remove any unique key constraints?

The analysis isn't necessarily for a specific key. It is about the overall state of the table before/after migration. Is there a set of columns that was previous unconstrained and now forms a unqieu constraints? Regardless of how we got there, whether by ADD KEY or REMOVE KEY.

The information is persisted in schema_migrations table in these columns:

  • added_unique_keys
  • removed_unique_keys

both int unsigned not null default 0, and indicate the number of added constraints and number of removed constraints, respectively.

Why

This is fundamental to automating revertible migrations. Not all migrations are revertible. If you add a new constraint, and start using it, then reverting back to old table means you are now able to add what you consider as duplicates. And if you revert-the-revert (roll forward), then that may fail altogether.

So in this PR we first collect the information. Later on we can have educated logic based on that information.

Nothing right now actually uses the information gathered in this PR (other than in endtoend tests).

Change is tested in unit&endtoend tests.

Related Issue(s)

#6926

Checklist

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

…unique constraint

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>
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 shlomi-noach added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: Query Serving labels Jul 19, 2021
Copy link
Member

@deepthi deepthi left a comment

Choose a reason for hiding this comment

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

LGTM

@shlomi-noach shlomi-noach merged commit e86d2db into vitessio:main Jul 20, 2021
@shlomi-noach shlomi-noach deleted the onlineddl-vrepl-adds-unique-key branch July 20, 2021 03:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Query Serving Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants