Covering index not working

n1ql
#1

I have the following query:

SELECT META().id _ID, META().cas _CAS,
    a, b, c,
    d, e,
    f, g
  FROM myBucket
  WHERE documentType = "myDocType"
    AND d IS NOT NULL

And I created this index:

CREATE INDEX abc ON myBucket(META().id, META().cas,
          a, b, c,
          d, e,
          f, g, documentType)

But when I run an EXPLAIN the index is not taken into account. I tried with USE INDEX and no effect either.

What am I missing? What are the general rules to define a covering index? (Note: My project uses v4.1).

#2

Does it work if you remove META().id and META().cas from both the index and the query?

#3

I tried and it doesn’t work either.

#4

Ok, now I see one problem. Please move documentType and d to the beginning of the index.

#5

Thanks! It worked both adding and not adding the cas and id to the index. I decided to keep the version including cas and id

1 Like