1. Conditions for joint index failureA joint index is also called a composite index. An index on two or more columns is called a composite index. For composite indexes: MySQL uses the fields in the index from left to right. A query can use only part of the index, but only the leftmost part. For example, the index is key index (a,b,c). It can support the search of three combinations: a | a,b | a,b,c, but does not support the search of b,c. When the leftmost field is a constant reference, the index is very effective. The additional columns in the index allow you to narrow the scope of your search, but using one index with two columns is different from using two separate indexes. The structure of a composite index is similar to a phone book, where a person's name consists of a last name and a first name. The phone book is sorted first by last name pairs, and then by first name pairs for people with the same last name. A phone book is very useful if you know the last name, even more useful if you know both the first and last name, but useless if you know only the first name. So when creating a composite index, you should carefully consider the order of the columns. Composite indexes are useful when you perform searches on all columns in the index or on just the first few columns; they are not useful when you perform searches on just any of the later columns. For example: create a composite index of name, age, and gender. create table myTest( a int, b int, c int, KEY a(a,b,c) ); (1) select * from myTest where a=3 and b=5 and c=4; ---- abc order (2) select * from myTest where c=4 and b=6 and a=3; (3) select * from myTest where a=3 and c=7; (4) select * from myTest where a=3 and b>7 and c=3; ---- b range value, breakpoint, blocks the index of c (5) select * from myTest where b=3 and c=4; --- Joint indexes must be used in order and all of them must be used. Because index a is not used, indexes b and c are not used here. (6) select * from myTest where a>4 and b=7 and c=9; (7) select * from myTest where a=3 order by b; (8) select * from myTest where a=3 order by c; (9) select * from mytable where b=3 order by a; 2. Conditions for index failure
String indexing fails without single quotes SELECT * from staffs where name='2000'; -- Because MySQL will perform implicit type conversion at the bottom level SELECT * from staffs where name=2000; --- No index is used General advice
This is the end of this article about the conditions for the effectiveness of MySQL joint indexes and the conditions for index invalidation. For more relevant content about the effectiveness of MySQL joint indexes, 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:
|
<<: Javascript File and Blob Detailed Explanation
>>: Introduction to RHCE bridging, password-free login and port number modification
When we add borders to table and td tags, double ...
Table of contents 1. Concept 2. Environmental Des...
How to check where the metadata lock is blocked i...
Simple description Since it was built with Centos...
This article describes how to configure time sync...
This article shares a simple HTML shopping quanti...
To replace a string, we need to use the following...
Table of contents 1. MySQL replication related co...
usemap is an attribute of the <img> tag, use...
Table of contents Global Registration Partial Reg...
Table of contents 1. Set Deduplication 2. Double ...
This article shares the specific code of using ca...
Copy code The code is as follows: a:link { font-s...
Table of contents Preface 1. Download MySQL from ...
Table of contents introduce Key Features Effect d...