这是关于 MySQL 5.5
我有这张桌子:
CREATE TABLE IF NOT EXISTS isup_trace_test (
id int(11) NOT NULL AUTO_INCREMENT,
datetime datetime DEFAULT NULL,
microseconds int(11) DEFAULT NULL,
opc int(11) DEFAULT NULL,
dpc int(11) DEFAULT NULL,
slc int(11) NOT NULL,
operation varchar(45) DEFAULT NULL,
release_text varchar(45) DEFAULT NULL,
release_code int(11) DEFAULT NULL,
calling varchar(45) DEFAULT NULL,
nrn varchar(10) DEFAULT NULL,
called varchar(45) DEFAULT NULL,
cic int(11) DEFAULT NULL,
message text,
filename varchar(100) NOT NULL,
PRIMARY KEY (id,datetime),
UNIQUE KEY opc (opc,dpc,cic,operation,datetime,microseconds),
KEY indice (datetime,microseconds,operation,cic,calling,called),
KEY cic_datetime (cic,datetime,microseconds),
KEY calling (calling),
KEY called (called),
KEY both_a_and_b (datetime,calling),
KEY by_release_text (release_text),
KEY by_release_code (release_code),
KEY operation (datetime,operation),
KEY per_opc (datetime,opc,dpc,operation),
KEY for_search (cic,operation,datetime),
KEY for_search_2 (datetime,calling,operation),
KEY for_search_3 (datetime,called,operation),
KEY search_1 (opc,dpc,cic,operation,datetime),
KEY por_fecha (datetime),
KEY tata (datetime,opc,dpc),
KEY datetime_calling_called_operation (datetime,calling,called,operation),
KEY filename (filename)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1
PARTITION BY LIST( HOUR(datetime) )(
PARTITION p00 VALUES IN (0) ,
PARTITION p01 VALUES IN (1) DATA DIRECTORY='/mnt/disk2' INDEX DIRECTORY='/mnt/disk2',
PARTITION p02 VALUES IN (2) DATA DIRECTORY='/mnt/disk3' INDEX DIRECTORY='/mnt/disk3',
PARTITION p03 VALUES IN (3) DATA DIRECTORY='/mnt/disk4' INDEX DIRECTORY='/mnt/disk4',
PARTITION p04 VALUES IN (4) DATA DIRECTORY='/mnt/disk5' INDEX DIRECTORY='/mnt/disk5',
PARTITION p05 VALUES IN (5) DATA DIRECTORY='/mnt/disk6' INDEX DIRECTORY='/mnt/disk6',
PARTITION p06 VALUES IN (6) ,
PARTITION p07 VALUES IN (7) DATA DIRECTORY='/mnt/disk2' INDEX DIRECTORY='/mnt/disk2',
PARTITION p08 VALUES IN (8) DATA DIRECTORY='/mnt/disk3' INDEX DIRECTORY='/mnt/disk3',
PARTITION p09 VALUES IN (9) DATA DIRECTORY='/mnt/disk4' INDEX DIRECTORY='/mnt/disk4',
PARTITION p10 VALUES IN (10) DATA DIRECTORY='/mnt/disk5' INDEX DIRECTORY='/mnt/disk5',
PARTITION p11 VALUES IN (11) DATA DIRECTORY='/mnt/disk6' INDEX DIRECTORY='/mnt/disk6',
PARTITION p12 VALUES IN (12) ,
PARTITION p13 VALUES IN (13) DATA DIRECTORY='/mnt/disk2' INDEX DIRECTORY='/mnt/disk2',
PARTITION p14 VALUES IN (14) DATA DIRECTORY='/mnt/disk3' INDEX DIRECTORY='/mnt/disk3',
PARTITION p15 VALUES IN (15) DATA DIRECTORY='/mnt/disk4' INDEX DIRECTORY='/mnt/disk4',
PARTITION p16 VALUES IN (16) DATA DIRECTORY='/mnt/disk5' INDEX DIRECTORY='/mnt/disk5',
PARTITION p17 VALUES IN (17) DATA DIRECTORY='/mnt/disk6' INDEX DIRECTORY='/mnt/disk6',
PARTITION p18 VALUES IN (18) ,
PARTITION p19 VALUES IN (19) DATA DIRECTORY='/mnt/disk2' INDEX DIRECTORY='/mnt/disk2',
PARTITION p20 VALUES IN (20) DATA DIRECTORY='/mnt/disk3' INDEX DIRECTORY='/mnt/disk3',
PARTITION p21 VALUES IN (21) DATA DIRECTORY='/mnt/disk4' INDEX DIRECTORY='/mnt/disk4',
PARTITION p22 VALUES IN (22) DATA DIRECTORY='/mnt/disk5' INDEX DIRECTORY='/mnt/disk5',
PARTITION p23 VALUES IN (23) DATA DIRECTORY='/mnt/disk6' INDEX DIRECTORY='/mnt/disk6'
)
现在选择有分区的想法是选择只搜索相关的分区,我希望这样:
EXPLAIN PARTITIONS SELECT *
FROM isup_trace_test PARTITION (p18)
use index (operation)
WHERE
hour(datetime) = "18" and
DATETIME >= '2013-05-23 18:07:59' AND DATETIME <= '2013-05-23 18:37:59' AND
operation = 'Release (12)'
返回类似的东西:
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE isup_trace_test p19 range operation operation 56 NULL 24 Using where
但实际上它返回:
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE isup_trace_test p00,p01,p02,p03,p04,p05,p06,p07,p08,p09,p10,p11,p1... range operation operation 56 NULL 24 Using where
这意味着它将搜索所有分区......但它应该只搜索分区“p19”......
我究竟做错了什么??
谢谢!
大卫