The difference between mysql joint index and ordinary index

        In MySQL, joint indexes and ordinary indexes are both index types used to speed up queries. The difference between them is the number of columns indexed and the order of the columns.

        Ordinary indexes only index a single column, while joint indexes index multiple columns at the same time, and these columns can be combined in a specific order. For example, you can create a joint index for two columns in a table (column A and column B), so that queries can access rows that match both columns more quickly.

The following are the advantages and disadvantages of joint indexes and ordinary indexes:

1. Advantages of joint index

        Queries that need to query multiple columns simultaneously, such as with WHERE and ORDER BY clauses, can be processed more quickly.
The joint index can reduce the number of indexes and reduce the storage space occupied.
In some cases, using a joint index may be preferable to using a single index because the optimizer can make better use of the index.

2. Disadvantages of joint index

        When the number of rows in a table is very large, joint indexes can become slower because MySQL needs to scan more index data to find matching rows.
When only a part of the joint index is used in the query, the joint index may not be used, which may cause the query to be slower.
If rows in the table are frequently inserted, updated, or deleted, then the join index may become slower because MySQL needs to recalculate the index.

3. Advantages of common index

        Ordinary indexes only index a single column, which can process queries that only need to query one column faster.
When the number of rows in a table is very large, a normal index may be faster than a join index because MySQL needs to scan less index data.
When only part of a normal index is used in a query, MySQL can still use the index, which may make the query faster.

4. Common index disadvantages

        If multiple columns need to be queried at the same time, using normal indexes may become slower, because MySQL needs to scan more data to find matching rows.
When the number of rows in a table is very large, plain indexes can become slower because MySQL needs to scan more data to find matching rows.

Guess you like

Origin blog.csdn.net/m0_52191385/article/details/130488094