以下查询需要5-6秒才能执行。有什么方法可以改进吗?表中有大约190万条记录,合格记录为0.9百万
查询:
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毫秒。