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

Fixes #2105 - database tables can't be created on MySQL >= 8.4 because KEY is not unique #291

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ntavares
Copy link

Quote:

When using MySQL 8.4 or higher, there are a few tables that can't be created because a Key is not unique and there is a foreign key that references it, and from MySQL 8.4 it's not allowed to reference non-unique KEYs.

the keys that are bad (not UNIQUE) are:
Object.id-tid
TagTree.id-is_assignable

The fix:
ALTER TABLE Object DROP KEY `id-tid`, ADD UNIQUE KEY `id-tid` (`id`,`objtype_id`);
ALTER TABLE TagTree DROP KEY `id-is_assignable`, ADD UNIQUE KEY `id-is_assignable` (`id`,`is_assignable`);

Additional info: https://bugs.mysql.com/bug.php?id=114838

Nuno Tavares added 2 commits December 12, 2024 17:10
…e a PK ....

Group Replication requires tables to use InnoDB and have a PRIMARY KEY or PRIMARY KEY Equivalent (non-null unique key). Tables that do not follow these requirements will be readable but not updateable when used with Group Replication. If your applications make updates (INSERT, UPDATE or DELETE) to these tables, ensure they use the InnoDB storage engine and have a PRIMARY KEY or PRIMARY KEY Equivalent.

Ref: https://dev.mysql.com/doc/refman/8.4/en/group-replication-requirements.html

If you can't change the tables structure to include an extra visible key to be used as PRIMARY KEY, you can make use of the INVISIBLE COLUMN feature available since 8.0.23: https://dev.mysql.com/doc/refman/en/invisible-columns.html

Signed-off-by: Nuno Tavares <n.tavares@portavita.eu>
@ntavares
Copy link
Author

ntavares commented Dec 16, 2024

I've added an additional commit as we've came across another issue at restoring an old MySQL backup onto MySQL 8.4. These changes are non-breaking.

Group Replication requires tables to use InnoDB and have a PRIMARY KEY or PRIMARY KEY Equivalent (non-null unique key). Tables that do not follow these requirements will be readable but not updateable when used with Group Replication. If your applications make updates (INSERT, UPDATE or DELETE) to these tables, ensure they use the InnoDB storage engine and have a PRIMARY KEY or PRIMARY KEY Equivalent.

Ref: https://dev.mysql.com/doc/refman/8.4/en/group-replication-requirements.html

If you can't change the tables structure to include an extra visible key to be used as PRIMARY KEY, you can make use of the INVISIBLE COLUMN feature available since 8.0.23: https://dev.mysql.com/doc/refman/en/invisible-columns.html

@infrastation I was going to patch upgrade.php as well, but there's no slot for the "next version" and I don't know what's the release plan. If that changes, or you suggest the "next version" to add to, I'd be happy to provide that as well.

@infrastation
Copy link
Member

The second change does not look right, let me have some time to verify that. Let's solve one problem at a time.

upgrade.php now has a section for the next release, which is going to be 0.21.1. One issue with the proposed change is that it does not state the problem correctly. As I mentioned in the bug report, the keys have been unique for a very long time. The loss of capability in MySQL to recognise unique keys as such is a new thing and is the problem.

@ntavares
Copy link
Author

ntavares commented Dec 16, 2024

@infrastation thank you for the followup. A bit of context: while migrating from MySQL 5.x single server to MySQL 8(.4) HA setup, the database dump will not load. Both commits are related to that - that could well be the title of #2105 - I'm not sure how you'd like it to be rephrased... We did not run the install.php, but considering the timing of the error (upon CREATE TABLE) I expect Racktables to not install on MySQL 8.4 in its current form.

PS: Despite me running cardinality tests against IPv4LB, I only now realised our tables are empty - we don't use that funcionality... I've only changed it to PRIMARY KEY to get rid of the warnings while being able to reuse the index but if you need the NULLs then we'll have to use the "invisible PK" for this to suceed - therefore adding to the table rather than reusing that index.

Thanks for the additions in upgrade.php, I'll add them later, depending on your verification of the above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants