免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
Alibaba DBA Team » Blog Archive » MySQL MyIsam 存儲(chǔ)引擎索引長(zhǎng)度限制測(cè)試記錄
MySQL MyIsam 存儲(chǔ)引擎在創(chuàng)建索引的時(shí)候,索引鍵長(zhǎng)度是有一個(gè)較為嚴(yán)格的長(zhǎng)度限制的,所有索引鍵最大長(zhǎng)度總和不能超過1000,而且不是實(shí)際數(shù)據(jù)長(zhǎng)度的總和,而是索引鍵字段定義長(zhǎng)度的總和。下面做個(gè)簡(jiǎn)單的測(cè)試,記錄一下。

root@sky:~# mysql -u sky -p -h127.0.0.1
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 44
Server version: 5.0.51a-log MySQL Community Server (GPL)

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

sky@127.0.0.1 : (none) 05:23:08> use test;
Database changed
sky@127.0.0.1 : test 05:23:11>
sky@127.0.0.1 : test 05:23:12>

先創(chuàng)建一個(gè)MyIsam表,字符集選擇latin1,三個(gè)字段均設(shè)置為varchar 255,:
sky@127.0.0.1 : test 05:23:12> create table test_ind
-> (a varchar(255),
->  b varchar(255),
->  c varchar(255)
-> ) engine=myisam charset=latin1;
Query OK, 0 rows affected (0.01 sec)

創(chuàng)建效果:
sky@127.0.0.1 : test 05:23:32> show create table test_ind\G
*************************** 1. row ***************************
Table: test_ind
Create Table: CREATE TABLE `test_ind` (
`a` varchar(255) default NULL,
`b` varchar(255) default NULL,
`c` varchar(255) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1 row in set (0.00 sec)

三個(gè)字段聯(lián)合索引(長(zhǎng)度應(yīng)該在1000以內(nèi))

sky@127.0.0.1 : test 05:23:41> create index test_a_b_c_ind on test_ind(a,b,c);
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

我們看到,創(chuàng)建成功了。

下面我們做一次字符集轉(zhuǎn)換,將字符集轉(zhuǎn)換成utf8

sky@127.0.0.1 : test 05:25:54> alter table test_ind convert to charset utf8;
ERROR 1071 (42000): Specified key was too long; max key length is 1000 bytes
sky@127.0.0.1 : test 05:26:24>
sky@127.0.0.1 : test 05:28:03> show create table test_ind\G
*************************** 1. row ***************************
Table: test_ind
Create Table: CREATE TABLE `test_ind` (
`a` varchar(255) default NULL,
`b` varchar(255) default NULL,
`c` varchar(255) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
1 row in set (0.00 sec)

結(jié)果報(bào)錯(cuò)了,查看表實(shí)際情況也確實(shí)沒有成功,仍然是latin1的字符集。

我們現(xiàn)drop掉索引,再轉(zhuǎn)換字符集。

sky@127.0.0.1 : test 05:28:10> drop index test_a_b_c_ind on test_ind;
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

sky@127.0.0.1 : test 05:28:15> alter table test_ind convert to charset utf8;
Query OK, 0 rows affected (0.00 sec)
Records: 0  Duplicates: 0  Warnings: 0
sky@127.0.0.1 : test 05:28:20> show create table test_ind\G
*************************** 1. row ***************************
Table: test_ind
Create Table: CREATE TABLE `test_ind` (
`a` varchar(255) default NULL,
`b` varchar(255) default NULL,
`c` varchar(255) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
轉(zhuǎn)換很順利,成功了。

現(xiàn)在再創(chuàng)建索引看看效果怎樣:

sky@127.0.0.1 : test 05:28:36> create index test_a_b_c_ind on test_ind(a,b,c);
ERROR 1071 (42000): Specified key was too long; max key length is 1000 bytes

失敗,減少索引鍵字段
sky@127.0.0.1 : test 05:28:54> create index test_a_b_c_ind on test_ind(a,b);
ERROR 1071 (42000): Specified key was too long; max key length is 1000 bytes

還是失敗,繼續(xù)減少
sky@127.0.0.1 : test 05:29:00> create index test_a_b_c_ind on test_ind(a);
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

ok,總算成功了。

最后再看看其他存儲(chǔ)引擎有沒有這個(gè)限制呢?就看當(dāng)前用的最廣泛的存儲(chǔ)引擎之一Innodb吧:

sky@127.0.0.1 : test 05:29:03> drop index test_a_b_c_ind on test_ind;
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

sky@127.0.0.1 : test 05:29:54>
sky@127.0.0.1 : test 05:29:58>
sky@127.0.0.1 : test 05:30:11> alter table test_ind engine=innodb;
Query OK, 0 rows affected (0.01 sec)
Records: 0  Duplicates: 0  Warnings: 0
sky@127.0.0.1 : test 05:31:15> show create table test_ind\G
*************************** 1. row ***************************
Table: test_ind
Create Table: CREATE TABLE `test_ind` (
`a` varchar(255) default NULL,
`b` varchar(255) default NULL,
`c` varchar(255) default NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.00 sec)

sky@127.0.0.1 : test 05:31:23> create index test_a_b_c_ind on test_ind(a,b,c);
Query OK, 0 rows affected (0.03 sec)
Records: 0  Duplicates: 0  Warnings: 0

很順利,創(chuàng)建成功,Innodb是沒有這個(gè)限制的。
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
mysql學(xué)習(xí)筆記!
MySQL5.6 新性能之二(exchange partitions)
? MySQL ORDER BY 的實(shí)現(xiàn)分析
玩轉(zhuǎn)MySQL的外鍵約束之級(jí)聯(lián)刪除篇
mysql處理存在則更新,不存在則插入(多列唯一索引)
MySQL 多表關(guān)聯(lián)更新
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服