github / gh-ost

GitHub's Online Schema-migration Tool for MySQL
MIT License
12.43k stars 1.26k forks source link

Improve logic to include originalUniqueKey in sharedUniqueKeys #1453

Open htmsousa opened 2 months ago

htmsousa commented 2 months ago

Until now, when building the list of SharedUniqueKeys, the code was selecting only the originalUniqueKeys that existed in ghostUniqueKeys list.

However, as part of the alter table, it is possible to add more unique keys or even composed primary keys with multiple columns.

The new logic keeps the old behaviour (it matches originalUniqueKey with exactly the same ghostUniqueKey) but also supports the cases where the originalUniqueKey is now a subset of one of the new ghostUniqueKeys.

If such a case happens, we can still use the originalUniqueKey as normal because a new ghostUniqueKey with the columns of originalUniqueKey plus some new columns is inherently unique just by the columns in the originalUniqueKey, no matter the value in the new columns of the new unique key.

A Pull Request should be associated with an Issue.

We wish to have discussions in Issues. A single issue may be targeted by multiple PRs. If you're offering a new feature or fixing anything, we'd like to know beforehand in Issues, and potentially we'll be able to point development in a particular direction.

Related issue: https://github.com/github/gh-ost/issues/1452

Further notes in https://github.com/github/gh-ost/blob/master/.github/CONTRIBUTING.md Thank you! We are open to PRs, but please understand if for technical reasons we are unable to accept each and any PR

Description

This PR [briefly explain what it does]

In case this PR introduced Go code changes: