sql - 发布 || 聚合耗时
问题描述
下面的查询需要 5-6 秒才能执行。有什么办法可以改进吗?表中有大约 190 万条记录,符合条件的记录为 90 万条
询问:
Select startdate, perosntypecode, verificationstatuscode, activitynumber, enddate, activityname, COUNT(*)
from personmoderation
where startdatetimegmt >= '2018-06-12T10:00:56'
and embarkdate between (SELECT p.startdate FROM personmoderation AS p
WHERE p.startdatetimegmt >= '2018-06-12T10:00:56'
ORDER BY p.startdatetimegmt ASC LIMIT 1
)
and (SELECT p.startdate FROM personmoderation AS p
WHERE p.startdatetimegmt >= '2018-06-12T10:00:56'
ORDER BY p.startdatetimegmt ASC LIMIT 1
) + interval '100 days'
group by startdate, perosntypecode, verificationstatuscode, activitynumber, enddate, activityname
指数:
create
index ix1 on
personmoderation
using btree(
startdatetimegmt,
startdate,
persontypecode,
verificationstatuscode,
activitynumber,
enddate,
activityname
);
注意:where 子句中使用的子查询需要 3-4 毫秒。
解决方案
推荐阅读
- ios - 删除插入分组 UITableView 上方的空间
- python-3.x - 在 PyCharm 中导入文件 for UnitTest 教程
- tensorflow - 为什么 1x1 卷积层可用于神经网络回归中的特征减少?
- node.js - Node.js/NestJS:强制执行 HTTP 调用(使其成为更热的 Observable)
- android-studio - Gradle任务assembleDebug在颤振中失败
- tcl - 使用 TCL 脚本从 REST API 获取价值
- r - 试图删除第一次出现的字符 |
- java - 如何使用从 Hashmap 上的 Arraylist 中选择的值?
- python - 'pandas.core' 没有属性 'index'
- python - 在python的循环中创建lambda表达式并应用于数据框列