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

[N1QL] query w/ DISTINCT was covering and pushing, now it is not

    XMLWordPrintable

Details

    • Untriaged
    • 1
    • Yes

    Description

      load travel-sample

      create index idx1 on `travel-sample`(DISTINCT ARRAY FLATTEN_KEYS(r.author,r.ratings.Cleanliness) FOR r IN reviews END, email, free_parking, type)
      SELECT MIN(r.ratings.Cleanliness), MAX(r.ratings.Cleanliness) FROM `travel-sample` AS d unnest reviews as r WHERE d.type = 'hotel' and r.author LIKE 'N%' and r.author is not missing and r.ratings.Cleanliness > 1 AND d.free_parking = False AND d.email is not missing GROUP BY r.ratings.Cleanliness"

      Previously this was covering and pushing, now it only covers but does not push

      {
          "plan": {
              "#operator": "Sequence",
              "~children": [
                  {
                      "#operator": "IndexScan3",
                      "as": "d",
                      "covers": [
                          "cover ((`r`.`author`))",
                          "cover (((`r`.`ratings`).`Cleanliness`))",
                          "cover ((`d`.`email`))",
                          "cover ((`d`.`free_parking`))",
                          "cover ((`d`.`type`))",
                          "cover ((meta(`d`).`id`))"
                      ],
                      "filter": "((cover ((`d`.`type`)) = \"hotel\") and (cover ((`d`.`free_parking`)) = false) and (cover ((`d`.`email`)) is not missing) and cover (is_array((`d`.`reviews`))))",
                      "filter_covers": {
                          "cover (((`d`.`reviews`) < {}))": true,
                          "cover (([] <= (`d`.`reviews`)))": true,
                          "cover (is_array((`d`.`reviews`)))": true
                      },
                      "index": "idx1",
                      "index_id": "c094518c5662a4c9",
                      "keyspace": "travel-sample",
                      "namespace": "default",
                      "spans": [
                          {
                              "exact": true,
                              "range": [
                                  {
                                      "high": "\"O\"",
                                      "inclusion": 1,
                                      "index_key": "(`r`.`author`)",
                                      "low": "\"N\""
                                  },
                                  {
                                      "inclusion": 0,
                                      "index_key": "((`r`.`ratings`).`Cleanliness`)",
                                      "low": "1"
                                  },
                                  {
                                      "inclusion": 1,
                                      "index_key": "`email`",
                                      "low": "null"
                                  },
                                  {
                                      "high": "false",
                                      "inclusion": 3,
                                      "index_key": "`free_parking`",
                                      "low": "false"
                                  },
                                  {
                                      "high": "\"hotel\"",
                                      "inclusion": 3,
                                      "index_key": "`type`",
                                      "low": "\"hotel\""
                                  }
                              ]
                          }
                      ],
                      "using": "gsi"
                  },
                  {
                      "#operator": "Parallel",
                      "~child": {
                          "#operator": "Sequence",
                          "~children": [
                              {
                                  "#operator": "Filter",
                                  "condition": "((cover ((`r`.`author`)) like \"N%\") and (cover ((`r`.`author`)) is not missing) and (1 < cover (((`r`.`ratings`).`Cleanliness`))))"
                              },
                              {
                                  "#operator": "InitialGroup",
                                  "aggregates": [
                                      "max(cover (((`r`.`ratings`).`Cleanliness`)))",
                                      "min(cover (((`r`.`ratings`).`Cleanliness`)))"
                                  ],
                                  "group_keys": [
                                      "cover (((`r`.`ratings`).`Cleanliness`))"
                                  ]
                              }
                          ]
                      }
                  },
                  {
                      "#operator": "IntermediateGroup",
                      "aggregates": [
                          "max(cover (((`r`.`ratings`).`Cleanliness`)))",
                          "min(cover (((`r`.`ratings`).`Cleanliness`)))"
                      ],
                      "group_keys": [
                          "cover (((`r`.`ratings`).`Cleanliness`))"
                      ]
                  },
                  {
                      "#operator": "FinalGroup",
                      "aggregates": [
                          "max(cover (((`r`.`ratings`).`Cleanliness`)))",
                          "min(cover (((`r`.`ratings`).`Cleanliness`)))"
                      ],
                      "group_keys": [
                          "cover (((`r`.`ratings`).`Cleanliness`))"
                      ]
                  },
                  {
                      "#operator": "Parallel",
                      "~child": {
                          "#operator": "Sequence",
                          "~children": [
                              {
                                  "#operator": "InitialProject",
                                  "result_terms": [
                                      {
                                          "expr": "min(cover (((`r`.`ratings`).`Cleanliness`)))"
                                      },
                                      {
                                          "expr": "max(cover (((`r`.`ratings`).`Cleanliness`)))"
                                      }
                                  ]
                              }
                          ]
                      }
                  }
              ]
          }
      }
      

      if we change DISTINCT to ALL, we see it covers AND pushes down, however for this query both indexes should be identical since it is using MIN/MAX only. This is a regression from MB-51410

      Attachments

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

        Activity

          People

            pierre.regazzoni Pierre Regazzoni
            ajay.bhullar Ajay Bhullar
            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