请找到以下查询,它在/tmp/
目录上花费更多时间、负载和空间
SELECT DISTINCT pil.pilsellersku,
pil.pilname,
pbi.pbicode,
'',
group_concat(DISTINCT ppt.pptcmtrfnum SEPARATOR ','),
pbi.pbibrand,
'',
'',
'',
'',
pil.pilicmdisplaycolor,
pbi.pbidesc,
pbi.pbiattrlabel1,
pil.pilattrvalue1,
pbi.pbiattrlabel2,
pil.pilattrvalue2,
pbi.pbiattrlabel3,
pil.pilattrvalue3,
'',
pod.PODISBESTSELLER,
pod.PODISNEWARRIVAL,
pod.PODISCHOSEN,
pit.pitzoomimage,
pit.pitimage,
pil.pilimage,
pit.pitthumbnailimage,
pit.pitthumbnailimage,
pil.pilmrp,
pod.PODMARGIN,
pod.PODRETCOST,
pbi.pbidiscvalue,
pbi.pbidiscinvalue,
pil.pilvat,
pil.pilstockqty,
pil.PILASRTGRP,
sot.sotsomrfnum,
group_concat(DISTINCT ppm.PPMPMTRFNUM SEPARATOR ','),
ccg.ccgrfnum,
pil.pilactive,
pbi.pbiisgiftwrap,
pbi.pbigiftwrapcharge,
pbi.pbiispreffdate,
pbi.pbissirfnum,
pod.PODSTSL,
'',
'',
pod.PODPVC,
pod.PODWSPRICE,
pod.PODODV,
pod.PODSEQ,
pod.PODSTCODE,
pod.PODTAXATTRI,
pod.PODPRODUNIT,
pod.PODSTDCOST,
pod.PODMATCODE,
pod.PODWEEK,
pod.PODYEAR,
pod.PODDYRWK,
pod.PODISBESTBUY,
pbi.isonline,
pbi.pbiseqnum,
scm.scmcode
FROM Ismpbi pbi
LEFT JOIN ISMPIL pil
ON pbi.pbirfnum = pil.pilpbirfnum
LEFT JOIN ISMPIT pit
ON pbi.pbirfnum = pit.pitpbirfnum
AND pit.pitviewseq = 1
LEFT JOIN ISMSOT sot
ON sot.sotpbirfnum = pbi.pbirfnum
LEFT JOIN OTHPOD pod
ON pod.podpbirfnum = pbi.pbirfnum
LEFT JOIN ISMPPM ppm
ON ppm.ppmpbirfnum = pbi.pbirfnum
LEFT JOIN ISMPPT ppt
ON ppt.pptpbirfnum = pbi.pbirfnum
LEFT JOIN ISMCCG ccg
ON pbi.pbiccgrfnum = ccg.ccgrfnum
LEFT JOIN OCTSCM scm
ON pbi.pbiscmrfnum = scm.scmrfnum
WHERE pbi.PBIBRAND = 35
GROUP BY pil.pilsellersku;
在上面的查询中,所有连接的列和条件列(即pbi.PBIBRAND
& pit.pitviewseq
)都被索引。
并解释语句如下。
+----+-------------+-------+--------+-------------------------------------------+--------------+---------+-------------------------+------+----------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+--------+-------------------------------------------+--------------+---------+-------------------------+------+----------------------------------------------+
| 1 | SIMPLE | pbi | ref | IDX_PBIBRAND | IDX_PBIBRAND | 9 | const | 4420 | Usingwhere; Using temporary; Using filesort |
| 1 | SIMPLE | pil | ref | IDX_PILPBI | IDX_PILPBI | 8 | apparel.pbi.PBIRFNUM | 3 | |
| 1 | SIMPLE | pit | ref | IDX_PITPBI | IDX_PITPBI | 8 | apparel.pbi.PBIRFNUM | 9 | |
| 1 | SIMPLE | sot | ref | PRIMARY,SOTPBIRFNUM,IDX_SOTPBI | PRIMARY | 8 | apparel.pbi.PBIRFNUM | 1 | Using index |
| 1 | SIMPLE | pod | ref | PODPBIRFNUM,FK_POD_PBI,FK8B908042468F70B6 | PODPBIRFNUM | 9 | apparel.pbi.PBIRFNUM | 1 | |
| 1 | SIMPLE | ppm | ref | IDX_PPMPBI | IDX_PPMPBI | 8 | apparel.pbi.PBIRFNUM | 1 | |
| 1 | SIMPLE | ppt | ref | PRIMARY,PPTPBIRFNUM,IDX_PPTPBI | PRIMARY | 8 | apparel.pbi.PBIRFNUM | 1 | Using index |
| 1 | SIMPLE | ccg | eq_ref | PRIMARY,CCGRFNUM | PRIMARY | 8 | apparel.pbi.PBICCGRFNUM | 1 | Using index |
| 1 | SIMPLE | scm | eq_ref | PRIMARY,SCMRFNUM | PRIMARY | 8 | apparel.pbi.PBISCMRFNUM | 1 | |
+----+-------------+-------+--------+-------------------------------------------+--------------+---------+-------------------------+------+----------------------------------------------+
9 rows in set (0.00 sec)
上述查询耗时近 17 分钟。服务器上的负载超过 15,/tmp/
磁盘级别的方向消耗 21 GB。
任何人都可以建议优化和修改查询以获得结果。