我正在开发一个使用 Couchbase 4.1 的项目,我们正在尝试使用 N1QL 来查询文档。问题是即使我创建了索引器,它似乎也很慢。查询大约需要 2 秒,有大约 11000 个文档。
查询:
SELECT name, displayName, imageId, childCategories FROM `bd-couchbase` WHERE assortment = 'CategoryAssortmentOne' AND categoryPath = 'category-displayname/subcategory-displayName' AND displayName IS NOT MISSING
我的文档如下所示:
{
"parentName": "8442",
"categoryPath": "category-displayname/subcategory-displayName",
"lastUpdated": "2016-05-31T11:02:03.5129252+02:00",
"childCategories": [
{
"name": "0041",
"displayName": "Category 1",
"imageId": "0041"
},
{
"name": "0042",
"displayName": "Category 2",
"imageId": "0042"
},
{
"name": "0043",
"displayName": "Category 3",
"imageId": "0043"
},
{
"name": "0044",
"displayName": "Category 4",
"imageId": "0044"
},
{
"name": "0045",
"displayName": "Category 5",
"imageId": "0045"
},
{
"name": "0046",
"displayName": "Category 6",
"imageId": "0046"
}
],
"assortment": "CategoryAssortmentOne",
"name": "0040",
"displayName": "MyCategory",
"imageId": "0040"
}
我有以下索引:
CREATE INDEX `category_idx` ON `bd-couchbase`((meta().`id`),`name`,`displayName`,`imageId`,`categoryPath`,`childCategories`,`assortment`) USING GSI;
当我执行解释时,我可以看到它使用#primary 索引,然后进行提取(我猜这是查询的慢部分)。但是当我创建我的索引时不应该使用它吗?
我解释的结果:
{
"requestID": "da1946f3-5cc8-4d1e-a05b-06789aa6be92",
"signature": "json",
"results": [
{
"#operator": "Sequence",
"~children": [
{
"#operator": "PrimaryScan",
"index": "#primary",
"keyspace": "my-couchbase",
"namespace": "default",
"using": "gsi"
},
{
"#operator": "Parallel",
"~child": {
"#operator": "Sequence",
"~children": [
{
"#operator": "Fetch",
"keyspace": "my-couchbase",
"namespace": "default"
},
{
"#operator": "Filter",
"condition": "((((`my-couchbase`.`assortment`) =
\"CategoryAssortmentOne\") and ((`my-couchbase`.`categoryPath`) = \"category-displayname/subcategory-displayName\")) and ((`my-couchbase`.`displayName`) is not missing))"
},
{
"#operator": "InitialProject",
"result_terms": [
{
"expr": "(`my-couchbase`.`name`)"
},
{
"expr": "(`my-couchbase`.`displayName`)"
},
{
"expr": "(`my-couchbase`.`imageId`)"
},
{
"expr": "(`my-couchbase`.`childCategorie
s`)"
}
]
},
{
"#operator": "FinalProject"
}
]
}
}
]
}
],
"status": "success",
"metrics": {
"elapsedTime": "13.6696ms",
"executionTime": "13.6696ms",
"resultCount": 1,
"resultSize": 2089
}
}
有什么建议么?
提前致谢。