Reputation: 129
Given an SQL database with index for (startpage, endpage)
, with a relation Articles(*ID*, title, startpage, endpage)
, why isn't a query
SELECT title
FROM Articles
WHERE endpage = 100;
sped up by the previous index?
Apologies for this peculiar question as it came from a practice paper without explanation.
Upvotes: 0
Views: 334
Reputation: 562260
Why the index shown does not help that query: because endpage
is not the leftmost column of the index.
See my answer to Does Order of Fields of Multi-Column Index in MySQL Matter for more explanation (that question is about MySQL, but the answer should apply to any implementation of B-tree indexes).
Upvotes: 3