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

[GSI] array index with flatten_keys and when clause skips some documents, leads to incorrect query results

    XMLWordPrintable

Details

    • Untriaged
    • 1
    • No

    Description

      I have a single node cluster with kv,n1ql,index services a bucket named default with the backup data that is attached inside of it.

      I create this index

      CREATE INDEX `idx2` ON `default`(`country`,(distinct (array flatten_keys((`r`.`author`), ((`r`.`ratings`).`Cleanliness`)) for `r` in `reviews` when (((`r`.`ratings`).`Cleanliness`) < 3) end)),`email`,`free_parking`)

      I see in the logs this error message
      Index entries were skipped in index: idx2, bucket: default, IndexInstId: 3759883280083208803 PartitionId: 0 due to errors. Please check indexer logs for more details.

      Looking deeper into the indexer logs I see these
      2021-10-21T01:52:44.963-07:00 [Error] plasmaSlice::insertSecArrayIndex SliceId 0 IndexInstId 3759883280083208803 PartitionId 0 Error in creating compostite new secondary keys. Skipping docid:<ud>(doc_13771)</ud> Error: not an array
      2021-10-21T01:52:44.963-07:00 [Error] plasmaSlice::insertSecArrayIndex SliceId 0 IndexInstId 3759883280083208803 PartitionId 0 Error in creating compostite new secondary keys. Skipping docid:<ud>(doc_15333)</ud> Error: not an array
      2021-10-21T01:52:44.964-07:00 [Error] plasmaSlice::insertSecArrayIndex SliceId 0 IndexInstId 3759883280083208803 PartitionId 0 Error in creating compostite new secondary keys. Skipping docid:<ud>(doc_16409)</ud> Error: not an array
      2021-10-21T01:52:44.965-07:00 [Error] plasmaSlice::insertSecArrayIndex SliceId 0 IndexInstId 3759883280083208803 PartitionId 0 Error in creating compostite new secondary keys. Skipping docid:<ud>(doc_11361)</ud> Error: not an array
      2021-10-21T01:52:44.966-07:00 [Error] plasmaSlice::insertSecArrayIndex SliceId 0 IndexInstId 3759883280083208803 PartitionId 0 Error in creating compostite new secondary keys. Skipping docid:<ud>(doc_15764)</ud> Error: not an array
      2021-10-21T01:52:44.966-07:00 [Error] plasmaSlice::insertSecArrayIndex SliceId 0 IndexInstId 3759883280083208803 PartitionId 0 Error in creating compostite new secondary keys. Skipping docid:<ud>(doc_17158)</ud> Error: not an array
      2021-10-21T01:52:44.967-07:00 [Error] plasmaSlice::insertSecArrayIndex SliceId 0 IndexInstId 3759883280083208803 PartitionId 0 Error in creating compostite new secondary keys. Skipping docid:<ud>(doc_13801)</ud> Error: not an array
      2021-10-21T01:52:44.968-07:00 [Error] plasmaSlice::insertSecArrayIndex SliceId 0 IndexInstId 3759883280083208803 PartitionId 0 Error in creating compostite new secondary keys. Skipping docid:<ud>(doc_17766)</ud> Error: not an array
      2021-10-21T01:52:44.968-07:00 [Error] plasmaSlice::insertSecArrayIndex SliceId 0 IndexInstId 3759883280083208803 PartitionId 0 Error in creating compostite new secondary keys. Skipping docid:<ud>(doc_17331)</ud> Error: not an array
      2021-10-21T01:52:44.969-07:00 [Error] plasmaSlice::insertSecArrayIndex SliceId 0 IndexInstId 3759883280083208803 PartitionId 0 Error in creating compostite new secondary keys. Skipping docid:<ud>(doc_15404)</ud> Error: not an array
      2021-10-21T01:52:44.969-07:00 [Error] plasmaSlice::insertSecArrayIndex SliceId 0 IndexInstId 3759883280083208803 PartitionId 0 Error in creating compostite new secondary keys. Skipping docid:<ud>(doc_18002)</ud> Error: not an array

      These errors cause this query to fail:
      SELECT *
      FROM default AS d
      WHERE ANY r IN d.reviews SATISFIES CONTAINS(r.author,'M')
      AND r.ratings.Cleanliness = 4 END
      AND free_parking = TRUE
      AND country IS NOT NULL

      1430 docs returned w/flatten_keys, however if we run against primary index it returns 1568 docs and if we create an array index without flatten_keys that does the same as above, we also get 1568 docs back. Logs and backup attached

      here is doc 15404 and doc 18002 (two of the docs that were skipped)

      doc_18002
      {
        "country": "Guinea",
        "address": "75598 Jast Forge",
        "free_parking": true,
        "city": "South Kemberlybury",
        "type": "Suites",
        "url": "www.adria-wiza.name",
        "reviews": [
          {
            "date": "2021-10-21 01:42:02",
            "author": "Clyde Larson",
            "ratings": {
              "Value": 1,
              "Cleanliness": 4,
              "Overall": 4,
              "Check in / front desk": 2,
              "Rooms": 1
            }
          },
          {
            "date": "2021-10-28 01:42:02",
            "author": "Fredric Welch",
            "ratings": {
              "Value": 2,
              "Cleanliness": 4,
              "Overall": 4,
              "Check in / front desk": 4,
              "Rooms": 2
            }
          }
        ],
        "phone": "(955) 070-5027",
        "price": 830,
        "avg_rating": 1,
        "free_breakfast": false,
        "name": "Olivia Howe Suites",
        "public_likes": [
          "Corrine Jakubowski PhD",
          "Ayesha Feeney MD",
          "Mohammad Carroll",
          "Mike Romaguera",
          "Earl Paucek",
          "Nelda Luettgen"
        ],
        "email": null
      }
       
      doc_15404
      {
        "country": "Guernsey",
        "address": "7907 Schroeder Path",
        "free_parking": false,
        "city": "Beattyhaven",
        "type": "Hostel",
        "url": "www.dorsey-connelly.com",
        "reviews": [
          {
            "date": "2021-10-21 01:42:01",
            "author": "German Paucek",
            "ratings": {
              "Value": 4,
              "Cleanliness": 4,
              "Overall": 2,
              "Check in / front desk": 3,
              "Rooms": 1
            }
          },
          {
            "date": "2021-10-28 01:42:01",
            "author": "Florencio Senger",
            "ratings": {
              "Value": 4,
              "Cleanliness": 4,
              "Overall": 1,
              "Check in / front desk": 1,
              "Rooms": 2
            }
          },
          {
            "date": "2021-11-04 01:42:01",
            "author": "Wai Ledner",
            "ratings": {
              "Value": 1,
              "Cleanliness": 4,
              "Overall": 1,
              "Check in / front desk": 3,
              "Rooms": 2
            }
          },
          {
            "date": "2021-11-11 01:42:01",
            "author": "Geoffrey Walter",
            "ratings": {
              "Value": 3,
              "Cleanliness": 4,
              "Overall": 4,
              "Check in / front desk": 4,
              "Rooms": 1
            }
          }
        ],
        "phone": "865.359.1559 x221",
        "price": 1189,
        "avg_rating": 1,
        "free_breakfast": true,
        "name": "Lu Kunde Hostel",
        "public_likes": [
          "Dr. Kareem Reinger"
        ],
        "email": "Kunde.Lu@hotels.com"
      }
      

      explain plan of query:

      {
          "#operator": "Sequence",
          "~children": [
              {
                  "#operator": "DistinctScan",
                  "scan": {
                      "#operator": "IndexScan3",
                      "as": "d",
                      "index": "idx2",
                      "index_id": "7dc48a04c2457351",
                      "index_projection": {
                          "primary_key": true
                      },
                      "keyspace": "default",
                      "namespace": "default",
                      "spans": [
                          {
                              "exact": true,
                              "range": [
                                  {
                                      "inclusion": 0,
                                      "index_key": "`country`",
                                      "low": "null"
                                  },
                                  {
                                      "inclusion": 0,
                                      "index_key": "(`r`.`author`)"
                                  },
                                  {
                                      "inclusion": 0,
                                      "index_key": "((`r`.`ratings`).`Cleanliness`)"
                                  },
                                  {
                                      "inclusion": 0,
                                      "index_key": "`email`"
                                  },
                                  {
                                      "high": "true",
                                      "inclusion": 3,
                                      "index_key": "`free_parking`",
                                      "low": "true"
                                  }
                              ]
                          }
                      ],
                      "using": "gsi"
                  }
              },
              {
                  "#operator": "Fetch",
                  "as": "d",
                  "keyspace": "default",
                  "namespace": "default"
              },
              {
                  "#operator": "Parallel",
                  "~child": {
                      "#operator": "Sequence",
                      "~children": [
                          {
                              "#operator": "Filter",
                              "condition": "(any `r` in (`d`.`reviews`) satisfies (contains((`r`.`author`), \"M\") and (((`r`.`ratings`).`Cleanliness`) = 4)) end and ((`d`.`free_parking`) = true) and ((`d`.`country`) is not null))"
                          },
                          {
                              "#operator": "InitialProject",
                              "result_terms": [
                                  {
                                      "expr": "self",
                                      "star": true
                                  }
                              ]
                          }
                      ]
                  }
              }
          ]
      }
      

      Attachments

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

        Activity

          People

            ajay.bhullar Ajay Bhullar
            ajay.bhullar Ajay Bhullar
            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