I have a huge table that stores many tracked events, such as a user click.
The table is already in the 10's of millions, and its growing larger everyday. The queries are starting to get slower when i try to fetch events from a large timeframe, and after reading quite a bit on the subject i understand that partitioning the table may boost the performance.
What i want to do is partition the table on a per month basis.
I have only found guides that show how to partition manually each month, is there a way to just tell MySQL to partition by month and it will do that automatically?
If not, what is the command to do it manually considering my partitioned by column is a datetime?
As explained by the manual: http://dev.mysql.com/doc/refman/5.6/en/partitioning-overview.html
This is easily possible by hash partitioning of the month output.
Do note that this only partitions by month and not by year, also there are only 6 partitions (so 6 monhts) in this example.
And for partitioning an existing table (manual: https://dev.mysql.com/doc/refman/5.7/en/alter-table-partition-operations.html):
Querying can be done both from the entire table:
Or from specific partitions:
HASHing
by month with 6 partitions means that two months a year will land in the same partition. What good is that?Don't bother partitioning, index the table.
Assuming these are the only two queries you use:
then start the
PRIMARY KEY
withthe_date
.The first query simply reads the entire table; no change between partitioned and not.
The second query, assuming you want a single month, not all the months that map into the same partition, would need to be
If you have other queries, let's see them.
(I have not found any performance justification for ever using
PARTITION BY HASH
.)Use TokuDb which has an access time independent of the table size.