This article brings you an introduction to the MySQL database index. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
The storage engine is the core of the database. Commonly used MySQL storage engines include InnoDB, MyISAM, and memory. Index is a data structure that speeds up data query.
1. Introduction to index
1.1 Index advantages
- Query data block
- Data uniqueness
- Accelerate the connection between tables
1.2 Index Disadvantages
- The index will occupy storage space and may be larger than the table data itself
- It is only good for query, and increases the burden of additions, deletions and modifications
1.3 Precautions for using indexes
- Use indexes for data with large field value differences (do not use indexes for gender columns)
- Character fields can be created by selecting only the first few characters of the field Indexes can store data easily.
2. Two important storage engines, InnoDB and MyISAM
2.1 InnoDB
2.1.1 Features
- Support transactions
- Process huge amounts of data
- Table data and indexes are stored separately
- Support row-level locking
- Default 6B length primary key
- The primary key itself is the index, and the index maps not the address, but the primary key, so as to find the row record
##2.1.2 InnoDB index
Only supports B-tree
2.2 MyISAM
2.2.1 Features
Does not support transactions- Inserts and searches are extremely fast
- Does not support transactions
- The first choice for simply adding data
-
2.2.2 MyISAM index
Only supports B-tree
2.2.3 memory index
Support B-tree and HASH
MySQL database generally defaults to innoDB storage engine.
3. Index classification
Ordinary index and unique index- Single column Index and combined index (combined index: only the leftmost match can be used)
- Full-text index: Create word segments, map addresses for each word segment, and find the address of the data by finding the word segments in the index.
- Spatial Index
-
4. Index design principles
The more the better.- Avoid creating too many indexes on frequently updated tables.
- Tables with small data volume do not use indexes.
- Indexes should be built on columns with large value differences.
- Build combined indexes on tables with frequent grouping operations.
- Use short indexes as much as possible to save disk space.
-
This article is over here. For more exciting content, you can pay attention to the
MySQL video tutorial on the PHP Chinese website. Column!
The above is the detailed content of Introduction to the content of MySQL database index. For more information, please follow other related articles on the PHP Chinese website!