Uploaded image for project: 'Couchbase Server'
  1. Couchbase Server
  2. MB-63069

UNNEST applies early order on unnest variable

    XMLWordPrintable

Details

    • Untriaged
    • 0
    • Yes

    Description

      UPSERT INTO default VALUES("test::1", { "type": "test", "items": [ { "nestedId": 1 } ] }),
                          VALUES("test::2", { "type": "test", "items": [ { "nestedId": 2 } ] });
       
      CREATE INDEX ix30 ON default(type);
       
      SELECT _a.nestedId as id
      FROM default AS a
      UNNEST a.items AS _a
      WHERE a.type = "test"
      ORDER BY id DESC
      LIMIT 2;

      EXPLAIN SELECT _a.nestedId as id FROM default AS a UNNEST a.items AS _a WHERE a.type = "test" ORDER BY id DESC LIMIT 2;{
          "requestID": "f162c015-1585-40e3-89c6-b814dbb13f1d",
          "signature": "json",
          "results": [
          {
              "plan": {
                  "#operator": "Sequence",
                  "~children": [
                      {
                          "#operator": "Sequence",
                          "~children": [
                              {
                                  "#operator": "IndexScan3",
                                  "as": "a",
                                  "index": "ix30",
                                  "index_id": "576b0c84935422c7",
                                  "index_keys": [
                                      "_index_key ((meta(`a`).`id`))"
                                  ],
                                  "index_projection": {
                                      "primary_key": true
                                  },
                                  "keyspace": "default",
                                  "namespace": "default",
                                  "spans": [
                                      {
                                          "exact": true,
                                          "range": [
                                              {
                                                  "high": "\"test\"",
                                                  "inclusion": 3,
                                                  "index_key": "`type`",
                                                  "low": "\"test\""
                                              }
                                          ]
                                      }
                                  ],
                                  "using": "gsi"
                              },
                              {
                                  "#operator": "Order",
                                  "flags": 7,
                                  "sort_terms": [
                                      {
                                          "desc": "\"desc\"",
                                          "expr": "(`_a`.`nestedId`)"
                                      }
                                  ]
                              },
                              {
                                  "#operator": "Fetch",
                                  "as": "a",
                                  "early_projection": [
                                      "items",
                                      "type"
                                  ],
                                  "keyspace": "default",
                                  "namespace": "default"
                              },
                              {
                                  "#operator": "Parallel",
                                  "maxParallelism": 1,
                                  "~child": {
                                      "#operator": "Sequence",
                                      "~children": [
                                          {
                                              "#operator": "Filter",
                                              "alias": "a",
                                              "condition": "((`a`.`type`) = \"test\")"
                                          },
                                          {
                                              "#operator": "Unnest",
                                              "as": "_a",
                                              "expr": "(`a`.`items`)"
                                          }
                                      ]
                                  }
                              },
                              {
                                  "#operator": "Parallel",
                                  "maxParallelism": 1,
                                  "~child": {
                                      "#operator": "Sequence",
                                      "~children": [
                                          {
                                              "#operator": "InitialProject",
                                              "preserve_order": true,
                                              "result_terms": [
                                                  {
                                                      "as": "id",
                                                      "expr": "(`_a`.`nestedId`)"
                                                  }
                                              ]
                                          }
                                      ]
                                  }
                              }
                          ]
                      },
                      {
                          "#operator": "Limit",
                          "expr": "2"
                      }
                  ]
              },
              "text": "SELECT _a.nestedId as id FROM default AS a UNNEST a.items AS _a WHERE a.type = \"test\" ORDER BY id DESC LIMIT 2;"
          }
          ],
          "status": "success",
          "metrics": {
              "elapsedTime": "1.512ms",
              "executionTime": "1.436166ms",
              "resultCount": 1,
              "resultSize": 4380,
              "serviceLoad": 2
          }
      }

      Order is on Unnest variable and explicit UNNEST present. Early Order can't be done

      Even ORDER BY _a.nestedId DESC also does early order

      Attachments

        For Gerrit Dashboard: MB-63069
        # Subject Branch Project Status CR V

        Activity

          People

            pierre.regazzoni Pierre Regazzoni
            Sitaram.Vemulapalli Sitaram Vemulapalli
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty