Covering Index clarification

Hi All,
According to this article on covering indexes https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/covering-indexes.html covered indexes never use data service.

Isn’t the index service returns only the document ids even when covered index is used so that query service has to consult the data service to fetch the actual document data to sent out to the client?

In uncovered scenario only additional step is after documents are fetched from data service additional processing is done by query service to filter out uncovered fields by index?

Please clarify.

Thanks,
Isuru

All the required information of query (query block) is available in single index, it is called covered index. Query avoids Fetching the document from data service. Index service can return the document keys, index keys.

https://blog.couchbase.com/n1ql-practical-guide-second-edition/ DESIGNING INDEX FOR QUERY IN
COUCHBASE N1QL

@vsr1
Yes all the required information to fetch the docids are at covered index.But Isn’t the query service has to make a roundtrip to data service to fetch full document details as per client requirement regardless of covered or uncovered situation?
Thanks
Isuru

covered means docid + fields , that query no longer covered and that index will not be called covered index for that query. Even predicate is part of the index. (If Fetch involved, it is not covered query).

Ok lets say my document D has 4 fields (a,b,c,d) in Bucket test

And I have a Query as "SELECT * from test WHERE _class=‘com.test.D’ AND a=? AND b=?

Then I ll have GSI
CREATE INDEX test ON test(_class,a,b) WHERE _class=‘com.test.D’ USING GSI

I am considering this as a covered index. But I did not specify in the index to store all the fields.
So even you did not specify fields to be stored as values in index does it store all fields in the index node by default?

If so why uncovered scenario needs to consult data service?

Thanks
Isuru

CREATE INDEX test ON test (a,b) WHERE _class=‘com.test.D’ USING GSI;

SELECT a,b, META().id from test WHERE _class=‘com.test.D’ AND a=? AND b=?
Query uses any combination of _class, a, b, META().id and choose above index it avoids Fetch because index has all the information that query needed.

SELECT a,b, META().id, c from test WHERE _class=‘com.test.D’ AND a=? AND b=?

Above query the index doesn’t have c when choose above index it required Fetch. * means all fields, It must Fetch the document even index explicitly included all the fields.

So covered index definition would be “coverage of all search fields” not the “coverage of both search fields and results fields” implies needing to contact data service when additional fields in the index are fetched?
Or
covered index definition is “coverage of both search fields and results field by the index without consulting data service”?

Any field referenced in the query. Assume above query c can be present in predicate, projection, group, aggregation, order by. As Index doesn’t have information of c it must fetch the document and see if it present inside the document. Otherwise it result in wrong results.

Ok lets avoid talking definitions and focus on how it works .

Thanks @vsr1 for the clarifications.