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

[N1QL] query using primary returns incorrect results, the query using a gsi index returns the correct results

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Critical
    • 5.5.0
    • 5.5.0
    • secondary-index
    • 5.5.0-2250 (observed in 2211 as well)
    • Untriaged
    • Yes

    Description

      This query:

      select join_day from default where meta().id = "query-testemployee10231.2819054-0" OR meta().id > "" OR meta().id < "query-testemployee10317.9004497-0" order by meta().id

      returns every document in the bucket, however when it is forced to use the primary index:

      select join_day from default use index(`#primary`) where meta().id = "query-testemployee10231.2819054-0" OR meta().id > "" OR meta().id < "query-testemployee10317.9004497-0" order by meta().id

       

      It returns only 24 results with the primary index (I will attach a backup of my data). There are three indexes in my cluster

      primary index

      idx1 - default(join_day)

      idx2 - default(meta().id)

       

      Here is the explain for the query w/o using primary

      select join_day from default where meta().id = "query-testemployee10231.2819054-0" OR meta().id > "" OR meta().id < "query-testemployee10317.9004497-0" order by meta().id

      {
      "plan": {
      "#operator": "Sequence",
      "~children": [
      {
      "#operator": "Sequence",
      "~children": [
      {
      "#operator": "IndexScan3",
      "index": "idx2",
      "index_id": "530546c94156848d",
      "index_order": [
      {
      "keypos": 0
      }
      ],
      "index_projection": {
      "primary_key": true
      },
      "keyspace": "default",
      "namespace": "default",
      "spans": [
      {
      "exact": true,
      "range": [
      {
      "high": "\"query-testemployee10231.2819054-0\"",
      "inclusion": 3,
      "low": "\"query-testemployee10231.2819054-0\""
      }
      ]
      },
      {
      "exact": true,
      "range": [
      {
      "inclusion": 0,
      "low": "\"\""
      }
      ]
      },
      {
      "exact": true,
      "range": [
      {
      "high": "\"query-testemployee10317.9004497-0\"",
      "inclusion": 0,
      "low": "null"
      }
      ]
      }
      ],
      "using": "gsi"
      },
      {
      "#operator": "Fetch",
      "keyspace": "default",
      "namespace": "default"
      },
      {
      "#operator": "Parallel",
      "maxParallelism": 1,
      "~child": {
      "#operator": "Sequence",
      "~children": [
      {
      "#operator": "Filter",
      "condition": "((((meta(`default`).`id`) = \"query-testemployee10231.2819054-0\") or (\"\" < (meta(`default`).`id`))) or ((meta(`default`).`id`) < \"query-testemployee10317.9004497-0\"))"
      },
      {
      "#operator": "InitialProject",
      "result_terms": [
      {
      "expr": "(`default`.`join_day`)"
      }
      ]
      },
      {
      "#operator": "FinalProject"
      }
      ]
      }
      }
      ]
      }
      ]
      },
      "text": "select join_day from default where meta().id = \"query-testemployee10231.2819054-0\" OR meta().id > \"\" OR meta().id < \"query-testemployee10317.9004497-0\" order by meta().id"
      }

       

      Here is the explain for the query using primary:

      select join_day from default use index(`#primary`) where meta().id = "query-testemployee10231.2819054-0" OR meta().id > "" OR meta().id < "query-testemployee10317.9004497-0" order by meta().id

      {
      "plan": {
      "#operator": "Sequence",
      "~children": [
      {
      "#operator": "Sequence",
      "~children": [
      {
      "#operator": "IndexScan3",
      "index": "#primary",
      "index_id": "ee93633af7be7570",
      "index_order": [
      {
      "keypos": 0
      }
      ],
      "keyspace": "default",
      "namespace": "default",
      "spans": [
      {
      "exact": true,
      "range": [
      {
      "high": "\"query-testemployee10231.2819054-0\"",
      "inclusion": 3,
      "low": "\"query-testemployee10231.2819054-0\""
      }
      ]
      },
      {
      "exact": true,
      "range": [
      {
      "inclusion": 0,
      "low": "\"\""
      }
      ]
      },
      {
      "exact": true,
      "range": [
      {
      "high": "\"query-testemployee10317.9004497-0\"",
      "inclusion": 0,
      "low": "null"
      }
      ]
      }
      ],
      "using": "gsi"
      },
      {
      "#operator": "Fetch",
      "keyspace": "default",
      "namespace": "default"
      },
      {
      "#operator": "Parallel",
      "maxParallelism": 1,
      "~child": {
      "#operator": "Sequence",
      "~children": [
      {
      "#operator": "Filter",
      "condition": "((((meta(`default`).`id`) = \"query-testemployee10231.2819054-0\") or (\"\" < (meta(`default`).`id`))) or ((meta(`default`).`id`) < \"query-testemployee10317.9004497-0\"))"
      },
      {
      "#operator": "InitialProject",
      "result_terms": [
      {
      "expr": "(`default`.`join_day`)"
      }
      ]
      },
      {
      "#operator": "FinalProject"
      }
      ]
      }
      }
      ]
      }
      ]
      },
      "text": "select join_day from default use index(`#primary`) where meta().id = \"query-testemployee10231.2819054-0\" OR meta().id > \"\" OR meta().id < \"query-testemployee10317.9004497-0\" order by meta().id"
      }

       

      Logs and backup attached

      To restore from backup please create an repo with the same name as the file included:

      ./cbbackupmgr config --archive /data/backups --repo <name of file>

      Then move the file attached into this archive

      Then restore(must have empty buckets of the same name in your cluster, in this case just a bucket named default):

      ./cbbackupmgr restore --archive /data/backups --repo <name of file> --cluster http://127.0.0.1:8091 --username Administrator --password password

      Attachments

        Activity

          People

            prathibha Prathibha Bisarahalli (Inactive)
            ajay.bhullar Ajay Bhullar
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              PagerDuty