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

UNNEST with covering array index should remove DistinctScan

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Critical
    • 4.6.2, 5.0.0
    • 5.0.0
    • query
    • None

    Description

      Unnest using covered index we may have to remove DistinctScan (due to distinct on meta().id).  

      CREATE INDEX by_replies ON default (ALL ARRAY r.`user` FOR r IN replies END, title);

      explain SELECT t.title, r.`user` FROM default t UNNEST t.replies AS r WHERE r.`user` = "bcf160-000000000538”;

       

      explain SELECT t.title, r.`user` FROM default t UNNEST t.replies AS r WHERE r.`user` IN [ "bcf160-000000000538", "ccf160-000000000538" ];

      {

          "requestID": "c18df553-57f3-4aa7-901c-dcd9139df051",

          "signature": "json",

          "results": [

              {

                  "plan": {

                      "#operator": "Sequence",

                      "~children": [

                          {

                              "#operator": "DistinctScan",

                              "scan": {

                                  "#operator": "IndexScan",

                                  "covers": [

                                      "cover ((`r`.`user`))",

                                      "cover ((`t`.`title`))",

                                      "cover ((meta(`t`).`id`))"

                                  ],

                                  "index": "by_replies",

                                  "index_id": "aa6e10c282d257b6",

                                  "keyspace": "default",

                                  "namespace": "default",

                                  "spans": [

                                      {

                                          "Range": {

                                              "High": [

                                                  "\"bcf160-000000000538\""

                                              ],

                                              "Inclusion": 3,

                                              "Low": [

                                                  "\"bcf160-000000000538\""

                                              ]

                                          }

                                      },

                                      {

                                          "Range": {

                                              "High": [

                                                  "\"ccf160-000000000538\""

                                              ],

                                              "Inclusion": 3,

                                              "Low": [

                                                  "\"ccf160-000000000538\""

                                              ]

                                          }

                                      }

                                  ],

                                  "using": "gsi"

                              }

                          },

                          {

                              "#operator": "Parallel",

                              "~child": {

                                  "#operator": "Sequence",

                                  "~children": [

                                      {

                                          "#operator": "Filter",

                                          "condition": "(cover ((`r`.`user`)) in [\"bcf160-000000000538\", \"ccf160-000000000538\"])"

                                      },

                                      {

                                          "#operator": "InitialProject",

                                          "result_terms": [

                                              {

                                                  "expr": "cover ((`t`.`title`))"

                                              },

                                              {

                                                  "expr": "cover ((`r`.`user`))"

                                              }

                                          ]

                                      },

                                      {

                                          "#operator": "FinalProject"

                                      }

                                  ]

                              }

                          }

                      ]

                  },

                  "text": "SELECT t.title, r.`user` FROM default t UNNEST t.replies AS r WHERE r.`user` IN [ \"bcf160-000000000538\", \"ccf160-000000000538\" ];"

              }

          ],

          "status": "success",

          "metrics": {

              "elapsedTime": "5.339364ms",

              "executionTime": "5.319885ms",

              "resultCount": 1,

              "resultSize": 3360

          }

      }

      Attachments

        Issue Links

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

          Activity

            People

              ajay.bhullar Ajay Bhullar
              Sitaram.Vemulapalli Sitaram Vemulapalli
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  PagerDuty