Home > database > How does the SQL optimization, takes 10 seconds, amount of data in 4000
How does the SQL optimization, takes 10 seconds, amount of data in 4000
Time:09-25
The SELECT Anderson d, a.n ame, p.n ame AS platformName, COUNT (1) The FROM xx_coupon AS a LEFT the JOIN msds_saleplat AS p=p.o ON Amy polumbo latform rder_plaform LEFT the JOIN ( The SELECT coupon, COUNT (1) recCount The FROM xx_coupon_card GROUP BY coupon ) AS t1 ON Anderson, d=t1. Coupon LEFT the JOIN ( SELECT the coupon, the SUM (useCount) useCount The FROM ( The SELECT Arthur c. oupon, COUNT (1) the useCount The FROM xx_coupon_code c INNER JOIN xx_order o ON o. chua oupon_code=c.i d WHERE o.o rder_status!=3 AND o.p ayment_status=2 AND O. chua oupon_code & gt;=0 AND coupons IS NULL GROUP BY Arthur c. oupon UNION ALL The SELECT Arthur c. oupon, COUNT (1) the useCount The FROM xx_order o INNER JOIN xx_order_item_coupon xc ON xc. The orders=o.i d INNER JOIN xx_coupon_code c ON xc. Coupon_code=c.i d WHERE o.o rder_status!=3 AND o.p ayment_status=2 AND O. chua oupon_code IS NULL AND o. chua oupons & gt;=0 GROUP BY Arthur c. oupon ) k GROUP BY coupon ) AS t2 ON Anderson, d=t2. Coupon WHERE Anderson s_giftcards=0 AND a.t ype!=2 AND a.e nd_date & gt; AND ='2019-12-09'A. egin_date & lt; ='2020-01-09'The ORDER BY DESC Anderson, d
CodePudding user response:
Turn LEFT into a temporary table,
CodePudding user response:
You should A list the amount of data is large, the database is to put A table and other tables all associated, and the results after the WHERE, so will be efficient, if just query, recommends that the result of A table after the WHERE to the temporary table and associated with other tables
CodePudding user response:
1. Check the slow speed is which link 2. Creating a suitable index
CodePudding user response:
Look at the execution plan, see slow in where?
CodePudding user response:
The SELECT coupon, COUNT (1) recCount The FROM xx_coupon_card GROUP BY coupon The SQL for 9 seconds, the data quantity 35 million
CodePudding user response:
Coupon have index, in view of the coupon to build a clustered index