MySQL Forums
Forum List  »  Partitioning

Re: Partition on day of year
Posted by: Rick James
Date: March 04, 2011 08:23PM

Oops, it was Shantanu Oak's post that mentioned InnoDB. Most things apply to either Engine. One change: Add id thus:
KEY `search` (`customer_id`,`job_date_time`,`printer_name`,`username`, id)
That will make the subquery approach efficient for MyISAM.

Even if customer_id is always 1, it should be included in the compound indexes where mentioned. Searching on just customer_id would ignore the indexes and do a table scan.

SELECT * FROM test_jobs WHERE customer_id = 1 AND job_date_time BETWEEN '2011-01-02 00:00:00' AND '2011-01-02 23:59:59' ORDER BY job_date_time LIMIT 0,25;
can stop after only 25 rows. Adding to the WHERE clause says it has to scan all the rows with (customer_id = 1 AND job_date_time...) and check the other things before finding the desired 25.

Try adding id to the index (above), then see how fast this runs:
SELECT id (not '*') ...
I expect it to be somewhere between 1 and 30 seconds.

That's the subquery. Then, when it is put in the outer query, it will need to SELECT * to get the 25 (only 25) rows. This will take another 1 second. Total time might be 10-20 seconds. Not great, but better than 30. And PARTITIONing is irrelevant (in this case).

Options: ReplyQuote


Subject
Views
Written By
Posted
8456
February 28, 2011 07:18PM
2868
February 28, 2011 08:43PM
4071
March 01, 2011 12:53AM
2545
March 01, 2011 10:33PM
2428
March 02, 2011 10:00AM
2030
March 02, 2011 11:16AM
2205
March 03, 2011 09:47PM
2640
March 04, 2011 08:58AM
2087
March 04, 2011 10:45AM
Re: Partition on day of year
2621
March 04, 2011 08:23PM
1808
March 02, 2011 02:58AM


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.