I don't think there is a reason to have an index on the column "entity_type", when the primary key is already [entity_type, entity_id, deleted, delta, language].
Not sure about other database engines, but MySQL would just use the first part of the primary key if you had a query selecting rows by entity_type.
----------------
Also (though I'm not sure on these ones), some of the other indexes are also worth re-evaluating...
entity_id is probably never used without "entity_type", so that would be covered by the primary key as well.
revision_id is unique within each entity_type, just like entity_id, as far as I know. So it will commonly be used without "entity_id", but never without "entity_type". That means another multi-column index [entity_type, revision_id] might make more sense.
language could be used to globally delete all content of a language. But I don't know if that is ever done. Otherwise it would have no purpose either. Same goes for bundle and deleted.
Comments
Comment #1
ralf.strobel CreditAttribution: ralf.strobel commentedAll of this goes for the "field_revision_field_xxx" tables as well, of course.
Comment #2
ralf.strobel CreditAttribution: ralf.strobel commentedAnother note:
InnoDB appends the primary key fields to the entries of every secondary index. Since the primary key is currently quite long, encompassing almost all fields, this gives even more reason to reduce the number of secondary indexes.
I just checked on some of my field data tables and the index takes about 7 times more space than the actual data! And that's while most of the columns are for structure and don't even store the actual field data, so the real overhead is probably a lot bigger.
Comment #3
ralf.strobel CreditAttribution: ralf.strobel commentedAlright, since nobody seemed to care about this when I posted it in D7, I'm now changing it to D8 and hoping for a backport to D7. I've checked that the issue is just as valid for D8.
Affected code is in field_sql_storage.module, _field_sql_storage_schema():
I suggest this instead:
Comment #3.0
ralf.strobel CreditAttribution: ralf.strobel commentedMoved some parts of my comment #1 into the main issue.
Comment #12
catchThese have changed a bit, we currently have the following:
Primary key: entity_id, deleted, delta, langcode
bundle, bundle
revision_id, revision_id
field_{tags_target_id} field_{tags_target_id}
Or as a SHOW INDEXES:
However, I really wonder whether we have many queries using the bundle or revision ID indexes, so it's possible those could be dropped.
This issue might be a duplicate of/duplicated by others elsewhere, but haven't found them to link to yet.
Comment #16
pameeela CreditAttribution: pameeela commentedBased on the OP and the comment by @catch, I think this is a task rather than a bug, as nothing is broken but could be improved.