This article uses examples to describe MySQL duplicate indexes and redundant indexes. Share with you for your reference, the details are as follows: Duplicate index : refers to multiple indexes created on one column or several columns in the same order. Redundant indexes : The columns covered by the two indexes overlap Redundant indexes use index coverage in some special scenarios, so they are faster. Scenario For example, the article and tag table
In actual use, there are two types of queries
SQL statement: select tag from t11 where artid=2; select artid from t11 where tag='PHP'; We can create redundant indexes to achieve index coverage, which will increase query efficiency. 1. Create an article tag table There are two indexes in this table, one is at and the other is ta. Both indexes use the artid and tag fields. CREATE TABLE `t16` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `artid` int(10) unsigned NOT NULL DEFAULT '0', `tag` char(20) NOT NULL DEFAULT '', PRIMARY KEY (`id`), KEY `at` (`artid`,`tag`), KEY `ta` (`tag`,`artid`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 2. Test two SQL statements select artid from t11 where tag='PHP'; The Extra in the query analysis of this statement contains Using index, which means that index coverage is used here. After using index coverage, there is no need to return rows to query data, so the query efficiency is relatively high. select tag from t11 where artid = 1; The Extra in the query analysis of this statement contains Using index, which means that index coverage is used here. After using index coverage, there is no need to return rows to query data, so the query efficiency is relatively high. For more information about index coverage, please refer to the previous article: Index Coverage Readers who are interested in more MySQL-related content can check out the following topics on this site: "Summary of MySQL Index Operation Skills", "Summary of MySQL Common Functions", "Summary of MySQL Log Operation Skills", "Summary of MySQL Transaction Operation Skills", "Summary of MySQL Stored Procedure Skills" and "Summary of MySQL Database Lock-Related Skills". I hope this article will be helpful to everyone's MySQL database design. You may also be interested in:
|
<<: Graphic tutorial on installing Mac system in virtual machine under win10
>>: WeChat applet implements calculator function
Preface In order to ensure the consistency and in...
Table of contents Early creation method Factory P...
Vue+js realizes the fade in and fade out of the v...
This article uses examples to describe how to use...
In this system, the # sign represents the root us...
This article summarizes various ways to implement...
Table of contents Ref and Reactive Ref Reactive T...
Preface Bash has many important built-in commands...
Table of contents 1: Encapsulation idea 2. Packag...
NAT In this way, the virtual machine's networ...
Table of contents Preface: Specific operations St...
This article is just to commemorate those CSS que...
This article example shares the specific code of ...
Preface There are a lot of information and method...
1.1 What is MySQL multi-instance? Simply put, MyS...