内存表的主键必须是 HASH,为什么?



我想使用一个内存表作为一组队列。

因此,将有一个包含int列a和b的内存表。
查询如下:
选择b FROM表,其中a=?订单按b下降限制1000

我试过这个:

create table `test_table` (
    `a` int(11) not null,
    `b` int(11) not null,
    primary key (`a`,`b`) using btree
) engine=memory

但是主密钥仍然是HASH:

show index from `test_table`
Table       Non_unique  Key_name  Seq_in_index  Column_name  Collation  Cardinality  Sub_part  Packed  Null    Index_type  Comment
----------  ----------  --------  ------------  -----------  ---------  -----------  --------  ------  ------  ----------  -------
test_table           0  PRIMARY              1  a            (NULL)          (NULL)    (NULL)  (NULL)          HASH
test_table           0  PRIMARY              2  b            (NULL)               0    (NULL)  (NULL)          HASH
  1. 这是否意味着,我需要为此类查询创建另一个密钥(a)?

  2. 为什么主键不能是BTREE索引?如果我将主键更改为普通键,会有什么不同?

您可以使用alter查询来修改索引类型。

ALTER TABLE test_table DROP PRIMARY KEY, ADD PRIMARY KEY USING BTREE (a,b);

OR使用以下创建查询,

create table test_table (a int(11) not null,b int(11) not null,primary key USING BTREE(a,b)) engine=memory

有关内存引擎的更多详细信息,请访问下面的链接。http://dev.mysql.com/doc/refman/5.0/en/memory-storage-engine.html

最新更新