我在 Couchbase 中有以下存储桶 我正在使用内部联接来获取文档
我们有父文档和子文档的全局二级索引。
- 存储桶中的总记录数:4,300,000
- 查询执行:5-7 秒
- 使用的 RAM 为 32 GB(已分配 90 GB)
- 使用的磁盘为 20 GB
就像我们有父文档并用父文档制作子文档的多个副本
示例:
{
"document_id" : "p-001",
"document_desc" : "parent doc 1",
"document_type" : "parent"
},
{
"document_id" : "c-001",
"parent_document_id" : "p-001",
"document_desc" : "child doc of parent 1",
"document_type" : "child",
"document_status" : "NEW",
"customer_id" : "c-001"
},
{
"document_id" : "c-002",
"parent_document_id" : "p-001",
"document_desc" : "child doc of parent 1",
"document_type" : "child",
"document_status" : "NEW",
"customer_id" : "c-001"
}
我正在使用内部联接来获取文档
SELECT * FROM
test_document AS parent
JOIN
test_document AS child
ON child.parent_document_id = parent.document_id
WHERE child.customer_id = 'c-001'
AND child.document_status IN ('NEW', 'OLD', 'OLDER')
我可以改进这个查询,使查询在几毫秒内(1 秒之前)执行吗? 或者还有其他想法可以实现 1 秒之前的查询执行吗?
最佳答案
CREATE ix1 ON test_document (customer_id, document_status, parent_document_id);
CREATE ix2 ON test_document (document_id);
由于您对 child 有谓词,请切换 JOIN 顺序
SELECT *
FROM test_document AS child
JOIN test_document AS parent ON child.parent_document_id = parent.document_id
WHERE child.customer_id = 'c-001' AND child.document_status IN ['NEW', 'OLD', 'OLDER'];
关于couchbase - 改进大型数据集的 Couchbase 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76130051/