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.
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?
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?
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?
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.