MySQL優化GROUP BY-鬆散索引掃描與緊湊索引掃描
阿新 • • 發佈:2019-01-27
鬆散索引
EXPLAIN
SELECT DISTINCT time_id,strative_id FROM d_tf_ydfh_realtime_1;
EXPLAIN
SELECT time_id FROM d_tf_ydfh_realtime_1 GROUP BY time_id;
EXPLAIN
SELECT time_id,strative_id FROM d_tf_ydfh_realtime_1 GROUP BY time_id,strative_id;
EXPLAIN
SELECT time_id,MAX(tdfdfh),MIN(tdfdfh) FROM d_tf_ydfh_realtime_1 WHERE strative_id='3213' GROUP BY time_id;
EXPLAIN
SELECT time_id,strative_id,MAX(tdfdfh),MIN(tdfdfh) FROM d_tf_ydfh_realtime_1 WHERE strative_id<'3213' AND strative_id>'32' GROUP BY time_id,strative_id;
EXPLAIN
SELECT time_id,strative_id,MAX(tdfdfh),MIN(tdfdfh) FROM d_tf_ydfh_realtime_1 WHERE strative_id IN ('3213','32','3210') GROUP BY time_id,strative_id;
EXPLAIN
SELECT time_id,strative_id,MAX(tdfdfh),MIN(tdfdfh) FROM d_tf_ydfh_realtime_1 WHERE time_id='20110903' GROUP BY time_id,strative_id;
EXPLAIN
SELECT time_id,strative_id,MAX(tdfdfh),MIN(tdfdfh) FROM d_tf_ydfh_realtime_1 WHERE time_id<'20130101' GROUP BY time_id,strative_id;
EXPLAIN
SELECT time_id,strative_id,MAX(tdfdfh),MIN(tdfdfh) FROM d_tf_ydfh_realtime_1 WHERE time_id<'20130101' AND time_id>='20120101' GROUP BY time_id,strative_id;
EXPLAIN
SELECT time_id,strative_id,MAX(tdfdfh),MIN(tdfdfh) FROM d_tf_ydfh_realtime_1 WHERE time_id='20110903' AND (strative_id>='32' AND strative_id<'3213') GROUP BY time_id,strative_id;
緊湊索引
EXPLAIN
SELECT strative_id,MAX(tdfdfh),MIN(tdfdfh) FROM d_tf_ydfh_realtime_1 WHERE time_id='20110903' GROUP BY strative_id;
EXPLAIN
SELECT time_id,tdfdfh FROM d_tf_ydfh_realtime_1 WHERE strative_id='32' GROUP BY time_id,tdfdfh;
EXPLAIN
SELECT time_id,strative_id,tdfdfh FROM d_tf_ydfh_realtime_1 WHERE time_id='20110903' GROUP BY strative_id,tdfdfh;