mysql - 如何减少使用或者不用LEFT JOIN查询?
PHPz
PHPz 2017-04-17 16:50:13
0
4
730
PHPz
PHPz

学习是最好的投资!

reply all(4)
Ty80

Separate query, using key-value pairs

PHPzhong

A very simple and practical solution is to create an intermediate table and exchange space for time.

In addition, when the amount of data reaches a certain level, consider dividing databases and tables. You can look at the mycat middleware.

大家讲道理

Personally, it is recommended to exclude tables one by one to see which table affects the query speed. After determining which table it is, then do index optimization based on it

小葫芦

From the perspective of database optimization, the final result is just one count(*). A large number of associations lead to memory consumption and time waste.

Give me an idea:
Make the sql result as follows:

The final count(*) is equal to the multiplication and final addition of the quantities in each row,
That is: (Quantity 11*Quantity 12*...*Quantity 16)+(Quantity 21*...*Quantity 26)
To reduce a large number of Cartesian product.

sql:

select t_for_sale.id,  nvl(t1.count1, 0), ...
left join (select id, count(*) count1 from t_user group by id) t1 on t1.id=t_for_sale.id
....
from t_for_sale
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!