MySQL Forums
Forum List  »  Optimizer & Parser

Re: Query Optimisation of a slow query
Posted by: Rick James
Date: September 20, 2011 09:20PM

Use the DATETIME datatype instead of this:
`date_time` varchar(23) NOT NULL default '',

I suspect this is giving the wrong answer:
date_time < a.date_time + interval 1 second

The second of these is redundant and can be DROPped:
UNIQUE KEY `traffic_id_date_time`( `network_traffic_id` , `date_time` ),
KEY `network_traffic_id`( `network_traffic_id` ),

innodb_buffer_pool_size is 2G, I assume all your tables are InnoDB. If so, then caching is no the issue. With 20GB of RAM, the buffer pool could be made much larger (but this may not help the current issue).

* SHOW TABLE STATUS LIKE 'tbl'\G -- sizes

It's a "correlated subquery" (see a.network_traffic_id), so it cannot be turned into a temp table without some further thought.

date_time < a.date_time + interval 1 second
instead of
date_time <= a.date_time

With that change, there is hope for the 'group by trick':,428347 (Last or Max?),400775 (Assistance required for query with subquery),396680 (Slow Query),394154 (Require help to formulate a query.),389565 (query returns unwanted duplicates),387554 (aggreate data),373984 (select max date in Inner Join),291994 (create function help),290067 (Help with minimum/group by),284734 (max function),280124 (limiting rows returned),272271 (Subquery and JOIN's),266585 (How does group by algorithm works?),250033 (Listing threads by newest posts?),236805 (Complex Select with Min/Max Syntax)

Options: ReplyQuote

Written By
September 13, 2011 03:26AM
September 16, 2011 10:21PM
September 19, 2011 01:01AM
Re: Query Optimisation of a slow query
September 20, 2011 09:20PM
September 21, 2011 12:21AM
September 21, 2011 02:38AM
September 22, 2011 12:03AM
September 20, 2011 01:51AM

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.