【发布时间】:2012-01-14 02:27:46
【问题描述】:
我使用分区插件 ACTIVE 运行 MySQL 5.1.47。
我创建了下表:
CREATE TABLE IF NOT EXISTS `prova` (
`NE` varchar(8) NOT NULL,
`ASSERT` longtext NOT NULL
) ENGINE=MyISAM
PARTITION BY KEY(NE)
PARTITIONS 4;
然后我插入 4 行:
INSERT INTO prova values ('AAA','this assert is from AAA');
INSERT INTO prova values ('BBB','this assert is from BBB');
INSERT INTO prova values ('CCC','this assert is from CCC');
INSERT INTO prova values ('DDD','this assert is from DDD');
我希望在每个分区中找到 1 条记录,但是:
mysql> explain partitions select * from prova where NE='AAA';
+----+-------------+-------+------------+--------+---------------+------+---------+------+------+-------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------------+--------+---------------+------+---------+------+------+-------+
| 1 | SIMPLE | prova | p2 | system | NULL | NULL | NULL | NULL | 1 | |
+----+-------------+-------+------------+--------+---------------+------+---------+------+------+-------+
1 row in set (0.00 sec)
mysql> explain partitions select * from prova where NE='BBB';
+---+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | prova | p1 | ALL | NULL | NULL | NULL | NULL | 4 | Using where |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)
mysql> explain partitions select * from prova where NE='CCC';
+----+-------------+-------+------------+--------+---------------+------+---------+------+------+-------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------------+--------+---------------+------+---------+------+------+-------+
| 1 | SIMPLE | prova | p0 | system | NULL | NULL | NULL | NULL | 1 | |
+----+-------------+-------+------------+--------+---------------+------+---------+------+------+-------+
1 row in set (0.00 sec)
mysql> explain partitions select * from prova where NE='DDD';
+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+
| 1 | SIMPLE | prova | p1 | ALL | NULL | NULL | NULL | NULL | 4 | Using where |
+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+
1 row in set (0.00 sec)
所以,我的问题是: 我究竟做错了什么?为什么 4 个插入没有分成 4 个分区? 为什么 BBB 和 DDD 在同一个分区?
非常感谢您的帮助! 埃文)
【问题讨论】:
-
我刚刚发现如果我使用 A、B、C、D 而不是 AAA、BBB、CCC、DDD 分区工作正常。您能否建议如何根据字符串而不是单个字符对表进行分区?谢谢!!!
标签: mysql partitioning