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.
Problem/Motivation
The content moderation views joins only on the revision ID. However, the table only has an index on both entity ID and revision ID. This was leading to very slow queries.
To reproduce, create a view of entity revisions and add a content moderation field.
Proposed resolution
Adding the join on entity ID and revision ID makes these queries faster, since the queries generated by views can now use the index.
Remaining tasks
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#8 | 3112916-8.patch | 2 KB | Sam152 |
#5 | core-content_moderation-join-on-entity-id.patch | 795 bytes | Sam152 |
#4 | core-content_moderation-join-on-entity-id.patch.txt | 795 bytes | Sam152 |
core-content_moderation-join-on-entity-id.patch | 795 bytes | realkevinoshea | |
Comments
Comment #2
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedComment #3
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedComment #4
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedHm, not sure why the patch can't be tested. Reuploading might help?
Really interesting issue. It would be really helpful to do some profiling on a large view before and after this change to validate it for committers.
I'm not sure testing this makes sense. Since functionally things should work the same before and after the patch, any test would just be copying details of the implementation into a test, so this is the kind of thing I'd be comfortable marking RTBC without explicit test coverage.
Lets see what the bot says.
Comment #5
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedWrong extension, lets see about this one.
Comment #7
realkevinoshea CreditAttribution: realkevinoshea at Ocelot commented@Sam152: as it had been a couple months it took me a moment to remember the details of this. I think the issue is pretty clear from the explain. If I can find some time I could write a quick example code to trigger the issue. Take a look at this:
In the `content_moderation_state__lookup` index the revision ID is the 3rd in the sequence. So originally that index could not be used because the content_entity_id was not present in the join.
Comment #8
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedNice, thanks for the explanation.
I argued against including assertions like this in the views tests, but since they already exist, using for the new join.
Comment #9
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedI ran some profiling on the queries generated by views before and after the patch applied:
This seems like a dramatic speed up. I'm comfortable RTBCing, since I did not write the patch and the test fix is essentially duplicating the implementation.
Comment #11
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedRandom fail.
Comment #12
jonnyeom CreditAttribution: jonnyeom as a volunteer commentedThanks for the patch!
This is a good one.
+1 RTBC
Comment #14
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedComment #15
godotislate CreditAttribution: godotislate commented+1 RTBC
Comment #16
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedRealising I wrote the original patch in #5, but it was @ocelotkevin who came up with the fix 🤦
I probably shouldn't have RTBC'd, but #12 and #15 have been posted since.
Comment #18
bkosborne+1 RTBC. I tested this on a very complex view.
Before patch, query execute time was ~170 seconds.
After patch, query execute time was ~3 seconds.
The results of the view were identical before and after the patch.
Comment #21
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedThanks for following up and testing @bkosborne.
Adding users who were credited in #3097303: Poor performance when using moderation state views filter to this issue, since they were solving the same problem but in slightly different ways.
Comment #23
godotislate CreditAttribution: godotislate commentedRandom test failure.
Comment #24
jantoine CreditAttribution: jantoine as a volunteer commented+1 RTBC. I just ran into this issue with a query taking 6+ minutes to complete. With the patch from #8, the query takes less than .62 seconds.
Comment #25
catchNice find. Committed/pushed to 9.1.x and cherry-picked back to 8.9.x, thanks!
Comment #30
joseph.olstadwhile it's nice to have the join, if we want to sort by moderation state some modes of MySQL (defaults for certain versions) require the sort column to be in the select statement. This is a constraint oracle is adding into MySQL releases.
See
core/modules/views/src/Plugin/views/field/EntityField.php
"Column is not in query; add a sort on it (without adding the column)."
More info on sql mode changes in 5.7:
https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sql-mode-changes
Comment #31
joseph.olstad