Skip to content

Instantly share code, notes, and snippets.

Created May 25, 2013 15:16
Show Gist options
  • Save anonymous/47de33ef46e3c68fe856 to your computer and use it in GitHub Desktop.
Save anonymous/47de33ef46e3c68fe856 to your computer and use it in GitHub Desktop.
mysql> EXPLAIN (SELECT Text FROM Strip_Text LEFT JOIN Strip_Panels ON Strip_Text.Parent_Table = "Panels" AND Strip_Text.Parent_ID = Strip_Panels.ID WHERE Strip_Panels.Strip_ID = 5) UNION ALL (SELECT DISTINCT Text FROM Strip_Text LEFT JOIN Strip_Panels ON Strip_Text.Parent_Table = "Scenes" AND Strip_Text.Parent_ID = Strip_Panels.Scene_ID WHERE Strip_Panels.Strip_ID = 5);
+----+--------------+--------------+------+------------------------+-----------+---------+------------------------------------------+------+------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+--------------+--------------+------+------------------------+-----------+---------+------------------------------------------+------+------------------------------+
| 1 | PRIMARY | Strip_Panels | ref | PRIMARY,Strip_ID | Strip_ID | 8 | const | 4 | Using where |
| 1 | PRIMARY | Strip_Text | ref | Parent_Table,Parent_ID | Parent_ID | 8 | Project_Doonesbury.Strip_Panels.ID | 2 | Using where |
| 2 | UNION | Strip_Panels | ref | Strip_ID,Scene_ID | Strip_ID | 8 | const | 4 | Using where; Using temporary |
| 2 | UNION | Strip_Text | ref | Parent_Table,Parent_ID | Parent_ID | 8 | Project_Doonesbury.Strip_Panels.Scene_ID | 2 | Using where |
| NULL | UNION RESULT | <union1,2> | ALL | NULL | NULL | NULL | NULL | NULL | |
+----+--------------+--------------+------+------------------------+-----------+---------+------------------------------------------+------+------------------------------+
5 rows in set (0.08 sec)
mysql> EXPLAIN SELECT DISTINCT Text FROM Strip_Text INNER JOIN Strip_Panels ON
(Strip_Text.Parent_Table = "Panels" AND Strip_Text.Parent_ID = Strip_Panels.ID)
OR (Strip_Text.Parent_Table = "Scenes" AND Strip_Text.Parent_ID = Strip_Panels.Scene_ID)
WHERE Strip_Panels.Strip_ID = 5;
+----+-------------+--------------+------+---------------------------+----------+---------+-------+-------+------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+--------------+------+---------------------------+----------+---------+-------+-------+------------------------------------------------+
| 1 | SIMPLE | Strip_Panels | ref | PRIMARY,Strip_ID,Scene_ID | Strip_ID | 8 | const | 4 | Using temporary |
| 1 | SIMPLE | Strip_Text | ALL | Parent_ID | NULL | NULL | NULL | 10098 | Range checked for each record (index map: 0x4) |
+----+-------------+--------------+------+---------------------------+----------+---------+-------+-------+------------------------------------------------+
2 rows in set (1.53 sec)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment