V
V
vasdor2015-04-25 13:48:01
MySQL
vasdor, 2015-04-25 13:48:01

How to properly organize Mysql Partitioning by DAYOFMONTH?

Hello!
There is a table:

CREATE TABLE `logs` (
  `INSERT_DATE` datetime DEFAULT NULL,
  `DATA` text NOT NULL,
  KEY `INSERT_DATE` (`INSERT_DATE`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE (DAYOFMONTH(INSERT_DATE))
(PARTITION p0 VALUES LESS THAN (2) ENGINE = InnoDB,
 PARTITION p1 VALUES LESS THAN (3) ENGINE = InnoDB,
 ...
 PARTITION p30 VALUES LESS THAN (32) ENGINE = InnoDB) */

with partitions made by day of the month
Query
SELECT PARTITION_NAME, TABLE_ROWS FROM INFORMATION_SCHEMA.PARTITIONS WHERE  TABLE_NAME LIKE 'logs';

shows that the partitions contain the number of records corresponding to the real data. Those. if there are 17 entries on the 20th, then partition p21 also contains 17 rows. Everything seems to be fine here.
The problem is that the request
EXPLAIN PARTITIONS SELECT * FROM logs WHERE insert_date BETWEEN '2014-10-28' AND '2014-10-29';

shows in the "partitions" column all 31 created partitions, although it should only show for resp. days of the month
The questions are:
1) Why does Explain behave this way?
2) Is it possible that only the necessary partitions will be used in a real query?
Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2015-04-25
@melkij

Show like this:

EXPLAIN PARTITIONS SELECT * FROM logs WHERE DAYOFMONTH(insert_date) BETWEEN '2014-10-28' AND '2014-10-29';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question