Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardSQLindex-only scansSingle-choice MCQ

A B-tree index exists on (a). A query is SELECT a FROM t WHERE a > 0 ORDER BY a. The planner could do an index-only scan. Now you add a WHERE clause referencing a column NOT in the index: WHERE a > 0 AND b = 5. Even though only column a is selected, the plan switches to a regular Index Scan with heap access. What is the precise internal reason an index-only scan becomes impossible here?

-- index: CREATE INDEX ON t (a); SELECT a FROM t WHERE a > 0 AND b = 5;