Problem/Motivation
After #2875033: Optimize joins and table selection in SQL entity query implementation, UUID entity query lookups are improved, but are still too complicated:
SELECT "base_table"."vid" AS "vid", "base_table"."nid" AS "nid" FROM "node" "base_table" INNER JOIN "node_field_data" "node_field_data" ON "node_field_data"."nid" = "base_table"."nid" WHERE ("base_table"."uuid" IN ("677f9911-f002-4639-9891-5c39e8b00d9d")) AND ("node_field_data"."default_langcode" IN (1))
It joins the node_field_data table to add the default_langcode condition. But it only needs that condition *because* it joins the node_field_data table, there is only one row in the base table for this case.
Steps to reproduce
Proposed resolution
If an entity query only has a condition on UUID, then we could only query the base table and avoid the join completely.
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Comments
Comment #3
berdirThe fundamental change here is easier than expected. This moves the order in which $entity_tables is prepared so that the base table is first, as a result, if we find the column in there, for example the uuid, but would also apply to the ID for example. I then also moved the simple query flag and only add that when we don't run against the base table.
That worked in manual testing with \Drupal\block_content\BlockContentUuidLookup::resolveCacheMiss(), it did not yet apply to the json api performance test. Turns out, that's because of the special logic around the default langcode in \Drupal\Core\Entity\Sql\SqlContentEntityStorage::buildPropertyQuery(), I added a check to skip that if the only condition is the uuid.
This is obviously going to fail tests, I didn't adjust entity query tests yet, I also expect that the revision logic needs some updates for example.
Comment #4
papagrandeFixed a typo.