您好,登錄后才能下訂單哦!
本篇內容介紹了“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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。