该orders表有 2m 条记录。有 ~900K 独特ship-to-id的 s。
ship_to_id(字段为int(8))上有一个索引。
下面的查询需要将近 1000 万才能完成。我已经运行PROCESSLIST了Command=Query和State= Sending Data。
当我运行时explain,使用现有索引,并且possible_keys是NULL.
我应该做些什么来加快这个查询?谢谢。
SELECT
ship_to_id as customer_id
FROM orders
GROUP BY ship_to_id
HAVING SUM( price_after_discount ) > 0