Skip to content

Instantly share code, notes, and snippets.

@angrytoast
Last active December 10, 2016 04:31
Show Gist options
  • Select an option

  • Save angrytoast/0c3e61d39652d47a90d3de8adfd2de01 to your computer and use it in GitHub Desktop.

Select an option

Save angrytoast/0c3e61d39652d47a90d3de8adfd2de01 to your computer and use it in GitHub Desktop.
Results

Query

EXPLAIN SELECT DISTINCT field_revision_field_sections.entity_type AS entity_type, field_revision_field_sections.entity_id AS entity_id, field_revision_field_sections.revision_id AS revision_id, field_revision_field_sections.bundle AS bundle FROM field_revision_field_sections field_revision_field_sections WHERE  (field_revision_field_sections.field_sections_revision_id = '251315') AND (field_revision_field_sections.deleted = '0') AND(( ( EXISTS  (SELECT na.nid AS nid FROM node_access na WHERE (( (na.gid = '0') AND (na.realm = 'all') )OR( (na.gid = '1') AND (na.realm = 'taxonomy_access_role') ))AND (na.grant_view >= '1') AND (field_revision_field_sections.entity_id = na.nid) )) AND (field_revision_field_sections.entity_type = 'node') )OR (field_revision_field_sections.entity_type <> 'node') );

Before

+------+--------------+-------------------------------+------+-----------------------------+---------+---------+-------+--------+-----------------------------------------------------+
| id   | select_type  | table                         | type | possible_keys               | key     | key_len | ref   | rows   | Extra                                               |
+------+--------------+-------------------------------+------+-----------------------------+---------+---------+-------+--------+-----------------------------------------------------+
|    1 | PRIMARY      | field_revision_field_sections | ref  | PRIMARY,entity_type,deleted | deleted | 1       | const |  54196 | Using index condition; Using where; Using temporary |
|    2 | MATERIALIZED | na                            | ALL  | PRIMARY                     | NULL    | NULL    | NULL  | 190800 | Using where                                         |
+------+--------------+-------------------------------+------+-----------------------------+---------+---------+-------+--------+-----------------------------------------------------+

After

+------+--------------------+-------------------------------+----------------+--------------------------------------------------------+----------------------------+---------+-------+------+-----------------------------------------------------+
| id   | select_type        | table                         | type           | possible_keys                                          | key                        | key_len | ref   | rows | Extra                                               |
+------+--------------------+-------------------------------+----------------+--------------------------------------------------------+----------------------------+---------+-------+------+-----------------------------------------------------+
|    1 | PRIMARY            | field_revision_field_sections | ref            | PRIMARY,entity_type,deleted,field_sections_revision_id | field_sections_revision_id | 5       | const |    1 | Using index condition; Using where; Using temporary |
|    2 | DEPENDENT SUBQUERY | na                            | index_subquery | PRIMARY                                                | PRIMARY                    | 4       | func  |    2 | Using where                                         |
+------+--------------------+-------------------------------+----------------+--------------------------------------------------------+----------------------------+---------+-------+------+-----------------------------------------------------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment