relation_get_related_entity() causes a temporary table:



SELECT DISTINCT field_data_endpoints0.entity_type AS entity_type, field_data_endpoints0.entity_id AS entity_id, field_data_endpoints0.revision_id AS revision_id, field_data_endpoints0.bundle AS bundle FROM field_data_endpoints field_data_endpoints0 INNER JOIN field_data_endpoints field_data_endpoints1 ON field_data_endpoints1.entity_type = field_data_endpoints0.entity_type AND field_data_endpoints1.entity_id = field_data_endpoints0.entity_id WHERE (field_data_endpoints0.endpoints_entity_type = :db_condition_placeholder_0) AND (field_data_endpoints1.endpoints_entity_id = :db_condition_placeholder_1) AND (field_data_endpoints1.delta = field_data_endpoints0.delta) AND (field_data_endpoints0.deleted = :db_condition_placeholder_2) AND (field_data_endpoints0.entity_type = :db_condition_placeholder_3) AND (field_data_endpoints0.bundle = :db_condition_placeholder_4) LIMIT 50 OFFSET 0


id	select_type	table	type	possible_keys	key	key_len	ref	rows	extra
1	SIMPLE	field_data_endpoints0	ref	PRIMARY,entity_type,bundle,deleted,entity_id,endpoints_relation	bundle	386	const	3820	Using where; Using temporary
1	SIMPLE	field_data_endpoints1	ref	PRIMARY,entity_type,entity_id	PRIMARY	390	const,itv.field_data_endpoints0.entity_id	1	Using where; Distinct

Attached patch doesn't try to fix the query since that would involve removing the DISTINCT that EntityFieldQuery adds, this might be worth looking at but it's unlikely to be fixable in relation. Instead I'm persistently caching relations, then clearing in relation_save() for all endpoints.

, but just adds caching of relations for now

Comments

catch’s picture

Status: Active » Needs review
StatusFileSize
new1.64 KB
catch’s picture

StatusFileSize
new1.58 KB

Didn't mean to take out the static cache clear.

catch’s picture

StatusFileSize
new3.28 KB

Here's one with tests, I verified that the test fails if the cache clear is removed, current test coverage would not have caught this.

catch’s picture

StatusFileSize
new1.2 KB

Found a bug.

catch’s picture

StatusFileSize
new1.21 KB
chx’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.