Frequently Asked Interview-MySQL Index 01 (Overview)

Frequently Asked Interview-MySQL Index 01 (Overview)

1. What is an index?

Indexes are a special kind of file (the index on the InnoDB data table is a component of the table space), they contain reference pointers to all records in the data table.

Index is a data structure. The database index is a sorted data structure in the database management system to help quickly query and update the data in the database table; the realization of the index usually uses the B tree and its variant B+ tree.

More generally speaking, an index is equivalent to a directory. In order to facilitate the search of the contents of the book, a catalog is formed by indexing the contents. The index is a file, it is to occupy physical space.

2. What are the advantages and disadvantages of indexes?

Advantages of indexing

1. Can greatly speed up data retrieval speed, which is also the main reason for creating an index.

2. By using the index, you can use the optimization hider in the query process to improve the performance of the system.

Disadvantages of indexes

1. Time: it takes time to create and maintain indexes. Specifically, when adding, deleting, and modifying data in a table, indexes should also be dynamically maintained, which will reduce the execution efficiency of addition/change/deletion;

2. Space: The index needs to occupy physical space.

3. What types of indexes are there?

  1. Primary key index: The data column is not allowed to be repeated, and it is not allowed to be NULL. A table can only have one primary key.

  2. Unique index: Data columns are not allowed to be repeated, and NULL values ​​are allowed. A table allows multiple columns to create unique indexes.

You can create ordinary indexes through ALTER TABLE table_name ADD UNIQUE (column);.

You can create a unique composite index through ALTER TABLE table_name ADD UNIQUE (column1, column2).

  1. Ordinary index: The basic index type, there is no restriction on uniqueness, and NULL values ​​are allowed.

You can create a common index through ALTER TABLE table_name ADD INDEX index_name (column).

You can create a combined index through ALTER TABLE table_name ADD INDEX index_name(column1, column2, column3).

  1. Full-text index: It is a key technology currently used by search engines.

You can create a full-text index through ALTER TABLE table_name ADD FULLTEXT (column).

Guess you like

Origin blog.csdn.net/qq_37924905/article/details/108635081