Problem/Motivation
Now that the fields are split up as per-entity tables (this is awesome by the way!), There's a column that really shouldn't exist (I'm actually not sure why it existed in Drupal 7 either).
The column is "bundle". I'm not sure what the point of it is. To me it looks like duplicated data. Why in the world does Drupal need to store the bundle on each and every field value? This data is easily available in the entity table (node, taxonomy_term_data, etc.).
Not only is the data duplicated, but it also could potentially lead to a unnecessary data mismatch. Since Drupal does not fully support Foreign Key constraints #911352: Document that foreign keys may not be used by all drivers, it is possible that the data in the field table does not match what is in the entity table.
The only reason I can think of for this data to exist is that an entity of some sort relies on the field data to tell it what bundle the entity is. I can't think of any entity that is like that (if it's even allowed). And if it is allowed, it's a pretty terrible practice anyways.
Could we either remove the column, or could we have an explanation for it's existence?
Thanks!
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | 2163735-19.patch | 4.73 KB | longwave |
Comments
Comment #1
swentel commentedThe column is used when we need to purge field values, see field_purge_batch().
Comment #2
davidwbarratt commentedswentel,
The function you mentioned field_purge_batch(). Uses the "entity.query" service. Not only does it require an "entity_type" (node, user, etc.), but the class calls the initial query against the entity table (from my understanding).
Are you saying that the the "entity.query" service ignores the entity table completely when making queries and only queries against the field tables? I suppose that's slightly more efficient, but not at the cost of the immense amount of duplicated data and possible data mis-match.
Please do not close this issue until someone can explain 1) WHY it needs to be this way and 2) Does the costs of the current design outweigh the benefits?
peace & love
Comment #3
swentel commentedI'll let yched weight in on this.
Still, nowhere near critical. Stop doing that, it's annoying.
Comment #4
yched commentedThat info is used when a field instance is deleted - e.g remove the "body" field on 'article' nodes. This happens in FieldableDatabaseStorageController::onInstanceDelete().
We could write that query by joining from the base table (although it doesn't look like our DB API actually lets us write such a query), but this might cause perf impact on large databases. Notably, when a node type gets deleted, we loop this on every field instance present in the node type.
At any rate, yes, nothing there qualifies as critical.
Comment #5
davidwbarratt commentedyched,
Interesting.
IMHO, the Join (and slight loss of performance) would be better than the immense amount of extra data (on large databases) and possible data mis-match.
Data integrity should almost always trump data performance.
peace & love
Comment #18
longwaveJust ran into this after changing the bundle of a number of entities, and wondered why everything still appeared to work, even though the bundle column in the field data tables still referred to the old bundle name.
Technically I think this is a bug somewhere, given you can have two bundles with similar/identical fields, and then do
and then later delete a field on
new_bundle- the data won't be cleaned up properly if the summary in the comments above is correct.Comment #19
longwaveProof of concept that works locally for creating, editing and viewing a node, but doesn't refactor the bulk deletion code which expects the bundle column - let's see how many tests blow up.
Changing a bundle as in the comment above also likely has an effect on multilingual sites given the bundle is needed there, that is probably another subtle bug. I realise just changing the bundle like that probably shouldn't be supported, but it does work without error.
Comment #20
smustgrave commentedSeems a number of failures in the last both.
Will this require an update hook as well?
Comment #21
quietone commentedyched had not worked on this for 9 years, un-assigning. Added standard IS template.
Comment #24
catchBecause we have an index on the bundle field, removing the column and the index would reduce the total memory requirement for
innodb_buffer_pool_size.If it was one table it wouldn't matter much, but this is across often 100-300 field tables and the equivalent revision tables on many sites, so we're looking at losing potentially 200-600 indexes on quite high cardinality tables.