# Multi-Table Join Analysis

+ driving table optimization

```
ALTER TABLE t1 ADD INDEX idx_c(c)

```


![left](./student-guide/diagram/01-49-1.png)

------------------------------------------------------------

First, we analyze the optimization of the driving table t1, if the filter condition is better, then directly adding an index on t1 will obviously reduce the data scanning and filtering cost of the driving table, but if t1.c>'96743211' this condition filters out a large amount of data, such as 1/5 of the total data volume of the t1 table (experience value) or more, then the optimizer's In the cost estimation model, it may be thought that taking a full table scan or other index (for example, if the join column k of the t1 table has an index) is less expensive, instead of using the index on the t1.c field, so that even adding an index on t1.c will not achieve the desired effect, but instead increase the write and storage pressure.

We see from the execution plan of this SQL statement that after the t1 table is filtered according to the c column, there are about 3.4w records, accounting for a relatively small proportion of the total data volume, so adding index filtering on c is good, so we choose to add an index on the c field of t1: ALTER TABLE t1 ADD INDEX idx_c (c).
