It is said that InnoDB is good, so should we use the Memory engine?

The question I left for you at the end of the last article is: both group by statements use order by null, why the value of 0 is in the last line in the statement result obtained by using the memory temporary table; while using the disk temporary table to get In the results, the value 0 is in the first row?

Today we will take a look at the reasons for this problem.

Data organization structure of memory table

For the convenience of analysis, let me simplify this problem. Suppose there are the following two tables t1 and t2. Table t1 uses the Memory engine, and table t2 uses the InnoDB engine.

create table t1(id int primary key, c int) engine=Memory;
create table t2(id int primary key, c int) engine=innodb;
insert into t1 values(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(0,0);
insert into t2 values(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(0,0);

Then, I do select * from t1 and select * from t2 respectively.
It can be seen that 0 is in the last row in the return result of memory table t1, and 0 is in the first row in the return result of InnoDB table t2.

The reason for this difference starts with the organization of the primary key indexes of the two engines.

Table t2 uses the InnoDB engine. You are already familiar with the organization of its primary key index id: the number of InnoDB tables

Guess you like

Origin blog.csdn.net/yzh_2017/article/details/128741261