Task #101425
closedTYPO3 and MariaDB Galera Cluster (PRIMARY KEY)
100%
Description
In the Known Limitations of the MariaDB Galera Cluster you can read:
https://mariadb.com/kb/en/mariadb-galera-cluster-known-limitations/
All tables should have a primary key (multi-column primary keys are supported). DELETE operations are unsupported on tables without a primary key. Also, rows in tables without a primary key may appear in a different order on different nodes.
In our project we have a lot mm-tables that don't have a primary key:
TYPO3:
sys_category_record_mm
EXTENSIONS:
tx_rsmevents_event_category_mm
...
For TYPO3 it's normal to NOT have a primary key on MM-Tables:
https://docs.typo3.org/m/typo3/reference-tca/11.5/en-us/ColumnsConfig/CommonProperties/Mm.html#tca-property-mm
If you have a look at the LogWriter-Docu there is a hint about Galera:
https://docs.typo3.org/m/typo3/reference-coreapi/11.5/en-us/ApiOverview/Logging/Writers/Index.html
If you are using a MariaDB Galera Cluster you should definitely add a primary key field to the database definition, since it is required by Galera (this can be a normal uid autoincrement field as known from other tables): MariaDB Galera Cluster - Known Limitations.
So what for the mm-tables?
We could add:
a) an uid field with auto_increment and PRIMARY KEY
CREATE TABLE anytable_MM ( uid int(11) NOT NULL auto_increment, .. PRIMARY KEY (uid), );
b) or add an multi-column primary key on uid_local uid_foreign - I'm not sure if this is possible, or there can de duplicates.
CREATE TABLE anytable_MM ( uid_local int(11) DEFAULT '0' NOT NULL, uid_foreign int(11) DEFAULT '0' NOT NULL, ... PRIMARY KEY (uid_local,uid_foreign), );
I think the combination of uid_local and uid_foreign could or should be unique.
But I'm not sure, so solution a) should be the better solution.
Ralph
Updated by Ralph Brugger over 1 year ago
Sorry, I think I know that, but maybe I got you wrong.
Let's say we do not define the SQL for an MM-relation table because it's not needed anymore:
"The table defined in this property is automatically created by the Database Analyzer starting with v11.4."
mm-Relation with multiple = FALSE
If we have a mm-Relation with multiple = FALSE, we don't set MM_hasUidField.
The Database Analyzer will create a table like this:
fields:
uid_local int(10) unsigned [0] uid_foreign int(10) unsigned [0] sorting int(10) unsigned [0] sorting_foreign int(10) unsigned [0]
Indizes
INDEX uid_local INDEX uid_foreign
=> so we wouldn't be compatible with Galera.
If the relations are not multiple it should be possible to add a primary key for:
PRIMARY KEY (uid_local,uid_foreign),
But the install tool doesn't create it like that.
mm-Relation with multiple = TRUE and MM_hasUidField = TRUE
If we have a mm-Relation with multiple = TRUE, we have to set MM_hasUidField = TRUE.
"The table defined in this property is automatically created by the Database Analyzer starting with v11.4."
The Database Analyzer will create a table like this:
fields:
uid int(10) unsigned Auto-Inkrement uid_local int(10) unsigned [0] uid_foreign int(10) unsigned [0] sorting int(10) unsigned [0] sorting_foreign int(10) unsigned [0]
Indizes
PRIMARY uid INDEX uid_local INDEX uid_foreign
=> so we would be compatible with Galera.
Updated by Ralph Brugger over 1 year ago
Or should we set - to get compatible with Galera?
multiple = FALSE MM_hasUidField = TRUE
Updated by Christian Kuhn over 1 year ago
I'm aware of the issue with MM having no primary key if there is no uid column for a while already, and had a @todo on this in the code for some time.
The workaround for now was exactly as you described: keep 'multiple' false, but set 'MM_hasUidField' true, just to trigger the uid column generation.
We now did some other preparation, and will finally fix this issue in main and v12 now, though. The 'MM_hasUidField' is afterwards obsolete and will be deprecated in v13 with yet another patch.
Updated by Christian Kuhn over 1 year ago
- Related to Feature #95061: Auto creation of MM tables from TCA added
Updated by Christian Kuhn over 1 year ago
- Related to Task #101528: Fix MM TCA of blog_example added
Updated by Christian Kuhn over 1 year ago
- Related to Task #101537: Have correct blog_example related_posts TCA added
Updated by Gerrit Code Review over 1 year ago
- Status changed from New to Under Review
Patch set 3 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/80281
Updated by Gerrit Code Review over 1 year ago
Patch set 4 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/80281
Updated by Ralph Brugger over 1 year ago
Thanks a lot Christian for your feedback!
We have one week left to check our new server environment, before we will switch to the new hardware plattform, and didn't have any problem with our new Galera environment.
There was one query with an join over an MM-Table where "uid" wasn't unique in the query.
But that's our fault:)
Also our 4 parallel web-servers (4x Apache web-servers, 4x nginx Proxy / cache behind, one Kemp load-balancer) are wortking fine.
Thanks again!
Updated by Gerrit Code Review over 1 year ago
Patch set 1 for branch 12.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/80308
Updated by Christian Kuhn over 1 year ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 1acd10080c24f805b6fafc8f6c5a18ad67e464a0.
Updated by Christian Kuhn over 1 year ago
- Related to Task #101554: Get rid of MM_hasUidField added
Updated by Christian Kuhn over 1 year ago
- Related to Bug #101720: sys_category_mm does not have a unique key added
Updated by Stefan Bürk over 1 year ago
- Related to Task #101731: Adjust auto-created column length for MM tables added
Updated by Stefan Bürk 7 months ago
- Related to Bug #103604: MM table generation sets wrong PRIMARY KEY for columns with multiple=1 added