我有一個表的字段,它是ACTION_TIME主鍵和類型爲datetimeMySQL分區不起作用
我試圖打破它的分區
ALTER TABLE foo PARTITION BY RANGE (MONTH(action_time))
(
PARTITION p01 VALUES LESS THAN (02) ,
PARTITION p02 VALUES LESS THAN (03) ,
PARTITION p03 VALUES LESS THAN (04) ,
PARTITION p04 VALUES LESS THAN (05) ,
PARTITION p05 VALUES LESS THAN (06) ,
PARTITION p06 VALUES LESS THAN (07) ,
PARTITION p07 VALUES LESS THAN (08) ,
PARTITION p08 VALUES LESS THAN (09) ,
PARTITION p09 VALUES LESS THAN (10) ,
PARTITION p10 VALUES LESS THAN (11) ,
PARTITION p11 VALUES LESS THAN (12) ,
PARTITION p12 VALUES LESS THAN (13) ,
PARTITION pmaxval VALUES LESS THAN MAXVALUE
);
在phpMyAdmin我看到行 分區,但當我執行
explain partitions select * from foo where action_time between '2017-01-01 20:34:08' and '2017-01-21 20:34:08';
或
explain partitions select * from foo where action_time > '2017-01-01 20:34:08' && action_time < '2017-01-21 20:34:08'
它擊中所有分區(P01,P02,P03,P04,P05,P06,P07,P08,P09,P10,P11,P12,pmaxval)
什麼,我做錯了什麼?
我也嘗試這種方式的結果相同
ALTER TABLE foo
PARTITION BY RANGE( YEAR(action_time))
SUBPARTITION BY HASH(MONTH(action_time))
SUBPARTITIONS 12 (
PARTITION p2015 VALUES LESS THAN (2016),
PARTITION p2016 VALUES LESS THAN (2017),
PARTITION p2017 VALUES LESS THAN (2018),
PARTITION p2018 VALUES LESS THAN (2019),
PARTITION p2019 VALUES LESS THAN (2020),
PARTITION p2020 VALUES LESS THAN (2021),
PARTITION p2021 VALUES LESS THAN (2022),
PARTITION p2022 VALUES LESS THAN (2023),
PARTITION p2023 VALUES LESS THAN (2024),
PARTITION p2024 VALUES LESS THAN (2025),
PARTITION p2025 VALUES LESS THAN (2026),
PARTITION p2026 VALUES LESS THAN (2027),
PARTITION p2027 VALUES LESS THAN (2028),
PARTITION p2028 VALUES LESS THAN (2029),
PARTITION p2029 VALUES LESS THAN (2030),
PARTITION pmax VALUES LESS THAN MAXVALUE
);
我需要按年份和月份打破錶提高選擇的時候,當我的日期之間選擇它sholdn't在全表搜索它應該在相關的分區中進行搜索。我怎樣才能做到這一點?
還有一些更多的規則,如type ='...'和m_id ='...' 這個表很大,它充滿了大量的日常記錄 我認爲分區加速選擇 – David
而且,與您的新的編輯,你已經找到了一個爲什麼我說'SUBPARTITION'沒用的例子。 –
我在回答中添加了「爲什麼分區不會加速簡單查詢」。 –