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

[BP to 7.1.5 MB-56284] - Wrong results when filter has conditional query parameters

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Critical
    • 7.1.5
    • 7.1.4
    • query
    • 1

    Description

      Issue Resolution
      Incorrect results were returned when a filter contained conditional query parameters. This issue was due to a problem in an OR clause that depended on a named parameter and not a document. Constant filters in the subterms of the OR clause are now detected and marked. The extra check prevents index aggregation pushdown. For classifying expressions, when there is an OR clause under an AND, processing removes any constant subterms.

      create index ix1 on default(c1,c2);
       
      upsert into default values ("k01",{"c1":1, "c2":5});
      select count(1) FROM default AS d WHERE d.c1 = 1 AND ((d.c2 = 6 AND IFMISSINGORNULL(1,"") != "" ) OR IFMISSINGORNULL(1,"") = "");
       
      --gives 0  correct answer
      select count(1) FROM default AS d WHERE d.c1 = 1 AND ((d.c2 = 6 AND IFMISSINGORNULL($qp1,"") != "" ) OR IFMISSINGORNULL($qp1,"") = "");
       
      -- gives 1 wrong answer it not even depends on $qp1 no complain because it used index aggregates the spans not exact
       
      explain select count(1) FROM default AS d WHERE d.c1 = 1 AND ((d.c2 = 6 AND IFMISSINGORNULL($qp1,"") != "" ) OR IFMISSINGORNULL($qp1,"") = "");
       
       
      {
          "requestID": "367dbde2-d3f3-4365-a518-696f5826ba14",
          "signature": "json",
          "results": [
          {
              "plan": {
                  "#operator": "Sequence",
                  "~children": [
                      {
                          "#operator": "IndexScan3",
                          "as": "d",
                          "covers": [
                              "cover ((`d`.`c1`))",
                              "cover ((`d`.`c2`))",
                              "cover ((meta(`d`).`id`))",
                              "cover (count(1))"
                          ],
                          "index": "ix1",
                         "index_group_aggs": {
                              "aggregates": [
                                  {
                                      "aggregate": "COUNT",
                                      "expr": "1",
                                      "id": 3,
                                      "keypos": -1
                                  }
                              ]
                          },
                          "index_id": "f8939e87c23640f4",
                          "index_projection": {
                              "entry_keys": [
                                  3
                              ]
                          },
                          "keyspace": "default",
                          "namespace": "default",
                          "spans": [
                              {
                                  "exact": true,
                                  "range": [
                                      {
                                          "high": "1",
                                          "inclusion": 3,
                                          "low": "1"
                                      },
                                      {
                                          "high": "6",
       
                                       "inclusion": 3,
                                          "low": "6"
                                      }
                                  ]
                              },
                              {
                                  "exact": true,
                                  "range": [
                                      {
                                          "high": "1",
                                          "inclusion": 3,
                                          "low": "1"
                                      }
                                  ]
                              }
                          ],
                          "using": "gsi"
                      },
                      {
                          "#operator": "Parallel",
                          "~child": {
                              "#operator": "Sequence",
                              "~children": [
                                  {
                                      "#operator": "InitialProject",
                                      "result_terms": [
                                          {
                                              "expr": "cover (count(1))"
                                          }
                         }
                                      ]
                                  }
                              ]
                          }
                      }
                  ]
              },
              "text": "select count(1) FROM default AS d WHERE d.c1 = 1 AND ((d.c2 = 6 AND IFMISSINGORNULL($qp1,\"\") != \"\" ) OR IFMISSINGORNULL($qp1,\"\") = \"\");"
          }
          ],
          "status": "success",
          "metrics": {
              "elapsedTime": "2.715615ms",
              "executionTime": "2.527752ms",
              "resultCount": 1,
              "resultSize": 3011,
              "serviceLoad": 3
          }
      }
      

      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
              bingjie.miao Bingjie Miao
              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