本篇内容介绍了“MySQL内存表的缺点是什么”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
CREATETABLE`mem_test`(`id`int(10)unsignedNOTNULLDEFAULT'0',`name`varchar(10)DEFAULTNULL,`first`varchar(10)DEFAULTNULL,PRIMARYKEY(`id`),KEY`NewIndex1`(`name`,`first`))ENGINE=MEMORY;CREATETABLE`innodb_test`(`id`int(10)unsignedNOTNULLDEFAULT'0',`name`varchar(10)DEFAULTNULL,`first`varchar(10)DEFAULTNULL,PRIMARYKEY(`id`),KEY`NewIndex1`(`name`,`first`))ENGINE=InnoDB;
如:
1:在=或者<=>情况下,飞快,但是在如<或>情况下,他是不使用索引
mysql--chinastor.com-root@localhost:17db07:33:45>>explainselect*frommem_testwhereid>3;+----+-------------+----------+------+---------------+------+---------+------+------+-------------+|id|select_type|table|type|possible_keys|key|key_len|ref|rows|Extra|+----+-------------+----------+------+---------------+------+---------+------+------+-------------+|1|SIMPLE|mem_test|ALL|PRIMARY|NULL|NULL|NULL|15|Usingwhere|+----+-------------+----------+------+---------------+------+---------+------+------+-------------+1rowinset(0.00sec)mysql--chinastor.com-root@localhost:17db07:33:49>>explainselect*frominnodb_testwhereid>3;+----+-------------+-------------+-------+---------------+---------+---------+------+------+-------------+|id|select_type|table|type|possible_keys|key|key_len|ref|rows|Extra|+----+-------------+-------------+-------+---------------+---------+---------+------+------+-------------+|1|SIMPLE|innodb_test|range|PRIMARY|PRIMARY|4|NULL|7|Usingwhere|+----+-------------+-------------+-------+---------------+---------+---------+------+------+-------------+1rowinset(0.00sec)
2:不能用在orderby情况下来提高速度
mysql--chinastor.com-root@localhost:17db07:33:55>>explainselect*frominnodb_testorderbyid;+----+-------------+-------------+-------+---------------+---------+---------+------+------+-------+|id|select_type|table|type|possible_keys|key|key_len|ref|rows|Extra|+----+-------------+-------------+-------+---------------+---------+---------+------+------+-------+|1|SIMPLE|innodb_test|index|NULL|PRIMARY|4|NULL|15||+----+-------------+-------------+-------+---------------+---------+---------+------+------+-------+1rowinset(0.00sec)mysql--chinastor.com-root@localhost:17db07:34:27>>explainselect*frommem_testorderbyid;+----+-------------+----------+------+---------------+------+---------+------+------+----------------+|id|select_type|table|type|possible_keys|key|key_len|ref|rows|Extra|+----+-------------+----------+------+---------------+------+---------+------+------+----------------+|1|SIMPLE|mem_test|ALL|NULL|NULL|NULL|NULL|15|Usingfilesort|+----+-------------+----------+------+---------------+------+---------+------+------+----------------+1rowinset(0.00sec)
MySQL内存表的弊端有什么
3:不能确定俩值之间有多少行
mysql--chinastor.com-root@localhost:17db07:37:14>>explainselectcount(1)frommem_testwhereid>3andid<6;+----+-------------+----------+------+---------------+------+---------+------+------+-------------+|id|select_type|table|type|possible_keys|key|key_len|ref|rows|extra|+----+-------------+----------+------+---------------+------+---------+------+------+-------------+|1|simple|mem_test|all|primary|null|null|null|20|usingwhere|+----+-------------+----------+------+---------------+------+---------+------+------+-------------+1rowinset(0.00sec)mysql--chinastor.com-root@localhost:17db07:40:35>>explainselectcount(1)frominnodb_testwhereid>3andid<6;+----+-------------+-------------+-------+---------------+---------+---------+------+------+--------------------------+|id|select_type|table|type|possible_keys|key|key_len|ref|rows|extra|+----+-------------+-------------+-------+---------------+---------+---------+------+------+--------------------------+|1|simple|innodb_test|range|primary|primary|4|null|1|usingwhere;usingindex|+----+-------------+-------------+-------+---------------+---------+---------+------+------+--------------------------+1rowinset(0.00sec) localhost:17db07:37:07="">>explainselect*frominnodb_testwherename='b';+----+-------------+-------------+------+---------------+-----------+---------+-------+------+--------------------------+|id|select_type|table|type|possible_keys|key|key_len|ref|rows|Extra|+----+-------------+-------------+------+---------------+-----------+---------+-------+------+--------------------------+|1|SIMPLE|innodb_test|ref|NewIndex1|NewIndex1|33|const|8|Usingwhere;Usingindex|+----+-------------+-------------+------+---------------+-----------+---------+-------+------+--------------------------+1rowinset(0.00sec)mysql--chinastor.com-root@localhost:17db07:37:10>>explainselect*frommem_testwherename='b';+----+-------------+----------+------+---------------+------+---------+------+------+-------------+|id|select_type|table|type|possible_keys|key|key_len|ref|rows|Extra|+----+-------------+----------+------+---------------+------+---------+------+------+-------------+|1|SIMPLE|mem_test|ALL|NewIndex1|NULL|NULL|NULL|20|Usingwhere|+----+-------------+----------+------+---------------+------+---------+------+------+-------------+
当然内存表也可以手动添加btree
CREATEINDEXBTREE_indexUSINGBTREEonmem_test(name,first)mysql--chinastor.com-root@localhost:17db03:36:41>>explainselect*frommem_testwherename='b';+----+-------------+----------+------+-----------------------+-------------+---------+-------+------+-------------+|id|select_type|table|type|possible_keys|key|key_len|ref|rows|Extra|+----+-------------+----------+------+-----------------------+-------------+---------+-------+------+-------------+|1|SIMPLE|mem_test|ref|NewIndex1,BTREE_index|BTREE_index|33|const|9|Usingwhere|+----+-------------+----------+------+-----------------------+-------------+---------+-------+------+-------------+1rowinset(0.00sec)
哈哈,它也用到索引了。
所以要选择合适的存储引擎至关重要。
“MySQL内存表的缺点是什么”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。