I am trying to run a "simple" report and it is taking about 2 1/2 minutes to run. Here is the query:
The top half returns about 42,000 rows in about 2 seconds. I am trying to join it to another part that, on its own, returns about 10,000 rows in less than 1 second. Yet when I make the join, it takes 2 1/2 minutes. I'm assuming this is because they are both derived tables and therefore they are not indexed? Is there any way around this?Code:SELECT idx.* FROM (SELECT idxrecentacct.socsec FROM idxrecentacct INNER JOIN blfcustunq USING (socsec) INNER JOIN blfacct USING (class, account) WHERE idxrecentacct.company='BLF' UNION SELECT idxrecentacct.socsec FROM idxrecentacct INNER JOIN aaacustunq USING (socsec) INNER JOIN aaaacct USING (class, account) WHERE idxrecentacct.company='AAA' UNION SELECT idxrecentacct.socsec FROM idxrecentacct INNER JOIN crycustunq USING (socsec) INNER JOIN cryacct USING (class, account) WHERE idxrecentacct.company='CRY') idx INNER JOIN (SELECT * FROM aaaviewerblfmailmarketing UNION SELECT * FROM aaaviewercrymailmarketing UNION SELECT * FROM aaaviewerallmailmarketing) aaaviewer ON (idx.socsec = aaaviewer.socsec)
I ran an EXPLAIN EXTENDED and this is what I got. Not really sure how to read it:
Code:+----+--------------+---------------------------+--------+-------------------+-------------------+---------+---------------------------------------------------------------------+-------+--------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+--------------+---------------------------+--------+-------------------+-------------------+---------+---------------------------------------------------------------------+-------+--------------------------------+ | 1 | PRIMARY | <derived5> | ALL | NULL | NULL | NULL | NULL | 9771 | | | 1 | PRIMARY | <derived2> | ALL | NULL | NULL | NULL | NULL | 42088 | Using where | | 5 | DERIVED | aaaviewerblfmailmarketing | ALL | NULL | NULL | NULL | NULL | 9768 | | | 6 | UNION | aaaviewercrymailmarketing | ALL | NULL | NULL | NULL | NULL | 3 | | | 7 | UNION | NULL | NULL | NULL | NULL | NULL | NULL | NULL | no matching row in const table | | NULL | UNION RESULT | <union5,6,7> | ALL | NULL | NULL | NULL | NULL | NULL | | | 2 | DERIVED | idxrecentacct | ALL | classaccountindex | NULL | NULL | NULL | 42088 | Using where | | 2 | DERIVED | blfcustunq | ref | socsecindex | socsecindex | 12 | web_dev_test.idxrecentacct.socsec | 1 | Using where; Using index | | 2 | DERIVED | blfacct | eq_ref | PRIMARY | PRIMARY | 5 | web_dev_test.idxrecentacct.class,web_dev_test.idxrecentacct.account | 1 | Using index | | 3 | UNION | idxrecentacct | ALL | classaccountindex | NULL | NULL | NULL | 42088 | Using where | | 3 | UNION | aaacustunq | ref | socsecindex | socsecindex | 12 | web_dev_test.idxrecentacct.socsec | 1 | Using where; Using index | | 3 | UNION | aaaacct | eq_ref | PRIMARY | PRIMARY | 5 | web_dev_test.idxrecentacct.class,web_dev_test.idxrecentacct.account | 1 | Using index | | 4 | UNION | cryacct | index | PRIMARY | PRIMARY | 5 | NULL | 4 | Using index | | 4 | UNION | idxrecentacct | eq_ref | classaccountindex | classaccountindex | 5 | web_dev_test.cryacct.class,web_dev_test.cryacct.account | 1 | Using where | | 4 | UNION | crycustunq | ref | socsecindex | socsecindex | 12 | web_dev_test.idxrecentacct.socsec | 1 | Using where; Using index | | NULL | UNION RESULT | <union2,3,4> | ALL | NULL | NULL | NULL | NULL | NULL | | +----+--------------+---------------------------+--------+-------------------+-------------------+---------+---------------------------------------------------------------------+-------+--------------------------------+


Reply With Quote
Bookmarks