Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the disadvantages of MySQL memory table

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "what are the shortcomings of the MySQL memory table". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

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`))

Such as:

1: in the = or case, very fast, but in this case, he does not use the index

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 | 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: cannot be used to increase speed in the case of 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 | 15 | Usingfilesort | + +-+ 1rowinset (0.00sec)

What are the disadvantages of MySQL memory table

3: not sure how many rows there are between the two values

Mysql--chinastor.com-root@localhost:17db07:37:14 > > explainselectcount (1) frommem_testwhereid > 3andid > explainselectcount (1) frominnodb_testwhereid > 3andid > 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 | 20 | Usingwhere | + -+

Of course, you can also add btree manually to the memory table.

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)

Haha, it also uses the index.

Therefore, it is very important to choose the right storage engine.

This is the end of the content of "what are the shortcomings of the MySQL memory table". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report