Get the App
SLTechnology News&Howtos  ›  Database  › 

What are the wildcards optimized by mysql

Shulou Source: shulou.com Published: 2022-05-31 16:10:52 10月03日 Update

This article shows you how mysql optimized wildcards are, concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

When mysql queries the data again, if the index column of the where condition uses wildcards to match the data, if it is like this:

Mysql > EXPLAIN

Select * from np_order_lyz lzy where lzy.order_id like '29628%'

->

+-- +

| | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |

+-- +

| | 1 | SIMPLE | lzy | ALL | order_id | NULL | NULL | NULL | 45241 | Using where |

+-- +

1 row in set

Such an index can be used.

If wildcards are placed first, indexes such as

Mysql > EXPLAIN

Select * from np_order_lyz lzy where lzy.order_id like'% 29628'

+-- +

| | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |

+-- +

| | 1 | SIMPLE | lzy | ALL | NULL | NULL | NULL | NULL | 45241 | Using where |

+-- +

1 row in set

If you often need to start a query with a wildcard, the common method is to save the reverse reverse field like reverse'% .com'of the query value in the database to use the index.

The above is what the mysql-optimized wildcards look like. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Wildcards indexes data queries content skills knowledge concise concise fields that is commonly used beginnings databases articles methods are in more conditions articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Docker Xiaomi Apple MySQL