Home > Backend Development > PHP Tutorial > 6表联合查询,有一个表数据有1万多,访问速度10多秒解决方案

6表联合查询,有一个表数据有1万多,访问速度10多秒解决方案

WBOY
Release: 2016-06-13 13:27:17
Original
948 people have browsed it

6表联合查询,有一个表数据有1万多,访问速度10多秒
我们要做一个查询是由6表数据联合显示的,现在有一个表1万多数据,每次刷新都要10多秒才显示,各位帮忙给点建议,怎么做优化好呢?
sql :
SELECT com_cn_user.real_name,com_cn_client.clShortName,com_cn_product.skuNum1,com_cn_product.Arrival_cycle,com_cn_product.Buy,com_cn_chuku_detail.id,com_cn_chuku_detail.sku,com_cn_product.ItemNum,com_cn_product.Color,com_cn_product.model,com_cn_product.Title_CN,com_cn_product.Brand,sum(com_cn_chuku_detail.quantity) as quantity,com_cn_chuku_detail.remark 
 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 '2012-1-1' and '2012-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 NULL NULL 177 Using where; Using temporary
1 SIMPLE com_cn_chuku_detail ref chukuNum chukuNum 4 com_backup.com_cn_chuku.chukuNum 47  
1 SIMPLE com_cn_product ref ItemNum ItemNum 47 com_backup.com_cn_chuku_detail.itemNum 1  
1 SIMPLE com_cn_supply ref syNum syNum 32 com_backup.com_cn_product.syNum 1  
1 SIMPLE com_cn_user ref usernum usernum 38 com_backup.com_cn_supply.usernum 1  
1 SIMPLE com_cn_client ref clNum clNum 32 com_backup.com_cn_chuku.clNum 2

------解决方案--------------------
有索引也不一定不扫全表……一下子说不清,hoho~~~~

如果仅针对目前的搜索方式,state,submit_date联合索引更佳

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template