Yes, because that composite index in your example is also known as a covering index. Specifically mentioned in the previously linked documentation here:
...people sometimes made covering indexes by writing the payload columns as ordinary index columns, that is writing
CREATE INDEX tab_x_y ON tab(x, y);
even though they had no intention of ever using y as part of a WHERE clause. This works fine as long as the extra columns are trailing columns...
Basically, as long as the fields of your predicates are all sequentially part of the index definition (from left to right), then that index is covering and applicable to be used for that query.
The reverse of your example would not work though since the index does not cover that scenario. I.e. WHERE colB = 'someValue'
is not covered by an index with the definition of (colA, colB)
since the order of the field list in the index definition literally defines the structure of the underlying B-Tree used to sort the data. So first the data is sorted on colA
and then colB
, making it not possible to directly search on colB
(aka directly seek on colB
, rather an index scan could still be performed to indirectly search on colB
) without a predicate to search on colA
first.