6. table join query: there is more than 10 thousand table data and the access speed is more than 10 seconds.

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.