2012-08-16 49 views
0

我用hash(to_days(...))創建了一個MySQL分區表。mysql分區修剪不起作用

CREATE TABLE `requestlog` (
    `remotehost` varchar(40) DEFAULT NULL, 
    `user` varchar(255) DEFAULT NULL, 
    `request_time_str` varchar(40) DEFAULT NULL, 
    `request_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', 
    `request_line` varchar(255) DEFAULT NULL, 
    `status` int(11) DEFAULT NULL, 
    `bytes` int(11) DEFAULT NULL, 
    `referer` text, 
    `useragent` text, 
    `host` text, 
    `instance` text, 
    `ms` int(11) DEFAULT NULL, 
    `cpu_ms` int(11) DEFAULT NULL, 
    `api_cpu_ms` int(11) DEFAULT NULL, 
    `cpm_usd` float DEFAULT NULL, 
    `queue_name` varchar(40) DEFAULT NULL, 
    `task_name` varchar(40) DEFAULT NULL, 
    `loading_request` tinyint(1) DEFAULT NULL, 
    `pending_ms` int(11) DEFAULT NULL, 
    `exit_code` int(11) DEFAULT NULL, 
    `throttle_code` int(11) DEFAULT NULL, 
    `method` varchar(40) DEFAULT NULL, 
    `path` varchar(255) DEFAULT NULL, 
    `querystring` text, 
    `protocol` varchar(40) DEFAULT NULL, 
    `applog` text, 
    `applog0` text, 
    `applog1` text, 
    `applog2` text, 
    `applog3` text, 
    `applog4` text, 
    `id` int(11) NOT NULL AUTO_INCREMENT, 
    `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMES 
TAMP, 
    PRIMARY KEY (`request_time`,`id`), 
    UNIQUE KEY `path` (`path`,`request_time`,`remotehost`) 
) ENGINE=MyISAM DEFAULT CHARSET=utf8 
/*!50100 PARTITION BY HASH (to_days(request_time)) 
PARTITIONS 1000 */ 

但是,當我執行以下查詢。在explain partitions結果顯示分區修剪不工作,因爲它會掃描所有分區都屬於這個表...

explain partitions select count(*) from requestlog where to_days(request_time) = '2012-08-01'; 

我想這篇文章中的樣品。說明分區仍然顯示它掃描所有分區。 how to partition a table by datetime column?

如何讓分區修剪工作?任何提示?

回答

1

試試這個沒有to_days

explain partitions select count(*) from requestlog where request_time = '2012-08-01'; 

編輯:

explain partitions 
     select count(*) 
     from requestlog 
     where request_time BETWEEN '2012-08-01 00:00:00' AND '2012-08-01 23:59:59'; 
+0

分區修剪工作在這種情況下,但查詢本身只返回結果,其REQUEST_TIME =「2012-08-01 00: 00:00' – lucemia 2012-08-16 09:12:53

+0

因爲你在索引'request_time'上有效。也''To_DAYS'函數返回你正在比較的日期值的整數值。 – Omesh 2012-08-16 09:17:14

+0

分區修剪在此查詢中起作用,但結果不正確。例如,此查詢忽略request_time ='2012-08-01 00:00:01' – lucemia 2012-08-16 09:25:33