Couchbase n1ql主扫描性能
我的文件如下:Couchbase n1ql主扫描性能,couchbase,n1ql,Couchbase,N1ql,我的文件如下: { "date": "1970-02-19", “uid”: 2345 “profile": [ "Profile Text, Profile Text, Profile Text, Profile Text, Profile Text", "Profile Text, Profile Text, Profile Text, Profile Text, Profile Text", "Profile Text, Profile Tex
{
"date": "1970-02-19",
“uid”: 2345
“profile": [
"Profile Text, Profile Text, Profile Text, Profile Text, Profile Text",
"Profile Text, Profile Text, Profile Text, Profile Text, Profile Text",
"Profile Text, Profile Text, Profile Text, Profile Text, Profile Text"
],
“channel_a”: {
"reach": 915157,
"likes": 6.39,
"shares": 8.15,
"followergrowth": 6.89
},
“channel_b”: {
"reach": 894888,
"response": 8.64,
"influence": 7.03,
"reject": 5.09
},
“channel_c” {
"reach": 396938
}
}
文档密钥由文档类型、用户id(数字)和日期组成。e、 g.频道:9999:2015-12-31。我想创建一个查询,返回给定日历月内特定频道参与率最高的前10名用户列表。标准可能因渠道和要求而异
上面的查询计划使用主索引扫描,几乎需要一分钟才能完成。合格的数据集大约有1.3K行,但这可能会增加到5K行。Couchbase上是否有任何机制可供我使用,以获得更好的性能?此外,随着数据量的增长,我正在寻找一种可扩展的解决方案
select
s. uid,
sum(s.channel_c.reach) channel_c_Reach,
sum(s.channel_b.reach) channel_b_Reach,
sum(s.channel_a.likes) channel_a_Likes
FROM channels s
where meta().id like ‘channels:%:2016-05-%’
group by s.uid
ORDER BY sum(s.channel_a.likes) DESC
LIMIT 10
如果您的查询使用的是主索引,那么有很多地方可以改进。关键是创建几个索引来支持您的查询 查看这篇文章,讨论如何为group BY创建索引:
另外,我认为问题在于索引扫描,正如您在问题标题中所猜测的那样。您可以尝试几个选项来提高查询性能。
CREATE INDEX ix1 ON channels(uid, date, channel_a.likes, channel_c.reach, channel_b.reach)
WHERE meta().id like "channels:%";
SELECT
s.uid,
sum(s.channel_c.reach) channel_c_Reach,
sum(s.channel_b.reach) channel_b_Reach,
sum(s.channel_a.likes) channel_a_Likes
FROM channels s
WHERE meta(s).id like "channels:%" AND s.uid IS NOT NULL AND s.date LIKE "2016-05-%"
group by s.uid
ORDER BY sum(s.channel_a.likes) DESC
LIMIT 10 ;