SQL: a composite index on (a, b) does nothing for a query on b alone

A B-tree is sorted by the first column, then the second within it. Values of b are scattered across the whole index, so filtering on b alone cannot seek - the planner ignores the index and scans the table.

Full code & output

This topic is available to PRO members.

Open this topic Go PRO Sign in Create a free account
More in SQL

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-25

© Java Coding Hub · About · Contact · Privacy · Terms