我有以下查询
SELECT day,count(DISTINCT campaignId) campaigns
FROM Inheritx use index(daily_type_1)
where _type='DailyCampaignUsage'
group by day
我的索引低于
`CREATE INDEX `daily_type_1` ON `Inheritx`
(`_type`,`day`,(distinct (`campaignId`))) WHERE (`_type` = "DailyCampaignUsage")`
它正在 3s 并且我有52k数据whare _type =“DailyCampaignUsage”
我怎样才能提高它的速度?
答案 0 :(得分:0)
修改索引,如下所示。
CREATE INDEX `daily_type_1` ON `Inheritx` (campaignId,`day`)
WHERE (`_type` = "DailyCampaignUsage");
将索引保留在此答案中。修改您的查询,如下所示。
SELECT day,count(DISTINCT campaignId) campaigns
FROM Inheritx use index(daily_type_1)
where _type='DailyCampaignUsage'
and campaignId is not null
group by day;