Covering index scan

Write codeHard30 minOracle and Microsoft style

Your task

Simulate a covering index / index-only scan. You are given an index built over columns 'index_cols' (a list of column names) holding entries, each entry a dict containing exactly those columns plus 'row_id'. You are also given a query asking for columns 'needed_cols' and a range [lo, hi] on the FIRST index column (the leading key). If every needed column is present in the index (index covers the query), answer index-only: return entries whose leading-key value is in [lo,hi], projected to needed_cols, sorted ascending by the leading key (stable on ties). If not covered, return the string 'NEEDS_HEAP_FETCH'. Return either the list of projected dicts or that string.

Examples

covering_index_scan(index_cols: list[str], entries: list[dict], needed_cols: list[str], lo: int, hi: int) -> object
Example 1
Inputcovering_index_scan(["age", "name"], [{"age": 30, "name": "a", "row_id": 1}, {"age": 25, "name": "b", "row_id": 2}, {"age": 40, "name": "c", "row_id": 3}], ["name"], 26, 40)
Output
name
a
c