php interview topics --- 16, MySQL create high-performance index test sites
A summary
Sentence summary:
Note: Write-only boutique
1, the index base?
Similar books catalog: Index of books similar to the directory, in order to find a specific topic of a book, you need to find the directory of the book, positioning the corresponding page number
Index -> line number -> Data: storage engine used in a similar manner for data query, which go to the index to find the corresponding value, and then find the corresponding row of data matches the index
2, the impact on the performance of the index?
1, greatly reducing the amount of data that needs to scan the server, greatly improve query speed and reduce the write speed up disk
2, server help avoid sorts and temporary tables
3, the random I / O becomes sequential I / O
3, very small tables, such as 50 data, the index fast full table scan or fast?
Full table scan faster: Because much of the query index step, multi-step so slow
4, the index usage scenarios?
Small table full table scan high efficiency: For very small table, a full table scan higher efficiency in most cases
Medium to large tables very effective: the index is very effective
Large table + partition indexes: the cost of building and using the index will subsequently grow, you can use technology to solve the partition
5, type of the index (base)?
General index: very common index: the index most basic, without any constraints
The only index: unique constraint: Similar to a normal index, but with a unique constraint
Primary key index: uniqueness constraint NOT NULL +: special unique index, does not allow nulls
There are many types of index, are implemented in the storage engine layer
normal index: very common index: basic index, without any constraints
unique index: uniqueness constraint: ordinary index similar to, but having a unique constraint
primary key index : + unique constraint does not allow empty: a special unique index, does not allow nulls
6, the only difference between the index and the primary key index (often test)?
A plurality of unique index: a table can have only one primary key index, there may be a plurality of unique index
Primary key index is a special unique index: primary key index must be unique index, the only index is not a primary key index
Additional primary key index function: primary key the foreign key can be configured referential integrity constraints, preventing data inconsistency
7, the index type (advanced)?
Composite index: multiple columns are combined together to create the index, you can cover multiple columns
Foreign key index (rarely used): Only table type InnoDB foreign key index can only be used to ensure data consistency, integrity, and cascading operation
Full-text indexing (rarely used): MySQL comes with the full-text index can only be used for MyISAM, and can only be conducted in English full-text search
8, MySQL indexes founding principles?
1. The most suitable index column appears in the WHERE clause is a column, or join clause columns instead of appearing in columns after the SELECT keyword
2. the string index, should develop a prefix length, you can save a lot of space index
3. To avoid creating too many indexes, the index will take up extra disk space and reduce the efficiency of the write operation
4. Select the primary key data type short as possible, can effectively reduce the disk footprint index to improve query efficiency
1. The most suitable index column appears in the WHERE clause is a column, or join clause columns instead of appearing in columns after the SELECT keyword
2. The larger the index column of the base, the better the effect of the index
3. the string index, should develop a prefix length, you can save a lot of space index
4. create a composite index based on the situation, the composite index can improve query efficiency
5. avoid creating too many indexes, the index will take up additional disk space, reducing the write operation efficiency
6. select the primary key data type short as possible, can effectively reduce the disk footprint index to improve query efficiency
9, MySQL index precautions?
1.like query% can not front, you can use the full-text index: where name like "% wang%" index will fail
2. If the condition before or columns indexed, not behind, the index will not be used
3. In the column type is a string, you must give value quotes query, or index failure: where name = 100; name is a string, so 100 to quotes
1. composite index prefix follow the principle of
2.like query% can not front, you can use the full-text index: where name like "% wang% " index will fail
3.column is null can use the index
4. If MySQL estimated using the index than the full table scan slower, decide not to use index: where id> 1 and id < 100: query the index as more steps of
5. If the condition before the column or in an index, the latter is not, the index will not be used
6. The column type is a string, you must give values quoted query, the index or failure: where name = 100; name is a string, so 100 in quotes
Second, content in summary
Reproduced in: https: //www.cnblogs.com/Renyi-Fan/p/11073647.html