永发信息网

MySQL一个索引最多有多少个列

答案:2  悬赏:10  手机版
解决时间 2021-03-19 13:32
  • 提问者网友:山高云阔
  • 2021-03-19 09:09
MySQL一个索引最多有多少个列
最佳答案
  • 五星知识达人网友:西风乍起
  • 2021-03-19 09:26
MySQL一个索引最多有多少个列?
最多16列。

create table test (
f1 int,
f2 int,
f3 int,
f4 int,
f5 int,
f6 int,
f7 int,
f8 int,
f9 int,
f10 int,
f11 int,
f12 int,
f13 int,
f14 int,
f15 int,
f16 int,
f17 int
);

create index idx_test_16 on test (f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16);
create index idx_test_17 on test (f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17);

运行结果如下:

mysql> create table test (
-> f1 int,
-> f2 int,
-> f3 int,
-> f4 int,
-> f5 int,
-> f6 int,
-> f7 int,
-> f8 int,
-> f9 int,
-> f10 int,
-> f11 int,
-> f12 int,
-> f13 int,
-> f14 int,
-> f15 int,
-> f16 int,
-> f17 int
-> );
Query OK, 0 rows affected (0.06 sec)

mysql>
mysql> create index idx_test_16 on test (f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16);
Query OK, 0 rows affected (0.02 sec)
Records: 0 Duplicates: 0 Warnings: 0

mysql> create index idx_test_17 on test (f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17);
ERROR 1070 (42000): Too many key parts specified; max 16 parts allowed
mysql>
全部回答
  • 1楼网友:忘川信使
  • 2021-03-19 10:26
三个索引并不算多,索引的方式本来就有些偏向于空间换时间的方式; 然而索引的字段不能太大,否则除了占空间之外,在动态变更索引、查询上开销也会比较低效。 一般考虑使用基础类型(int/long/bit) 此类作为索引,需要规避大文本字段作为索引的做法!
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯