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

IndexProjection entry missing when filter on indexScan with LET

    XMLWordPrintable

Details

    • Untriaged
    • 0
    • Unknown

    Description

       

      insert into default values ("k01",{ "attr": { "colors": [ "red", "blue", "green" ], "id": 1 } });
      CREATE INDEX idx6 ON default(attr.id, attr);
       SELECT c FROM default d USE INDEX (idx6) UNNEST attr.colors AS c LET da = d.attr WHERE da.id=1 AND da.colors IS NOT MISSING;
       
      

      0 rows returned vs expected 3

      EXPLAIN SELECT c FROM default d USE INDEX (idx6) UNNEST attr.colors AS c LET da = d.attr WHERE da.id=1 AND da.colors IS NOT MISSING;
      {
          "requestID": "4f8ddd9a-249d-41d9-9b70-09d7db39795e",
          "signature": "json",
          "results": [
          {
              "optimizer_hints": {
                  "hints_followed": [
                      "INDEX(d idx6)"
                  ]
              },
              "plan": {
                  "#operator": "Sequence",
                  "~children": [
                      {
                          "#operator": "IndexScan3",
                          "as": "d",
                          "covers": [
                              "cover (((`d`.`attr`).`id`))",
                              "cover ((`d`.`attr`))",
                              "cover ((meta(`d`).`id`))"
                          ],
                          "filter": "((cover (((`d`.`attr`).`id`)) = 1) and ((cover ((`d`.`attr`)).`colors`) is not missing) and is_array((cover ((`d`.`attr`)).`colors`)))",
                          "index": "idx6",
                          "index_id": "6005ac23830d101b",
                          "index_projection": {
                              "entry_keys": [
                                  1
                              ]
                          },
                          "keyspace": "default",
                          "namespace": "default",
                          "spans": [
                              {
                                  "range": [
                                      {
                                          "high": "1",
                                          "inclusion": 3,
                                          "index_key": "(`attr`.`id`)",
                                          "low": "1"
                                      },
                                      {
                                          "inclusion": 0,
                                          "index_key": "`attr`",
                                          "low": "null"
                                      }
                                  ]
                              }
                          ],
                          "using": "gsi"
                      },
                      {
                          "#operator": "Parallel",
                          "~child": {
                              "#operator": "Sequence",
                              "~children": [
                                  {
                                      "#operator": "Unnest",
                                      "as": "c",
                                      "expr": "(cover ((`d`.`attr`)).`colors`)",
                                      "filter": "(`c` is not missing)"
                                  }
                              ]
                          }
                      },
                      {
                          "#operator": "Parallel",
                          "~child": {
                              "#operator": "Sequence",
                              "~children": [
                                  {
                                      "#operator": "Let",
                                      "bindings": [
                                          {
                                              "expr": "cover ((`d`.`attr`))",
                                              "var": "da"
                                          }
                                      ]
                                  },
                                  {
                                      "#operator": "Filter",
                                      "condition": "(((`da`.`id`) = 1) and ((`da`.`colors`) is not missing))"
                                  },
                                  {
                                      "#operator": "InitialProject",
                                      "discard_original": true,
                                      "result_terms": [
                                          {
                                              "expr": "`c`"
                                          }
                                      ]
                                  }
                              ]
                          }
                      }
                  ]
              },
              "text": "SELECT c FROM default d USE INDEX (idx6) UNNEST attr.colors AS c LET da = d.attr WHERE da.id=1 AND da.colors IS NOT MISSING;"
          }
          ],
          "status": "success",
          "metrics": {
              "elapsedTime": "2.451699ms",
              "executionTime": "2.290176ms",
              "resultCount": 1,
              "resultSize": 3731,
              "serviceLoad": 3
          }
      }

      index_projection is missing 0

      IndexScan    "filter": "((cover (((`d`.`attr`).`id`)) = 1) <=== 0 th key

      This is due to LET cause it decided it not need,

      But LET is not evaluated before indescan filter, if filter is there we need add the keys to projection

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty