mysql optimization (4) index coverage and optimal index
Index coverage** A very important concept is to search on the index! ! !
If the queried column happens to be part of the index, then the query only needs to be performed on the index file, and there is no need to go back to the disk to find data.
This kind of query is very fast and is called For "index coverage"
Non-clustered index index files correspond to data retrieval, which wastes time
The difference between index and data
The index is an efficiently organized tree , node, leaf structure search is better than data
The index can be imported into the memory for query
The index itself has a simple data structure and it is very fast to put it into the memory
. . . . . . . . . As a result, it was full as soon as I returned. . . I wipe. . .
So if you create two indexes index(uid, aid)
If the data you want has been covered in the index tree, such as select uid from msg where aid = 1
The index has covered what you want to look up, so the speed and efficiency of fetching the index directly from the memory are very fast and naturally there is no need to go back and search
Optimal index:
Query frequently, distinguish High degree, small length
Try to cover common fields, ------》Index coverage
The left prefix is not easy to distinguish, reverse the url to get the content; the left prefix is highly distinguishable
Pseudo hash crc32() function to uniquely distinguish crc32 ('http://wwww.baidu.com'); build an index for urlcrc instead of url to avoid indexing
Learn to explain to view Effect;
Pseudo hash index effect
Save url_hash column at the same time
create table t10 ( id int primary key, url char(60) not null default '' );
insert into t10 values (1,'http://www.baidu.com'), (2,'http://www.sina.com'), (3,'http://www.sohu.com.cn'), (4,'http://www.onlinedown.net'), (5,'http://www.gov.cn'); alter table t10 add urlcrc int unsigned not null;
When sql is stored, crcurl== crc32(url),
Because the result of crc is a 32-bit int unsigned number, when the data exceeds 4 billion, there will be duplication, but it is worth it.
(Index length is int4 bytes)
Multiple index design
But from the actual business of the mall, customers generally choose large categories first ->small categories->brands,
Finally choose (1)index(cat_id,brand_id), + index(cat_id,shop_price) to build the index
You can even add (3)index(cat_id,brand_id,shop_price), 3 redundant Redundant index fields. . .
But the first 2 columns in (3) are the same as the first 2 columns in (1), then remove (1)
index (cat_id,price) and index(cat_id,brand_id,shop_price); that is, the left prefix principle can be redundant but cannot be repeated
The above is mysql optimization ( 4) Index coverage and optimal index content. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to improve performance by optimizing the AVG function in MySQL MySQL is a popular relational database management system that contains many powerful functions and functions. The AVG function is widely used in calculating averages, but because this function needs to traverse the entire data set, it will cause performance problems in the case of large-scale data. This article will introduce in detail how to optimize the AVG function through MySQL to improve performance. 1. Using indexes Indexes are the most important part of MySQL optimization.

MySQL is a relational database management system widely used in the field of e-commerce. In e-commerce applications, it is crucial to optimize and secure MySQL. This article will analyze MySQL’s optimization and security project experience in e-commerce applications. 1. Performance optimization database architecture design: In e-commerce applications, database design is the key. Reasonable table structure design and index design can improve the query performance of the database. At the same time, using table splitting and partitioning technology can reduce the amount of data in a single table and improve query efficiency.

MySQL optimization based on TokuDB engine: improving writing and compression performance Introduction: As a commonly used relational database management system, MySQL is facing increasing writing pressure and storage requirements in the context of the big data era. To meet this challenge, TokuDB engine came into being. This article will introduce how to use the TokuDB engine to improve MySQL's writing performance and compression performance. 1. What is TokuDB engine? TokuDB engine is a big data-oriented engine designed to handle high write

MySQL is a widely used relational database management system commonly used for web application development and data storage. In practical applications, the underlying optimization of MySQL is particularly important, among which the advanced optimization of SQL statements is the key to improving database performance. This article will introduce some tips and best practices for implementing MySQL's underlying optimization, as well as specific code examples. Determine the query conditions When writing SQL statements, you must first clearly define the query conditions and avoid using unlimited wildcard queries, that is, avoid using "%" to open the query.

How to optimize MySQL connection number management MySQL is a popular relational database management system that is widely used in various websites and applications. In the actual application process, MySQL connection number management is a very important issue, especially in high concurrency situations. Reasonable management of the number of connections can improve the performance and stability of the system. This article will introduce how to optimize MySQL connection number management, including detailed code examples. 1. Understand connection number management In MySQL, the number of connections refers to the number of connections that the system can connect at the same time.

How to properly configure and optimize MySQL's double-write buffering technology Introduction: MySQL's double-write buffering technology is an important technology that improves data security and performance. This article will introduce how to properly configure and optimize MySQL's double-write buffering technology to better protect data and improve database performance. 1. What is double-write buffering technology? Double-write buffering technology is an I/O optimization technology of MySQL. It can significantly reduce the number of disk I/O operations and improve the write performance of the database. When MySQL performs a write operation, first

MySQL database is a common relational database. As the amount of data in the database increases and query requirements change, underlying optimization becomes particularly important. In the process of underlying optimization of MySQL, SQL statement optimization is a crucial task. This article will discuss common techniques and principles for SQL statement optimization and provide specific code examples. First of all, SQL statement optimization needs to consider the following aspects: index optimization, query statement optimization, stored procedure and trigger optimization, etc. In these aspects, we will have

MySQL is a widely used open source database management system for storing and managing large amounts of data. However, when using MySQL, you may encounter a variety of problems, from simple syntax errors to more complex performance issues and glitches. In this article, we will explore some of the most common MySQL problems and solutions. Connection Problems Connection problems are common. If you cannot connect to the MySQL server, please check the following points: 1) Whether the MySQL server is running 2) Whether the network connection is normal 3) MySQ
