1

我的分区表是这样描述的:

 CREATE TABLE `event_data` (id int(11) NOT NULL AUTO_INCREMENT,
  ...
  Timestamp int(10) unsigned NOT NULL,
  ...
  ...
  CurrentDate date NOT NULL,
  KEY `id_index` (`id`),
  KEY `ix_filter` (`Action`,`Location`),
  KEY `ix_time` (`Timestamp`)
)ENGINE=MyISAM AUTO_INCREMENT=1176568 DEFAULT CHARSET=latin1
/*!50500 PARTITION BY RANGE  COLUMNS(CurrentDate)
(PARTITION p20130106 VALUES LESS THAN ('2013-01-06') ENGINE = MyISAM,
 PARTITION p20130113 VALUES LESS THAN ('2013-01-13') ENGINE = MyISAM,
 PARTITION p20130120 VALUES LESS THAN ('2013-01-20') ENGINE = MyISAM) */ 

我正在尝试执行以下查询:

explain partitions select min(Timestamp) from event_data where CurrentDate < "2013-01-06";

+----+-------------+------------+------------+------+---------------+------+---------+------+--------+-------------+
| id | select_type | table      | partitions | type | possible_keys | key  | key_len | ref  | rows   | Extra       |
+----+-------------+------------+------------+------+---------------+------+---------+------+--------+-------------+
|  1 | SIMPLE      | event_data | p20130106  | ALL  | NULL          | NULL | NULL    | NULL | 512983 | Using where |
+----+-------------+------------+------------+------+---------------+------+---------+------+--------+-------------+

explain partitions select min(Timestamp) from event_data;

+----+-------------+-------+------------+------+---------------+------+---------+------+------+------------------------------+
| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows | Extra                        |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+------------------------------+
|  1 | SIMPLE      | NULL  | NULL       | NULL | NULL          | NULL | NULL    | NULL | NULL | Select tables optimized away |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+------------------------------+

似乎在不指定分区的情况下查询速度更快(我知道最小值总是在第一个分区中)

select min(Timestamp) from event_data where CurrentDate < "2013-01-06";

+----------------+
| min(Timestamp) |
+----------------+
|     1321747200 |
+----------------+
1 row in set (0.16 sec)

select min(Timestamp) from event_data ;

+----------------+
| min(Timestamp) |
+----------------+
|     1321747200 |
+----------------+
1 row in set (0.00 sec)

指定分区的查询是否应该更快,因为它只需要在单个分区中查看最小值,而不是在所有分区中搜索的最小值?

指示分区时似乎没有使用时间戳索引,但是为什么呢???我有每个分区文件的 MYI 文件,我确信索引是为每个这样的文件建立的......

我也知道索引在没有聚合函数的情况下用于不同的选择查询(基准测试)。

更新

我发现了这个错误报告http://bugs.mysql.com/bug.php?id=66187,这与我的问题有关。

4

1 回答 1

0

我发现了一个严重的错误报告http://bugs.mysql.com/bug.php?id=66187 描述了同样的问题。我已对此错误添加评论

于 2013-02-02T09:50:23.633 回答