您好,登錄后才能下訂單哦!
本篇內(nèi)容介紹了“MySQL內(nèi)存表的缺點是什么”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
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內(nèi)存表的弊端有什么
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|+----+-------------+----------+------+---------------+------+---------+------+------+-------------+
當(dāng)然內(nèi)存表也可以手動添加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)
哈哈,它也用到索引了。
所以要選擇合適的存儲引擎至關(guān)重要。
“MySQL內(nèi)存表的缺點是什么”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。