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
manualcrop does the following query when file_entity_revisions is enabled:
riaDB [web]> EXPLAIN SELECT c.x, c.y, c.width, c.height FROM manualcrop c INNER JOIN file_managed_revisions f ON c.fid = f.fid WHERE c.style_name = 'foo' AND f.uri = 'public://foo/foo.png' ORDER BY c.vid DESC;
+------+-------------+-------+------+---------------+---------+---------+----------------+-------+----------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+------+---------------+---------+---------+----------------+-------+----------------------------------------------+
| 1 | SIMPLE | f | ALL | fid | NULL | NULL | NULL | 31084 | Using where; Using temporary; Using filesort |
| 1 | SIMPLE | c | ref | PRIMARY | PRIMARY | 4 | web.f.fid | 1 | Using where |
+------+-------------+-------+------+---------------+---------+---------+----------------+-------+----------------------------------------------+
2 rows in set (0.00 sec)
With the patch:
MariaDB [web]> EXPLAIN SELECT c.x, c.y, c.width, c.height FROM manualcrop c INNER JOIN file_managed_revisions f ON c.fid = f.fid WHERE c.style_name = 'foo' AND f.uri = 'public://foo/foo.png' ORDER BY c.vid DESC;
+------+-------------+-------+------+---------------+---------+---------+----------------+------+--------------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+------+---------------+---------+---------+----------------+------+--------------------------------------------------------+
| 1 | SIMPLE | f | ref | fid,uri | uri | 767 | const | 3 | Using index condition; Using temporary; Using filesort |
| 1 | SIMPLE | c | ref | PRIMARY | PRIMARY | 4 | web.f.fid | 1 | Using where |
+------+-------------+-------+------+---------------+---------+---------+----------------+------+--------------------------------------------------------+
2 rows in set (0.00 sec)
Proposed resolution
See patch.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#6 | file-entity-revisions-2664388-6.patch | 1.48 KB | David_Rothstein |
#5 | 2664388.patch | 1.47 KB | catch |
#3 | 2664388.patch | 731 bytes | catch |
#2 | 2664388.patch | 917 bytes | catch |
Comments
Comment #2
catchComment #3
catchWrong patch.
Comment #4
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedComment #5
catchAlso good to have index on {file_managed}.vid
Comment #6
David_Rothstein CreditAttribution: David_Rothstein at Tag1 Consulting commentedThis shouldn't be there since it's adding an index to file_managed_revisions rather than file_managed (and "vid" is already the primary key there).
Removed in the attached. Also combined the two patches from above into one.
Comment #7
Kenneth Lancaster CreditAttribution: Kenneth Lancaster as a volunteer commentedI will try to get a build up this weekend and test this out. Thank you.
Comment #8
Kenneth Lancaster CreditAttribution: Kenneth Lancaster as a volunteer commented