欢迎投稿

今日深度:

GROUP BY外移,提高SQL运行速度,groupsql

GROUP BY外移,提高SQL运行速度,groupsql


数据表dh_order_detail 里一共有169247条数据

原始SQL

		SELECT
			FROM_UNIXTIME(order_time, '%H:%i') 'time',
			city,
			district,
			LEFT (company, 6) company,
			goods_num,
			order_price,
			order_code,
			order_time
		FROM
			dh_order_detail
		WHERE
			province_id = 16
                GROUP BY
	                order_code
		ORDER BY
			order_time DESC
		LIMIT 50

运行时间4秒多

改进,将GROUP BY外移

SELECT
	*
FROM
	(
		SELECT
			FROM_UNIXTIME(order_time, '%H:%i') 'time',
			city,
			district,
			LEFT (company, 6) company,
			goods_num,
			order_price,
			order_code,
			order_time
		FROM
			dh_order_detail
		WHERE
			province_id = 16
		ORDER BY
			order_time DESC
		LIMIT 50
	) o
GROUP BY
	order_code
运行时间0.049秒






www.htsjk.Com true http://www.htsjk.com/shujukunews/6973.html NewsArticle GROUP BY外移,提高SQL运行速度,groupsql 数据表dh_order_detail里一共有169247条数据 原始SQL SELECTFROM_UNIXTIME(order_time, %H:%i) time,city,district,LEFT (company, 6) company,goods_num,order_price,order_code,order_timeF...
评论暂时关闭