Cost-based optimizer choice

Write codeHard30 minOracle and Snowflake style

Your task

A cost-based optimizer must pick between two access paths for a selection. You are given table_rows (int row count), a 'selectivity' float in [0,1] (fraction of rows matching the predicate), and a 'has_index' bool. The full scan costs table_rows (one unit per row read). The index path, available only if has_index is true, costs 3 (index descent) plus 5 * (matched rows), where matched rows = round(table_rows * selectivity) using Python's round. Return the string 'index' if the index path exists and its cost is strictly less than the scan cost, otherwise 'scan'. Also return the chosen cost. Return [choice, cost].

Examples

choose_access_path(table_rows: int, selectivity: float, has_index: bool) -> list
Example 1
Inputchoose_access_path(1000, 0.01, True)
Output["index", 53]