Databases · Indexes & Query Plans
B-tree Indexes
Cheat sheet · https://pcornel.dk/topic.php?topic=6170
Answer
A B-tree index keeps keys sorted in a balanced tree so lookups, range scans and ordered reads are fast.
Remember
Composite index (a,b) helps filters on a or a+b, not b alone. Functions on columns prevent index use unless an expression index exists. Low-selectivity columns rarely benefit.
First checks
\di— first check for this topicpsql -c "SELECT now(), version();"— PostgreSQL reachable and versionmysql -e "SELECT NOW(), VERSION();"— MariaDB/MySQL reachable and versionsqlcmd -S <server> -Q "SELECT @@VERSION"— SQL Server reachable and version
Verify in this order
key → tree descent → leaf → row pointers
Where it usually breaks
Indexing low-selectivity columns (for example a boolean) rarely helps.
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6170