MySQL Forums
Forum List  »  Partitioning

Re: Partitioning not working need primary key?
Posted by: Rick James
Date: November 02, 2012 12:37AM

It depends.

If you search for
WHERE DateTime >= ... AND DateTime < ...
and that range is exactly the range of a partition (or partitions), then the "partition pruning" will pick the partition(s) and scan them entirely. This will be optimal. That is, not extra index would help.

If you search from some narrow range, say, one day when you are partitioning by month, then an index could help. First partitioning will pick the desired partition, then it will search that partition just like a table. If there is a useful index, it will use it. (This includes your proposed new index.) If there is no useful index, it will search the entire month to find the day's worth of rows.

If you have an index (or the PK) with (outletID,receiptID,dateTime) and you say
WHERE outletID = 123 AND dateTime >=...
It will use that index starting with outletID

If you have an index (or the PK) with (outletID,receiptID,dateTime) and you say
WHERE receiptID = 987 AND dateTime >=...
It will ignore that index, and would use your proposed INDEX(dateTime) if it existed.

Etc., Etc.

I hope you are learning by example how INDEXes work. Question... Are these examples or useful or less useful than
http://mysql.rjweb.org/doc.php/index1
?

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Partitioning not working need primary key?
7239
November 02, 2012 12:37AM


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.