For 6-table join queries, there is more than 10 thousand table data, and the access speed is more than 10 seconds. we want to perform a query that is displayed by 6-table join queries. now there is a table with more than 10 thousand data, it takes more than 10 seconds to display each refresh. you can give me some suggestions. how can I optimize it? SQL: SELECTcom_cn_user.real_name, com_cn_client.clShortName, com_cn_product.skuNum1, com_c 6 table joint query, there is a table with more than 10 thousand data, access speed more than 10 seconds
We want to make a query that is jointly displayed by 6 tables of data. now there is a table with more than 10 thousand data records. it takes more than 10 seconds to display each refresh. please give me some suggestions, how can we optimize it?
SQL:
SELECT com_cn_user.real_name, region, region, metrics, com_cn_product.ItemNum, com_cn_product.Color, com_cn_product.model, metrics, com_cn_product.Brand, sum (quota) as quantity, quota
FROM com_cn_chuku
Left join com_cn_chuku_detail ON com_cn_chuku.chukuNum = com_cn_chuku_detail.chukuNum
Left join com_cn_product ON com_cn_chuku_detail.itemNum = com_cn_product.ItemNum
Left join com_cn_supply ON com_cn_supply.syNum = com_cn_product.syNum
Left join com_cn_user ON com_cn_user.usernum = com_cn_supply.usernum
Left join com_cn_client ON com_cn_client.clNum = com_cn_chuku.clNum
Where com_cn_chuku.state = 2 and com_cn_chuku.submit_date between '2017-1-1 'and '2017-06-15' group by com_cn_product.ItemNum order by Null
Explain:
Id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE com_cn_chuku ALL state NULL 177 Using where; Using temporary
1 SIMPLE com_cn_chuku_detail ref chukuNum 4 com_backup.com_cn_chuku.chukuNum 47
1 SIMPLE com_cn_product ref ItemNum 47 com_backup.com_cn_chuku_detail.itemNum 1
1 SIMPLE com_cn_supply ref syNum 32 com_backup.com_cn_product.syNum 1
1 SIMPLE com_cn_user ref usernum 38 com_backup.com_cn_supply.usernum 1
1 SIMPLE com_cn_client ref clNum 32 com_backup.com_cn_chuku.clNum 2
------ Solution --------------------
If you have an index, you may not scan the entire table ...... I can't explain it all at once, hoho ~~~~
If you only search for the current method, it is better to combine the state and submit_date indexes.