我已经用date对我的一个数据表(devicelogs)进行了按月范围分区的重构( LogDate
)现场。下面是我的表的最小版本。
UUID | LogDate | DeviceId | Counter
------|----------------------|-----------|---------
xxxx | 2018-08-21 15:00:00 | 23 | 45
xxxx | 2018-08-21 15:00:00 | 24 | 23
xxxx | 2018-08-21 15:00:00 | 25 | 120
xxxx | 2018-08-21 16:00:00 | 23 | 55
xxxx | 2018-08-21 16:00:00 | 24 | 30
复合主键(uuid,logdate)
我创建了如下分区。。
ALTER TABLE DeviceLogs PARTITION BY RANGE (TO_DAYS(LogDate)) (
PARTITION plt201807 VALUES LESS THAN (TO_DAYS('2018-07-01')),
PARTITION plt201808 VALUES LESS THAN (TO_DAYS('2018-08-01')),
PARTITION plt201809 VALUES LESS THAN (TO_DAYS('2018-09-01')),
PARTITION plt201810 VALUES LESS THAN (TO_DAYS('2018-10-01'))
)
我对上表有几组查询,我将从中生成数据库报告和图表。我可以举一些我正在使用的查询模式的例子。
// Hourly (Last 25 hours)
SELECT DeviceId, sum(Counter) FROM DeviceLogs
WHERE LogDate BETWEEN '2018-08-21 15:00:00' AND '2018-08-20 14:00:00'
GROUP BY HOUR(LogDate)
.
// Daily (Last 30 days)
SELECT DeviceId, sum(Counter) FROM DeviceLogs
WHERE LogDate BETWEEN '2018-08-21 15:00:00' AND '2018-07-21 15:00:00'
GROUP BY DAY(LogDate)
.
// Monthly (Last 12 months)
SELECT DeviceId, sum(Counter) FROM DeviceLogs
WHERE LogDate BETWEEN '2018-08-21 15:00:00' AND '2017-08-21 15:00:00'
GROUP BY MONTH(LogDate)
我的问题是,首先,通过为上述类型的查询创建每月一次的分区,我会得到任何真正的好处吗?第二,我是否需要在上述查询中包含分区名称以获得分区的实际好处?
1条答案
按热度按时间nx7onnlm1#
您不必指定分区名称。优化器应该查看条件并为您修剪适当的分区。