select COUNT(distinct a.oid) count from member a where a.tid = '2001' AND a.type = 0 AND a.delete_at is null
执行是2.7s 库里有25w数据
select COUNT(a.id) count from member a where a.tid = '2001' AND a.type = 0 AND a.delete_at is null
执行是0.7s
select COUNT(distinct a.oid) count from member a where a.tid = '2001' AND a.type = 0 AND a.delete_at is null
执行是2.7s 库里有25w数据
select COUNT(a.id) count from member a where a.tid = '2001' AND a.type = 0 AND a.delete_at is null
执行是0.7s
试试
SELECT COUNT(*) `count` FROM (
SELECT DISTINCT `a`.`oid` FROM `member` `a` WHERE `a`.`tid` = '2001' AND `a`.`type` = 0 AND `a`.`delete_at` IS NULL
) `tmp`
另外记得给 oid
加个索引、给 tid, type
加个联合索引。
4 回答1.2k 阅读✓ 已解决
8 回答1.2k 阅读
2 回答1.3k 阅读✓ 已解决
3 回答1k 阅读✓ 已解决
2 回答824 阅读✓ 已解决
1 回答907 阅读✓ 已解决
2 回答1.7k 阅读
最终解决的还是子查询的慢 还是没有解决