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

Missing index_group_aggs for array unnest aggregate query

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • Critical
    • 7.1.0
    • 7.1.0
    • query
    • 7.1.0-2506
    • Untriaged
    • 1
    • Yes

    Description

      To repro:

      • create default bucket
      • create index ix3 on default(ALL DISTINCT ARRAY a.y FOR a IN arr END DESC )
      • EXPLAIN SELECT COUNT(DISTINCT a.y) FROM default d UNNEST d.arr As a WHERE a.y = 10;

      on 7.1.0-2506, there is no index_group_aggs:

      cbq> EXPLAIN SELECT COUNT(DISTINCT a.y) FROM default d UNNEST d.arr As a WHERE a.y = 10 ;
      {
          "requestID": "86fe2a35-6154-41e3-91e2-1e52766ee73b",
          "signature": "json",
          "results": [
          {
              "plan": {
                  "#operator": "Sequence",
                  "~children": [
                      {
                          "#operator": "IndexScan3",
                          "as": "d",
                          "covers": [
                              "cover ((`a`.`y`))",
                              "cover ((meta(`d`).`id`))"
                          ],
                          "filter": "cover (is_array((`d`.`arr`)))",
                          "filter_covers": {
                              "cover (((`d`.`arr`) \u003c {}))": true,
                              "cover (([] \u003c= (`d`.`arr`)))": true,
                              "cover (is_array((`d`.`arr`)))": true
                          },
                          "index": "ix3",
                          "index_id": "ae7f453dbcdfa33d",
                          "keyspace": "default",
                          "namespace": "default",
                          "spans": [
                              {
                                  "exact": true,
                                  "range": [
                                      {
                                          "high": "10",
                                          "inclusion": 3,
                                          "index_key": "(distinct (array (`a`.`y`) for `a` in `arr` end))",
                                          "low": "10"
                                      }
                                  ]
                              }
                          ],
                          "using": "gsi"
                      },
                      {
                          "#operator": "Parallel",
                          "~child": {
                              "#operator": "Sequence",
                              "~children": [
                                  {
                                      "#operator": "Filter",
                                      "condition": "(cover ((`a`.`y`)) = 10)"
                                  },
                                  {
                                      "#operator": "InitialGroup",
                                      "aggregates": [
                                          "count(DISTINCT cover ((`a`.`y`)))"
                                      ],
                                      "group_keys": []
                                  }
                              ]
                          }
                      },
                      {
                          "#operator": "IntermediateGroup",
                          "aggregates": [
                              "count(DISTINCT cover ((`a`.`y`)))"
                          ],
                          "group_keys": []
                      },
                      {
                          "#operator": "FinalGroup",
                          "aggregates": [
                              "count(DISTINCT cover ((`a`.`y`)))"
                          ],
                          "group_keys": []
                      },
                      {
                          "#operator": "Parallel",
                          "~child": {
                              "#operator": "Sequence",
                              "~children": [
                                  {
                                      "#operator": "InitialProject",
                                      "result_terms": [
                                          {
                                              "expr": "count(DISTINCT cover ((`a`.`y`)))"
                                          }
                                      ]
                                  }
                              ]
                          }
                      }
                  ]
              },
              "text": "SELECT COUNT(DISTINCT a.y) FROM default d UNNEST d.arr As a WHERE a.y = 10;"
          }
          ],
          "status": "success",
          "metrics": {
              "elapsedTime": "5.064429ms",
              "executionTime": "4.852417ms",
              "resultCount": 1,
              "resultSize": 3406,
              "serviceLoad": 6
          }
      }
       
       

      on 7.10-2475, previous behavior uses index_group_aggs:

       cbq> EXPLAIN SELECT COUNT(DISTINCT a.y) FROM default d UNNEST d.arr As a WHERE a.y = 10;
      {
          "requestID": "b980490e-12f6-4e8a-9746-4733f4dbbb8f",
          "signature": "json",
          "results": [
          {
              "plan": {
                  "#operator": "Sequence",
                  "~children": [
                      {
                          "#operator": "IndexScan3",
                          "as": "d",
                          "covers": [
                              "cover ((`a`.`y`))",
                              "cover ((meta(`d`).`id`))",
                              "cover (count(DISTINCT cover ((`a`.`y`))))"
                          ],
                          "filter_covers": {
                              "cover (((`d`.`arr`) \u003c {}))": true,
                              "cover (([] \u003c= (`d`.`arr`)))": true,
                              "cover (is_array((`d`.`arr`)))": true
                          },
                          "index": "ix3",
                          "index_group_aggs": {
                              "aggregates": [
                                  {
                                      "aggregate": "COUNT",
                                      "depends": [
                                          0
                                      ],
                                      "distinct": true,
                                      "expr": "cover ((`a`.`y`))",
                                      "id": 2,
                                      "keypos": 0
                                  }
                              ],
                              "depends": [
                                  0
                              ]
                          },
                          "index_id": "9e54031d106585a",
                          "index_projection": {
                              "entry_keys": [
                                  2
                              ]
                          },
                          "keyspace": "default",
                          "namespace": "default",
                          "spans": [
                              {
                                  "exact": true,
                                  "range": [
                                      {
                                          "high": "10",
                                          "inclusion": 3,
                                          "index_key": "(distinct (array (`a`.`y`) for `a` in `arr` end))",
                                          "low": "10"
                                      }
                                  ]
                              }
                          ],
                          "using": "gsi"
                      },
                      {
                          "#operator": "Parallel",
                          "~child": {
                              "#operator": "Sequence",
                              "~children": [
                                  {
                                      "#operator": "InitialProject",
                                      "result_terms": [
                                          {
                                              "expr": "cover (count(DISTINCT cover ((`a`.`y`))))"
                                          }
                                      ]
                                  }
                              ]
                          }
                      }
                  ]
              },
              "text": "SELECT COUNT(DISTINCT a.y) FROM default d UNNEST d.arr As a WHERE a.y = 10;"
          }
          ],
          "status": "success",
          "metrics": {
              "elapsedTime": "5.108762ms",
              "executionTime": "4.895672ms",
              "resultCount": 1,
              "resultSize": 2983,
              "serviceLoad": 6
          }
      }
       
      
      

      This might be related to MB-51531

      Attachments

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

        Activity

          People

            pierre.regazzoni Pierre Regazzoni
            pierre.regazzoni Pierre Regazzoni
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty