Project

General

Profile

Actions

Task #101425

closed

TYPO3 and MariaDB Galera Cluster (PRIMARY KEY)

Added by Ralph Brugger 9 months ago. Updated 3 months ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
System/Bootstrap/Configuration
Target version:
-
Start date:
2023-07-24
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
11
PHP Version:
8.1
Tags:
Complexity:
easy
Sprint Focus:

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


Related issues 7 (1 open6 closed)

Related to TYPO3 Core - Feature #95061: Auto creation of MM tables from TCAClosed2021-08-31

Actions
Related to TYPO3 Core - Task #101528: Fix MM TCA of blog_exampleClosed2023-08-02

Actions
Related to TYPO3 Core - Task #101537: Have correct blog_example related_posts TCAClosed2023-08-02

Actions
Related to TYPO3 Core - Task #101554: Get rid of MM_hasUidFieldClosed2023-08-03

Actions
Related to TYPO3 Core - Bug #101720: sys_category_mm does not have a unique keyClosed2023-08-21

Actions
Related to TYPO3 Core - Task #101731: Adjust auto-created column length for MM tablesClosedStefan Bürk2023-08-22

Actions
Related to TYPO3 Core - Bug #103604: MM table generation sets wrong PRIMARY KEY for columns with multiple=1Needs Feedback2024-04-11

Actions
Actions #1

Updated by Ralph Brugger 9 months ago

  • Tracker changed from Bug to Task
Actions #3

Updated by Ralph Brugger 9 months 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.

Actions #4

Updated by Ralph Brugger 9 months ago

Or should we set - to get compatible with Galera?

multiple = FALSE
MM_hasUidField = TRUE
Actions #5

Updated by Christian Kuhn 9 months 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.

Actions #6

Updated by Christian Kuhn 9 months ago

  • Related to Feature #95061: Auto creation of MM tables from TCA added
Actions #7

Updated by Christian Kuhn 9 months ago

Actions #8

Updated by Christian Kuhn 9 months ago

  • Related to Task #101537: Have correct blog_example related_posts TCA added
Actions #9

Updated by Gerrit Code Review 9 months 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

Actions #10

Updated by Gerrit Code Review 9 months 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

Actions #11

Updated by Ralph Brugger 9 months 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!

Actions #12

Updated by Gerrit Code Review 9 months 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

Actions #13

Updated by Christian Kuhn 9 months ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #14

Updated by Christian Kuhn 9 months ago

Actions #15

Updated by Christian Kuhn 8 months ago

  • Related to Bug #101720: sys_category_mm does not have a unique key added
Actions #16

Updated by Stefan Bürk 8 months ago

  • Related to Task #101731: Adjust auto-created column length for MM tables added
Actions #17

Updated by Benni Mack 3 months ago

  • Status changed from Resolved to Closed
Actions #18

Updated by Stefan Bürk 11 days ago

  • Related to Bug #103604: MM table generation sets wrong PRIMARY KEY for columns with multiple=1 added
Actions

Also available in: Atom PDF