AUTO_INCREMENT ON the MyISAM STORAGE ENGINE
AUTO_INCREMENT ON the MyISAM STORAGE ENGINE
CASE:
HOW TO TUNNING AUTO_INCREMENT ON THE MyIS STORAGE ENGINE
SOLVE:
1.AUTO_INCREMENT column is a multiple-column index and order by last column of a multiple-column index.
2.AUTO_INCREMENT column is one key faster in engine myisam than engine innodb
1.AUTO_INCREMENT column is a multiple-column index and order by last column of a multiple-column index.
mysql> create table autoincre_demo
-> (
-> d1 smallint not null auto_increment,
-> d2 smallint not null,
-> name varchar(10),
-> primary key (d2,d1)
-> )
-> engine=myisam;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into autoincre_demo(d2,name) values(2,'2'),(3,'3'),(4,'4'),(2,'2'),(3,'3'),(4,'4');
Query OK, 6 rows affected (0.00 sec)
Records: 6 Duplicates: 0 Warnings: 0
mysql> select * from autoincre_demo;
+----+----+------+
| d1 | d2 | name |
+----+----+------+
| 1 | 2 | 2 |
| 1 | 3 | 3 |
| 1 | 4 | 4 |
| 2 | 2 | 2 |
| 2 | 3 | 3 |
| 2 | 4 | 4 |
+----+----+------+
6 rows in set (0.00 sec)
## order by id2 and id2 is last column of a multiple-column index
2.AUTO_INCREMENT column is one key faster in engine myisam than engine innodb
mysql> create table myisam_tab
-> (
-> id MEDIUMINT NOT NULL AUTO_INCREMENT,
-> id2 MEDIUMINT NOT NULL,
-> PRIMARY KEY(ID)
-> )
-> engine=MYISAM;
Query OK, 0 rows affected (0.01 sec)
mysql> create table innodb_tab
-> (
-> id MEDIUMINT NOT NULL AUTO_INCREMENT,
-> id2 MEDIUMINT NOT NULL,
-> PRIMARY KEY(ID)
-> )
-> engine=innodb;
Query OK, 0 rows affected (0.04 sec)
mysql> insert into myisam_tab(id2) select id2 from myisam_tab;
Query OK, 409600 rows affected (1.10 sec)
Records: 409600 Duplicates: 0 Warnings: 0
mysql> insert into innodb_tab(id2) select id2 from innodb_tab;
Query OK, 409600 rows affected (4.22 sec)
Records: 409600 Duplicates: 0 Warnings: 0
## insert into myisam_tab time is 1.10 sec and insert into innodb_tab time is 4.22 sec
Reference
http://dev.mysql.com/doc/refman/5.7/en/myisam-storage-engine.html
When rows are
inserted in sorted order (as when you are using an
AUTO_INCREMENT column), the index tree is split so that the high node only contains one key. This
improves space utilization in the index tree.
Internal handling of one AUTO_INCREMENT column per table is supported. MyISAM automatically updates this column for INSERT and UPDATE operations. This makes AUTO_INCREMENT columns faster (at least 10%). Values at the top of the sequence are not reused after being deleted. (When an AUTO_INCREMENT column is defined as the last column of a multiple-column index, reuse of values deleted from the top of a sequence does occur.) The AUTO_INCREMENT value can be reset with ALTER TABLE or myisamchk.
########################################################################################
版權所有,文章允許轉載,但必須以連結方式註明源地址,否則追究法律責任!【QQ交流群:53993419】
QQ:14040928 E-mail:dbadoudou@163.com
本文連結: http://blog.itpub.net/blog/post/id/2072782/
########################################################################################
dbadoudou scripts
create table autoincre_demo
(
d1 smallint not null auto_increment,
d2 smallint not null,
name varchar(10),
primary key (d2,d1)
)
engine=myisam;
insert into autoincre_demo(d2,name) values(2,'2'),(3,'3'),(4,'4'),(2,'2'),(3,'3'),(4,'4');
select * from autoincre_demo;
create table myisam_tab
(
id MEDIUMINT NOT NULL AUTO_INCREMENT,
id2 MEDIUMINT NOT NULL,
PRIMARY KEY(ID)
)
engine=MYISAM;
create table innodb_tab
(
id MEDIUMINT NOT NULL AUTO_INCREMENT,
id2 MEDIUMINT NOT NULL,
PRIMARY KEY(ID)
)
engine=innodb;
insert into myisam_tab(id2) select id2 from myisam_tab;
insert into innodb_tab(id2) select id2 from innodb_tab;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26442936/viewspace-2072782/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL:ERROR 1286 (42000): Unknown storage engine 'MyISAM'MySqlError
- MYSQL TABLE CHANGE STORAGE ENGINEMySql
- Got error 28 from storage engine 解決方法GoError
- Percona XtraDB Storage Engine安裝筆記筆記
- Failed to read auto-increment value from storage engineAIREM
- MySQL ERROR 1031 (HY000) at line 33: Table storage engine forMySqlError
- MySQL AUTO_INCREMENTMySqlREM
- 解決ERROR 1030 (HY000): Got error 168 from storage engine apparmorErrorGoAPP
- MySQL的AUTO_INCREMENTMySqlREM
- The Storage Situation: Removable StorageREM
- 記錄一次常見的錯誤:java.sql.SQLException: Got error 28 from storage engineJavaSQLExceptionGoError
- Using AUTO_INCREMENT CASEREM
- mysql的auto_increment詳解MySqlREM
- AUTO_INCREMENT的實現方式REM
- MyISAM InnoDB 區別
- MySQL5.7之auto_increment回溯MySqlREM
- mysql中auto_increment是什麼MySqlREM
- SQL基礎 AUTO_INCREMENT 欄位SQLREM
- storage事件中的坑,storage.setItem()無法觸發storage事件事件
- Js template engineJS
- Database StorageDatabase
- MySQL: InnoDB 還是 MyISAM?MySql
- 表型別對AUTO_INCREMENT的影響型別REM
- 安裝 Docker EngineDocker
- mysql myisam的鎖機制MySql
- Innodb與MyISAM的區別
- MyISAM與InnoDB的區別
- InnoDB和MyISAM 區別(轉)
- Myisam & InnoDB 優化引數優化
- InnoDB和MyISAM的區別
- MyISAM和InnoDB的區別
- JavaScript storage 事件JavaScript事件
- Web Storage概述Web
- Kafka Offset StorageKafka
- MySQL Storage EnginesMySql
- Physical Storage StructuresStruct
- Password Storage - UserDetailsAI
- ALTER TABLE causes auto_increment resulting key 'PRIMARY'REM