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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

catch’s picture

Status: Active » Needs review
FileSize
917 bytes
catch’s picture

FileSize
731 bytes

Wrong patch.

David_Rothstein’s picture

catch’s picture

FileSize
1.47 KB

Also good to have index on {file_managed}.vid

David_Rothstein’s picture

Title: Add index on uri » Add index on {file_managed_revisions}.uri and {file_managed}.vid
FileSize
1.48 KB
   $schema['file_managed_revisions']['indexes'] = array(
     'fid' => array('fid'),
+    'vid' => array('vid'),

This 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.

Kenneth Lancaster’s picture

I will try to get a build up this weekend and test this out. Thank you.

Kenneth Lancaster’s picture

Assigned: Unassigned » Kenneth Lancaster