问题
I have below query
SELECT day,count(DISTINCT campaignId) campaigns
FROM Inheritx use index(daily_type_1)
where _type='DailyCampaignUsage'
group by day
I have below index
`CREATE INDEX `daily_type_1` ON `Inheritx`
(`_type`,`day`,(distinct (`campaignId`))) WHERE (`_type` = "DailyCampaignUsage")`
it is taking 3s and I habe 52k data whare _type= "DailyCampaignUsage"
how I Can improve it's speed ?
回答1:
Modify your index as follows.
CREATE INDEX `daily_type_1` ON `Inheritx` (campaignId,`day`)
WHERE (`_type` = "DailyCampaignUsage");
Keep the index in this answer. Modify your query as follows.
SELECT day,count(DISTINCT campaignId) campaigns
FROM Inheritx use index(daily_type_1)
where _type='DailyCampaignUsage'
and campaignId is not null
group by day;
来源:https://stackoverflow.com/questions/41544159/index-not-improve-speed-in-couchbase-4-5