如何通过以下方式优化Couchbase NQ1L订单

如何通过以下方式优化Couchbase NQ1L订单,couchbase,Couchbase,考虑以下用例: 索引 CREATE INDEX `type-index`ON bucket( type, createdAt) WHERE type='someType'; 查询(性能相当好) 执行时间:14.51毫秒 一个查询(执行得非常糟糕) 执行:1m 这里有一个解释 [ { "plan": { "#operator": "Sequence", "~children": [ { "#operator": "Seque

考虑以下用例:

索引

CREATE INDEX `type-index`ON bucket( type, createdAt) WHERE type='someType';
查询(性能相当好)

执行时间:14.51毫秒

一个查询(执行得非常糟糕)

执行:1m

这里有一个
解释

[
  {
    "plan": {
      "#operator": "Sequence",
      "~children": [
        {
          "#operator": "Sequence",
          "~children": [
            {
              "#operator": "IndexScan",
              "index": "type-index",
              "index_id": "ee6b75813c26795c",
              "keyspace": "bucket",
              "namespace": "default",
              "spans": [
                {
                  "Range": {
                    "High": [
                      "successor(\"someType\")"
                    ],
                    "Inclusion": 1,
                    "Low": [
                      "\"someType\""
                    ]
                  }
                }
              ],
              "using": "gsi"
            },
            {
              "#operator": "Parallel",
              "~child": {
                "#operator": "Sequence",
                "~children": [
                  {
                    "#operator": "Fetch",
                    "as": "a",
                    "keyspace": "bucket",
                    "namespace": "default"
                  },
                  {
                    "#operator": "Filter",
                    "condition": "((`a`.`_type`) = \"someType\")"
                  },
                  {
                    "#operator": "InitialProject",
                    "result_terms": [
                      {
                        "expr": "`a`",
                        "star": true
                      }
                    ]
                  }
                ]
              }
            }
          ]
        },
        {
          "#operator": "Order",
          "limit": "10",
          "offset": "10",
          "sort_terms": [
            {
              "desc": true,
              "expr": "(`a`.`createdAt`)"
            }
          ]
        },
        {
          "#operator": "Offset",
          "expr": "10"
        },
        {
          "#operator": "Limit",
          "expr": "10"
        },
        {
          "#operator": "FinalProject"
        }
      ]
    },
    "text": "SELECT a.* FROM `bucket` a WHERE a.type='someType' ORDER BY a.createdAt DESC IMIT 10 OFFSET 10"
  }
]

该存储桶包含170万个文档。是否有任何方法可以提高ORDER BY的性能?值
createdAt
是unix时间戳(数字)

解决方案是创建如下索引:

CREATE INDEX `type-index` ON bucket ( -createdAt ) WHERE type='sometType';
以及查询

SELECT a.*
FROM `bucket` a
WHERE type='someType'
AND -createdAt IS NOT NULL
ORDER BY -createdAt
LIMIT 10 OFFSET 10;

基本上,解决方案是创建正确的对流索引,并确保您正在使用它。计划中提供了对DESC的更好支持,并将在下一版本中提供。目前,上述解决方案应该可以正常工作。
CREATE INDEX `type-index` ON bucket ( -createdAt ) WHERE type='sometType';
SELECT a.*
FROM `bucket` a
WHERE type='someType'
AND -createdAt IS NOT NULL
ORDER BY -createdAt
LIMIT 10 OFFSET 10;