For any DBMS, indexes are the most important factor for optimization. For a small amount of data, not having a suitable index does not have a big impact, but as the amount of data increases, performance will drop sharply. If you index multiple columns (composite index), the order of the columns is very important. MySQL can only effectively search for a prefix of the leftmost column of the index. For example: Assume that there is a composite index (c1, c2), the query For example: select b.ISBN FROM book b where b.CATEGORY_ID = 1; Execution time: 0.053s Use explain to analyze the SQL: type = ALL Extra=Using where, the full table query does not use the index. EXPLAIN shows how MySQL uses indexes to process select statements and join tables. It can help choose better indexes and write more optimized query statements. ALL For each combination of rows from the previous tables, a full table scan is performed. This is usually bad if the table is the first table not marked const, and is usually very bad in other cases. Often you can add more indexes instead of using ALL so that rows can be retrieved based on constant values or column values in the previous table. Create a composite index: Execute the SQL again and find that the time is shortened to 0.009s Use explain to analyze the SQL: type = ref, Extra = Using index Index query is used. ref For each combination of rows from the previous tables, all rows with matching index values will be read from this table. If the join uses only a leftmost prefix of the key, or if the key is not UNIQUE or PRIMARY KEY (in other words, if the join cannot select a single row based on the key), then ref is used. This join type is good if the keys used match only a small number of rows. This is the end of this article about the detailed explanation of the combined index method of MySQL. For more relevant MySQL combined index content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Linux uses suid vim.basic file to achieve privilege escalation
>>: Vue uses OSS to upload pictures or attachments
In a project, you often need to use environment v...
For example: Copy code The code is as follows: <...
1. Introduction resolv.conf is the configuration ...
Before using idea to write JSP files, you need to...
A system administrator may manage multiple server...
Background Threads •Master Thread The core backgr...
We are in an era of rapid development of mobile In...
When it comes to switching directories under Linu...
Table of contents 1. v-on directive 1. Basic usag...
Table of contents DOM node Element node: Text nod...
The file name of the dynamic library file under L...
Note: This article is about the basic knowledge p...
Table of contents Prerequisites Setting up a test...
Table of contents Preface Rolling principle accom...
When one needs to edit or modify the website desi...