【发布时间】:2020-08-16 01:26:55
【问题描述】:
我有比较简单的查询:
select client_coordinator_id
from projects
where status not in ("DELETED", "ARCHIVED")
and client_coordinator_id > 0
group by client_coordinator_id
projects表大约有320k条记录,client_coordinator_id和status列都有索引,查询仍然需要0.7秒左右。
状态是ENUM类型。
EXPLAIN 给出了这个:
id - 1
select_type - SIMPLE
table - projects
partitions - null
type - index
possible_keys - status,client_coordinator_idx,status_project_batch_id_idx,idx_status_new_status_id
key - client_coordinator_idx
key_len - 4
ref - null
rows - 311837
filtered - 40.00
Extra - using where
我在这里做错了什么?知道这个查询有什么问题吗?
【问题讨论】:
-
我猜您使用
group by client_coordinator_id删除重复项。而是尝试select distinct client_coordinator_id并检查是否有任何改进。
标签: mysql sql select query-optimization where-clause