select(*)这个操作 在存储引擎MyISAM会比存储引擎Innodb的查询速度快

#MyISAM

mysql> select count(*) from sbtest1;

+----------+

| count(*) |

+----------+

|   800000 |

+----------+

1 row in set (0.47 sec)

 

#切换存储引擎为innodb

mysql> alter table sbtest1 ENGINE=innodb ;

Query OK, 800000 rows affected (45.84 sec)

 

Records: 800000  Duplicates: 0  Warnings: 0

mysql> select count(*) from sbtest1;

+----------+

| count(*) |

+----------+

|   800000 |

+----------+

1 row in set (2.43 sec)

 

哈哈,就是这么快,还有下文

 

mysql> explain select count(*) from sbtest1;

+----+-------------+---------+------------+-------+---------------+------+---------+------+--------+----------+-------------+

| id | select_type | table   | partitions | type  | possible_keys | key  | key_len | ref  | rows   | filtered | Extra       |

+----+-------------+---------+------------+-------+---------------+------+---------+------+--------+----------+-------------+

|  1 | SIMPLE      | sbtest1 | NULL       | index | NULL          | k_1  | 4       | NULL | 789120 |   100.00 | Using index |

+----+-------------+---------+------------+-------+---------------+------+---------+------+--------+----------+-------------+

1 row in set, 1 warning (0.39 sec)

mysql> alter table sbtest1 ENGINE=myisam;

Query OK, 800000 rows affected (20.63 sec)

Records: 800000  Duplicates: 0  Warnings: 0

mysql> explain select count(*) from sbtest1;

+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+------------------------------+

| id | select_type | table | partitions | type | possible_keys | key  | key_len | ref  | rows | filtered | Extra                        |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+------------------------------+

|  1 | SIMPLE      | NULL  | NULL       | NULL | NULL          | NULL | NULL    | NULL | NULL |     NULL | Select tables optimized away |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+----------+------------------------------+

1 row in set, 1 warning (0.06 sec)

创建时间:2021-12-22 10:38
浏览量:0