MySQL multi-table index analysis

1.2 Table Analysis

    select * form users left join dept on users.deptId = dept.id

    Driven by the left side, the data of the left table is naturally available, so the id index needs to be established in the dept table. This is a special case, because the department table id is the primary key, and the index is automatically established.

 

2.3 Table Analysis

    select * form users left join dept on users.deptId = dept.id left join wages on user.id = wages.user_id

    At this point, you need to create an index in the department table id and the wages table user_id

 

Summary: left join to the right table to create an index, right join you know.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326324243&siteId=291194637