B-tree index: The default, general-purpose index. Balanced tree that supports equality and range queries and ORDER BY. A B-tree index is the default index type in most relational databases. It keeps values sorted in a balanced tree, so the database can find a row in a few steps instead of reading the whole table.
It supports exact matches, ranges and sorting. A query like WHERE created_at > '2026-01-01' ORDER BY created_at can use a B-tree index on created_at for both the filter and the order.
What should you keep in mind with B-tree index?
The column order in a composite index matters. An index on (customer_id, created_at) helps queries that filter on customer_id, but not queries that only filter on created_at. Every index also slows down writes a little and uses disk space. Add indexes for the queries you actually run, and use EXPLAIN to check that the database uses them.
What does an example of B-tree index look like?
CREATE INDEX idx_orders_created ON orders (created_at);
Master SQL query optimization, indexing strategies, and EXPLAIN analysis to dramatically improve database performance and eliminate slow queries. Use when debugging slow queries, designing database schemas, or optimizing application performance.
Postgres best practices maintained by Supabase, for Postgres running anywhere. Load this skill BEFORE writing or changing anything that lives in a Postgres database: creating or altering tables and columns (including choosing column types), schema design, migrations and declarative schema files, RLS policies and the tests that verify them, indexes, triggers, database functions, queues and schedule