MySQL group-by very slow

后端 未结 5 2143
予麋鹿
予麋鹿 2021-02-07 05:34

I have the folowwing SQL query

SELECT CustomerID FROM sales WHERE `Date` <= \'2012-01-01\' GROUP BY CustomerID

The query is executed over 11

5条回答
  •  迷失自我
    2021-02-07 06:07

    Without knowing what your table schema looks like, it's difficult to be certain, but it would probably help if you added a multiple-column index on Date and CustomerID. That'd save MySQL the hassle of doing a full table scan for the GROUP BY statement. So try ALTER TABLE sales ADD INDEX (Date,CustomerID).

提交回复
热议问题