AlgoMaster Logo
AlgoMasterClassify a Composite Index Planhard

Classify a Composite Index Plan

hard

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:

  1. Starting at the left of indexColumns, consume consecutive columns present in equalityColumns.
  2. The single rangeColumn, when non-empty, can extend the access prefix only if it is the next index column.
  3. If no column was consumed, return "unusable".
  4. 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.
Hints

Loading...
CallReturns
new IndexAccessPlanAnalyzer()null
classify(["tenant","created","status"], ["tenant"], "created", ["status"])"covering"

Tenant supplies the leading equality prefix, created is the next range column, and every predicate and selected column is stored in the index.

Run checks these cases. Submit also runs a larger hidden set.