A composite index can support an access path without containing every query predicate in its seek prefix. It becomes a covering plan only when the index also stores every column the query must filter or return.
Design an IndexAccessPlanAnalyzer class:
IndexAccessPlanAnalyzer() creates a stateless analyzer.String classify(String[] indexColumns, String[] equalityColumns, String rangeColumn, String[] selectedColumns) returns "unusable", "seek", or "covering".
Apply these rules:
- Starting at the left of
indexColumns, consume consecutive columns present in equalityColumns. - The single
rangeColumn, when non-empty, can extend the access prefix only if it is the next index column. - If no column was consumed, return
"unusable". - Otherwise, return
"covering" when the index contains every equality column, the non-empty range column, and every selected column. Return "seek" when any required column is absent.
The query may evaluate a stored predicate as a residual filter even when it lies after a prefix gap. Such a column can contribute to coverage but not extend the seek prefix.
Example 1:
Input:
Output:
Explanation: The index supports the equality-plus-range access path and contains the selected status column.
Example 2:
Input:
Output:
Explanation: The access prefix is usable, but payload must be fetched from the table.
Constraints
1 <= indexColumns.length <= 10^5- Column names in each input array are unique lowercase strings.
rangeColumn is empty or differs from every equality column.- At most
100 calls are made to classify.