Back-end Interview Speaking Skills Collection Chapter 17: MySQL Interview Speaking Skills

This is the seventeenth blog post of the back-end interview collection - MySQLinterview skills❗❗❗

1. Explain single-column index and joint index

  1. A single-column index refers to creating an index on a certain column of a table.

  2. A joint index is an index created jointly on multiple columns.

Single-column indexes can appear whereanywhere in the condition, while joint indexes need to be written in a certain order. When querying with multiple conditions, the joint index is more efficient, and our joint index can create up to two columns.

When we create an index, we also have to consider the update frequency of our table. If there are many indexes in the table, it will affect the update speed, because the process of creating an index is actually to build a binary tree, and every time the data is updated, you have to Recalculate the binary tree, so it affects the update speed.

The index does not take effect all the time. For example, the following situations can cause the index to fail:

  1. If there are conditions or, even if there are conditions with indexes, they will not be used, which is why they should be used as little as possible. orIf you want to use them orand want the indexes to take effect, you can only oradd indexes to each column in the conditions.

  2. likeA query starting %with is will cause the index to fail.

  3. If the column type is a string, the data must be quoted in the condition, otherwise the index will fail.

  4. If mysqlit is estimated that using a full table scan will be faster than using an index, then do not use an index.

So, if we create an index, we don't create it casually.

2. Advantages and disadvantages of using index query

  1. Advantages of using indexes:

    <

Guess you like

Origin blog.csdn.net/lvoelife/article/details/132584770