MySQL Forums
Forum List  »  Newbie

Re: how to solve this complex query
Posted by: Rick James
Date: January 19, 2009 12:28AM

"FROM ( SELECT ... )" is a nifty tool. But it can have a serious flaw... There are no indexes on that tmp table. Suggest you try the following...

1. Run each inner SELECT by itself to see how long it takes and how many rows it returns.

2. Decide if the tmp table it generates would work better if it had an index.

3. Try
CREATE TEMPORARY TABLE t1
   SELECT ...
ALTER TABLE t1
   ADD INDEX ...
and then use t1 in your big query, instead of the FROM(SELECT...).

4. If you still have issues, report back. Please include SHOW CREATE TABLE, SHOW TABLE STATUS, and EXPLAIN. Remove the FORCE INDEX() when doing the EXPLAIN. Also bracket things with [ code ] and [ / code ] for legibility.

Options: ReplyQuote


Subject
Written By
Posted
January 18, 2009 11:28PM
Re: how to solve this complex query
January 19, 2009 12:28AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.