Get the App
SLTechnology News&Howtos  ›  Database  › 

What are the disadvantages of MySQL memory table

Shulou Source: shulou.com Published: 2022-05-31 18:50:55 09月30日 Update

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!

Tags: Memory situation shortcomings content more knowledge index appropriate practical important learned and then in between dilemmas practical drawbacks engines manual articles are in Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Information Shulou Technology Shulou Tech Info vpn