Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
It is common to load profiles by uid, type, status and is_default to get the default profile for a user. This is a bottleneck on busier commerce installs, especially with many anonymous profiles. I'd imagine the same problems could happen in non-commerce usages.
index to add
create index profile_test ON profile(uid, type, status, is_default);
The order of this index means it also allows indexes of
uid
uid, type
uid, type, status
Patch to follow
Comment | File | Size | Author |
---|---|---|---|
#2 | profile-add_index-3017788-2.patch | 2.05 KB | smccabe |
Comments
Comment #2
smccabe CreditAttribution: smccabe as a volunteer and at Acro Commerce commentedComment #3
AnybodyThis definitely makes sense. Can you perhaps give an overview which indexes are currently set on profiles? If none, this is definitely RTBC!
If not we should consider to update them.
Are these SQL statements generated in a public method of the module or called outside in other modules?
Thank you very much!
Comment #4
smccabe CreditAttribution: smccabe as a volunteer and at Acro Commerce commentedThe default indexes are:
profile_id
uuid
revision_id
type
uid
The statements are called outside the module primarily, as there are not really any searches or bulk loads within the module itself. Since these are common parameters of the profile, they are likely search parameters, although they are used in Commerce, which is the biggest use case for Profile.
Comment #5
AnybodyHi smccabe,
thank you for your clarification. I agree it would make sense to add status to the indexes. We should now decide if one of the existing indexed should be altered or simply add another. For a good decision we could have a look at similar cases or how the current indexes are used. Perhaps replace uid by the new index would make sense for that decision tree?
Comment #6
mglamanThe existing indexes are generated by field column definitions. Anything aggregated like this needs to be determined in the entity schema.
It'd be great if we had some EXPLAIN on queries (like even in Devel's Webprofiler.)
FWIW our ProfileStorage shows the benefit of this directly:
and
Comment #7
mglaman@smccabe has offered to bring some old testing instances online and provide some results!
Comment #9
mglamanRerolled and committed.
Comment #10
AnybodyThank you @mglaman!! :)