我有以下查询。
SELECT DailyCampaignUsage.day date, sum (ARRAY_SUM(DailyCampaignUsage.`statistics`[*].clicks)) clicks,
sum (ARRAY_SUM(DailyCampaignUsage.`statistics`[*].clicksCost)) revenue
FROM Inheritx DailyCampaignUsage
JOIN Inheritx Campaign ON KEYS ('Campaign|'||TOSTRING(DailyCampaignUsage.campaignId))
JOIN Inheritx Users on keys('User|'|| TOSTRING(Campaign.`user`))
WHERE DailyCampaignUsage._type='DailyCampaignUsage' and
DATE_PART_MILLIS(STR_TO_MILLIS(DailyCampaignUsage.day),'year')=2016
and DATE_PART_MILLIS(STR_TO_MILLIS(DailyCampaignUsage.day),'month')=5
group by DailyCampaignUsage.day
order by DailyCampaignUsage.day
我没有_type的索引 像
CREATE INDEX `Ottoman__type` ON `Inheritx`(`_type`)
当我执行上述查询时,它正在 10s
当我尝试创建像
这样的索引时 CREATE INDEX `dailyCampaignUsage_type_clicks_cost` ON
`Inheritx`(_type,day,`statistics`[*].clicks,`statistics`[*].clicksCost) WHERE
`_type` = "DailyCampaignUsage" USING GSI
但它不会花费更多的时间13s。 我还使用了使用索引(dailyCampaignUsage_type_clicks_cost) 但是不要工作。
我应该创建哪个索引?
答案 0 :(得分:0)
您可以发布示例文档,EXPLAIN输出,您拥有多少文档,couchbase版本,群集设置(同一节点上的所有服务,或使用MDS多维缩放)等。
您可能想尝试将年,月作为索引键包含在内..
创建索引dailyCampaignUsage_type_clicks_cost
ON
Inheritx
(_ type,DATE_PART_MILLIS(STR_TO_MILLIS(DailyCampaignUsage.day),'year'),DATE_PART_MILLIS(STR_TO_MILLIS(DailyCampaignUsage.day),'month'),day ...)WHERE ...