mysql - 优化“COUNT(DISTINCT col) WHERE othercol = ?” 为了速度
问题描述
我有一个不同的计数,大约需要半分钟或更长时间才能得到结果。
select COUNT(DISTINCT ip) as unique_visits
from idevaff_iptracking
where acct_id = ? and stamp = ?
计算 IP 的更快方法是什么?ip 列和带有 ip 列的 acct_id 上有索引。
解决方案
对于此查询:
select COUNT(DISTINCT ip) as unique_visits
from idevaff_iptracking
where acct_id = ? and stamp = ?
你想要一个关于idevaff_iptracking(acct_d, stamp, ip)
.
推荐阅读
- javascript - 带有 Lingui (i18n) 的语言切换器,我希望选择的语言在整个应用程序中保持不变,即使在刷新时也是如此
- c++ - 在 C++ 中访问和插入对和 int 的映射
- python - 在 Pandas 中使用自定义 C 函数(一种简单的方法)
- html - 如何将html元素放在一起?
- android - 如何从飞镖/颤振中的列表中获取价值?
- outlook - Microsoft Graph 为有效用户返回 ErrorInvalidUser
- java - 在 Spring bean 的构造函数中访问运行时参数和其他 bean
- sql - 使用 case 语句并为每条前 10 条记录设置不同的值
- azure - JMESPath如何汇总数据
- apache-nifi - 如何恢复从文件系统中删除(通过 GetFile)并在 Content Repository 中保存为 FlowFiles 的文件?