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

Selecting only meta().id returns empty result under primary index

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Critical
    • 4.5.0
    • 4.5.0
    • query
    • 4.5.0-1994
    • Untriaged
    • Unknown

    Description

      Hi,

      while working on the YCSB optimizations, I found some very weird behavior in combination with only selecting the meta().id and having it in the where clause.

      For some context, I have the primary index created on the default bucket and exactly one document with the key "foo" and the content is

      {"bar": "baz"}

      So the following query does not return anything:

      SELECT meta().id as id FROM `default` WHERE meta().id >= 'foo' LIMIT 10;
      

      {
          "requestID": "b9a2e7c2-be5c-4fde-aea2-52a8980cc20a",
          "signature": {
              "id": "json"
          },
          "results": [
          ],
          "status": "success",
          "metrics": {
              "elapsedTime": "4.134321ms",
              "executionTime": "4.094911ms",
              "resultCount": 0,
              "resultSize": 0
          }
      }
      

      Now if I remove either the where clause (or replace it with a WHERE 1=1, so the meta().id does not come up in the where clause) OR I add some other field to the select part (*, abc, whatever) it returns the correct result:

      cbq> SELECT meta().id as id, * FROM `default` WHERE meta().id >= 'foo' LIMIT 10;
      {
          "requestID": "89bf9c29-7530-4091-9799-32e7f127f1cf",
          "signature": {
              "*": "*",
              "id": "json"
          },
          "results": [
              {
                  "default": {
                      "bar": "baz"
                  },
                  "id": "foo"
              }
          ],
          "status": "success",
          "metrics": {
              "elapsedTime": "5.122042ms",
              "executionTime": "5.08547ms",
              "resultCount": 1,
              "resultSize": 104
          }
      }
       
      cbq> SELECT meta().id as id FROM `default` LIMIT 10;
      {
          "requestID": "aca691fb-fc68-4477-a474-2baddfac8114",
          "signature": {
              "id": "json"
          },
          "results": [
              {
                  "id": "foo"
              }
          ],
          "status": "success",
          "metrics": {
              "elapsedTime": "7.229889ms",
              "executionTime": "7.193382ms",
              "resultCount": 1,
              "resultSize": 35
          }
      }
      

      Looks like a bug to me? Here is the explain for the broken query, maybe it is a bug in the covered index?

      cbq> explain SELECT meta().id as id FROM `default` WHERE meta().id >= 'foo' LIMIT 10;
      {
          "requestID": "40980ff8-0ee3-47ab-8b74-229945a8820a",
          "signature": "json",
          "results": [
              {
                  "plan": {
                      "#operator": "Sequence",
                      "~children": [
                          {
                              "#operator": "Sequence",
                              "~children": [
                                  {
                                      "#operator": "IndexScan",
                                      "covers": [
                                          "cover ((meta(`default`).`id`))"
                                      ],
                                      "index": "#primary",
                                      "index_id": "2a543447b261f63f",
                                      "keyspace": "default",
                                      "limit": "10",
                                      "namespace": "default",
                                      "spans": [
                                          {
                                              "Range": {
                                                  "Inclusion": 1,
                                                  "Low": [
                                                      "\"foo\""
                                                  ]
                                              }
                                          }
                                      ],
                                      "using": "gsi"
                                  },
                                  {
                                      "#operator": "Parallel",
                                      "~child": {
                                          "#operator": "Sequence",
                                          "~children": [
                                              {
                                                  "#operator": "Filter",
                                                  "condition": "(\"foo\" \u003c= cover ((meta(`default`).`id`)))"
                                              },
                                              {
                                                  "#operator": "InitialProject",
                                                  "result_terms": [
                                                      {
                                                          "as": "id",
                                                          "expr": "cover ((meta(`default`).`id`))"
                                                      }
                                                  ]
                                              },
                                              {
                                                  "#operator": "FinalProject"
                                              }
                                          ]
                                      }
                                  }
                              ]
                          },
                          {
                              "#operator": "Limit",
                              "expr": "10"
                          }
                      ]
                  },
                  "text": "SELECT meta().id as id FROM `default` WHERE meta().id \u003e= 'foo' LIMIT 10"
              }
          ],
          "status": "success",
          "metrics": {
              "elapsedTime": "3.646887ms",
              "executionTime": "3.61492ms",
              "resultCount": 1,
              "resultSize": 2862
          }
      }
      

      One more observation is that specifying only "meta()" also works:

      cbq> SELECT meta() FROM `default` WHERE meta().id >= 'foo' LIMIT 10;
      {
          "requestID": "4042a422-4bd2-490e-8d79-876b16220b47",
          "signature": {
              "$1": "object"
          },
          "results": [
              {
                  "$1": {
                      "cas": 408901317885952,
                      "flags": 0,
                      "id": "foo",
                      "type": "json"
                  }
              }
          ],
          "status": "success",
          "metrics": {
              "elapsedTime": "4.393678ms",
              "executionTime": "4.358975ms",
              "resultCount": 1,
              "resultSize": 173
          }
      }
      

      Attachments

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

        Activity

          People

            Sitaram.Vemulapalli Sitaram Vemulapalli
            daschl Michael Nitschinger
            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