Today a friend of mine problem, MEMORY table query engine speed even slower than MYISAM engine!
After perusal of the manual, you do not have such doubts.
We have to solve small under.
Example Table Structure:
Create Table t1_memory (
ID unsigned int Not null Primary Key AUTO_INCREMENT,
A1 decimal (15,12),
A2 decimal (15,12),
the remark VARCHAR (200 is) Not null,
Key idx_u1 (A1, A2)
) Engine Memory;
Create Table t1_myisam (
ID unsigned int Not null Primary Key AUTO_INCREMENT,
A1 decimal (15,12),
A2 decimal (15,12),
the remark VARCHAR (200 is) Not null,
Key idx_u1 (A1, A2)
) Engine MyISAM;
example SQL statement:
SELECT * WHERE t1_memory from A1> A1 110 and <111 and A2> A2 and 23 is <24;
SELECT * WHERE t1_myisam from A1> A1 110 and <111 and A2> A2 and 23 is <24;
Program execution statement:
EXPLAIN
SELECT * WHERE t1_memory from A1> A1 110 and <111 and A2> A2 and 23 is <24;
explain
select * from t1_myisam where a1>110 and a1<111 and a2>23 and a2<24;
MEMORY fundamental reason is the default engine uses HASH indexes, so for RANGE INDEX, we want to modify to BTREE index.
Solution:
Change the index type
alter table t1_memory drop key idx_u1, add
key idx_u1 using btree (a1, a2); optimized execution plan:
EXPLAIN
SELECT * from t1_memory WHERE A1> 110 and A1 <111 and A2> 23 is and A2 <24 ;
See, we also were using the index. Haha.
After perusal of the manual, you do not have such doubts.
We have to solve small under.
Example Table Structure:
Create Table t1_memory (
ID unsigned int Not null Primary Key AUTO_INCREMENT,
A1 decimal (15,12),
A2 decimal (15,12),
the remark VARCHAR (200 is) Not null,
Key idx_u1 (A1, A2)
) Engine Memory;
Create Table t1_myisam (
ID unsigned int Not null Primary Key AUTO_INCREMENT,
A1 decimal (15,12),
A2 decimal (15,12),
the remark VARCHAR (200 is) Not null,
Key idx_u1 (A1, A2)
) Engine MyISAM;
example SQL statement:
SELECT * WHERE t1_memory from A1> A1 110 and <111 and A2> A2 and 23 is <24;
SELECT * WHERE t1_myisam from A1> A1 110 and <111 and A2> A2 and 23 is <24;
Program execution statement:
EXPLAIN
SELECT * WHERE t1_memory from A1> A1 110 and <111 and A2> A2 and 23 is <24;
query result
id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
1 | SIMPLE | t1_memory | ALL | idx_u1 | (NULL) | (NULL) | (NULL) | 3000 | Using where |
explain
select * from t1_myisam where a1>110 and a1<111 and a2>23 and a2<24;
query result
id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
1 | SIMPLE | t1_myisam | range | idx_u1 | idx_u1 | 9 | (NULL) | 1 | Using where |
MEMORY fundamental reason is the default engine uses HASH indexes, so for RANGE INDEX, we want to modify to BTREE index.
Solution:
Change the index type
alter table t1_memory drop key idx_u1, add
key idx_u1 using btree (a1, a2); optimized execution plan:
EXPLAIN
SELECT * from t1_memory WHERE A1> 110 and A1 <111 and A2> 23 is and A2 <24 ;
query result
id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
1 | SIMPLE | t1_memory | range | idx_u1 | idx_u1 | 9 | (NULL) | 2 | Using where |
See, we also were using the index. Haha.
This article comes from " God, let there or be square! " Blog, be sure to keep this source http://yueliangdao0608.blog.51cto.com/397025/228925
Reproduced in: https: //my.oschina.net/u/585111/blog/219507