Details
-
Type: Bug
-
Status: Open
-
Priority: Major
-
Resolution: Unresolved
-
Affects Version/s: 4.3.5
-
Fix Version/s: Unscheduled
-
Component/s: CiviMember, Core CiviCRM
-
Labels:None
-
Versioning Impact:Patch (backwards-compatible bug fixes)
Description
This is a database design issue. The schedule reminders functionality in our use case runs on new memberships, where we have household-inherited memberships. The generated query is 'in essence) :
SELECT cm.id AS owner_id, cm.contact_id AS owner_contact, m.id AS slave_id, m.contact_id AS slave_contact,cmt.relationship_type_id AS relation_type, rel.contact_id_a, rel.contact_id_b, rel.is_permission_a_b,rel.is_permission_b_a
FROM
civicrm_membership m
LEFT JOIN civicrm_membership cm ON cm.id = m.owner_membership_id
LEFT JOIN civicrm_membership_type cmt ON cmt.id = m.membership_type_id
LEFT JOIN
civicrm_relationship rel
ON (
( rel.contact_id_a = m.contact_id AND rel.contact_id_b = cm.contact_id AND rel.relationship_type_id = cmt.relationship_type_id )
OR
( rel.contact_id_a = cm.contact_id AND rel.contact_id_b = m.contact_id AND rel.relationship_type_id = cmt.relationship_type_id )
)
WHERE m.owner_membership_id IS NOT NULL ;
If there are no inherited memberships (i.e. owner_membership_id is always NULL) EXPLAIN gives the following :
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE m range index_owner_membership_id index_owner_membership_id 5 NULL 1 Using where
1 SIMPLE cm eq_ref PRIMARY PRIMARY 4 tijdelijke_eva.m.owner_membership_id 1
1 SIMPLE cmt eq_ref PRIMARY PRIMARY 4 tijdelijke_eva.m.membership_type_id 1
1 SIMPLE rel ref FK_civicrm_relationship_contact_id_a,FK_civicrm_relationship_contact_id_b,FK_civicrm_relationship_relationship_type_id FK_civicrm_relationship_relationship_type_id 4 tijdelijke_eva.cmt.relationship_type_id 1540
indicating that the index_owner_membership_id is used. When there are active owners (in our case, 18597 rows out of 43706 are inherited and therefore have an owner set) EXPLAIN turns into this
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE m ALL index_owner_membership_id NULL NULL NULL 43590 Using where
1 SIMPLE cm eq_ref PRIMARY PRIMARY 4 tijdelijke_eva.m.owner_membership_id 1
1 SIMPLE cmt eq_ref PRIMARY PRIMARY 4 tijdelijke_eva.m.membership_type_id 1
1 SIMPLE rel ref FK_civicrm_relationship_contact_id_a,FK_civicrm_relationship_contact_id_b,FK_civicrm_relationship_relationship_type_id FK_civicrm_relationship_relationship_type_id 4 tijdelijke_eva.cmt.relationship_type_id 1540
The query now runs for 50 seconds because of this.