Problem/Motivation

Single cardinality configured fields are always stored in a dedicated field table. This decision was taken in the early days of adding field API to core, so that we wouldn't need to move data between shared/dedicated tables when cardinality changed, however we should revisit that.

- dedicated tables mean duplication of id, revision id, language etc. and the indexes for those columns, meaning bigger databases and more indexes. The end result of this is higher disk space and more memory needed for innodb_buffer_pool_size

- until recently, it used to mean lots of individual queries when loading entities, after #3562172: Single cardinality entity fields are now loaded from the database at once it's lots of joins, but still not ideal

- similarly when saving entities it's lots of individual writes.

- entity and views queries end up adding conditions and sorts across tables, which leads to temporary tables/filesorts/full table scans etc. which can often be avoided if these are all against one table.

- we already have a very similar data migration in core - when a base field is deleted, we copy the data to a separate deleted field table, for field batch purging to then purge, using an INSERT INTO .. SELECT FROM - so the base logic already exists.

Steps to reproduce

Proposed resolution

Add a flag on field storage as to whether it should use shared storage or not. This flag can be set when the field is created, and we can also allow for changing it later with the data migration to/from the shared tables (base table or field data table depending on translatability etc.).

Remaining tasks

Follow-up issues:

1. An issue to discuss adding a UI option fo rthis, we could prevent it being changed (in the UI) for existing fields with data, but it would allow site builders to control it when creating new fields.

2. An issue to add a hook_requirements() warning on MySQL when the table is approaching the MySQL row size and indexes-per-table limit.

Between #1 and #2 we can also decide what the default should be. But all those decisions can be out of scope in this issue, where we can leave it as opt-in,

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Comments

catch created an issue. See original summary.

catch’s picture

Note that the title here is similar to #3183359: Allow single-value base fields to be saved to dedicated database tables but that's asking for doing the complete opposite - allowing base fields to be put in dedicated tables. We may be able to end up using the same mechanism/flag for both, but the functionality isn't duplicate.

amateescu’s picture

Assigned: Unassigned » amateescu

Working on this :)