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

CommentFileSizeAuthor
#19 2163735-19.patch4.73 KBlongwave

Comments

swentel’s picture

Priority: Critical » Normal
Status: Active » Closed (works as designed)

The column is used when we need to purge field values, see field_purge_batch().

davidwbarratt’s picture

Priority: Normal » Critical
Status: Closed (works as designed) » Active

swentel,

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

swentel’s picture

Assigned: Unassigned » yched
Priority: Critical » Normal

I'll let yched weight in on this.

Still, nowhere near critical. Stop doing that, it's annoying.

yched’s picture

That 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.

davidwbarratt’s picture

yched,

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

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

longwave’s picture

Just 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

$node->set('type', 'new_bundle')->save()

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.

longwave’s picture

Version: 9.5.x-dev » 10.1.x-dev
Status: Active » Needs review
StatusFileSize
new4.73 KB

Proof 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.

smustgrave’s picture

Status: Needs review » Needs work

Seems a number of failures in the last both.

Will this require an update hook as well?

quietone’s picture

Assigned: yched » Unassigned
Issue summary: View changes

yched had not worked on this for 9 years, un-assigning. Added standard IS template.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

catch’s picture

Priority: Normal » Major
Issue tags: +Performance

Because 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.