I have a MySQL table say data_table
mysql> desc data_table;
+------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+------------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| prod_id | int(10) unsigned | NO | | NULL | |
| date | date | NO | | NULL | |
| cost | double | NO | | NULL | |
+------------+------------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
This table has around 700 million rows. I have created indexes on prod_id
and date
. I need to perform a query like this -
SELECT `id`, `prod_id`, WEEKOFYEAR(`date`) AS period, SUM(`cost`) AS cost_sum
FROM `data_table` GROUP BY `prod_id`, `period`;
My question is -
Will partitioning the table on months (~20 partitions) improve the performance of this query?