N1QL中是否有内置函数,相当于MySQL中SQL_CALC_FOUND_ROWS
和FOUND_ROWS()
与LIMIT
,OFFSET
一起用于准备寻呼机目的?
如果没有什么是获得相同结果的最佳解决方法,而不是执行下面提到的其他N1QL查询
SELECT COUNT(id) FROM mybucket WHERE <same condition that get first result set>
答案 0 :(得分:1)
在我们对数据进行排序(因此我们可以计算)和LIMIT结果集的情况下,您可以获得完整可能结果集的计数。 sortCount是没有限制的可能文档的总数。
select * from `beer-sample` where city > "" order by city limit 10;
...
"status": "success",
"metrics": {
"elapsedTime": "273.677801ms",
"executionTime": "273.636223ms",
"resultCount": 10,
"resultSize": 8740,
**"sortCount": 1390**
}
}
如果没有ORDER BY,您只需获得以下内容。
select * from `beer-sample` where city > "" limit 10;
...
"status": "success",
"metrics": {
"elapsedTime": "21.661524ms",
"executionTime": "21.619021ms",
"resultCount": 10,
"resultSize": 10163
}
}
在4.5中,当您进行覆盖索引扫描时,您可以发出并行查询以仅从索引扫描进行计数。
解释将指示此“CountScan”方法是否可用于查询。
示例:
cbq> explain select count(1) from `beer-sample` where city = 'San Francisco';
{
"requestID": "fe9b3f0f-bfc2-4132-bfd7-6268b78860d4",
"signature": "json",
"results": [
{
"plan": {
"#operator": "Sequence",
"~children": [
{
**"#operator": "IndexCountScan",**
"covers": [
"cover ((`beer-sample`.`city`))",
"cover ((meta(`beer-sample`).`id`))"
],
"index": "idxcity",
"index_id": "66d88e11a6178a04",
"keyspace": "beer-sample",
"namespace": "default",
"spans": [
{
"Range": {
"High": [
"\"San Francisco\""
],
"Inclusion": 3,
"Low": [
"\"San Francisco\""
]
}
}
],
"using": "gsi"
},
{
"#operator": "IndexCountProject",
"result_terms": [
{
"expr": "count(1)"
}
]
}
]
},
"text": "select count(1) from `beer-sample` where city = 'San Francisco'"
}
],
"status": "success",
"metrics": {
"elapsedTime": "4.434551ms",
"executionTime": "4.382437ms",
"resultCount": 1,
"resultSize": 1572
}
}
cbq>