CREATE INDEX adds a secondary data structure that speeds up ParadeDB query filtering and sorting without modifying table data.
An index stores a sorted copy of selected columns, letting the planner avoid full-table scans. ParadeDB inherits PostgreSQL’s B-tree, Hash, GiST, GIN, BRIN, and Vector methods, so you can accelerate lookups, full-text search, and embeddings.
Create indexes for columns frequently used in WHERE, JOIN, ORDER BY, or GROUP BY clauses.Avoid indexing low-cardinality flags or columns updated every row, because maintenance cost can outweigh benefit.
Use B-tree for equality and range filters on “Customers.id” or “Orders.order_date”. Choose GIN for full-text on “Products.name”, BRIN for huge append-only “OrderItems.id”, and Vector for ANN search on embeddings.
INCLUDE stores extra columns in leaf pages so queries can be completely satisfied by the index, avoiding heap access.Example: include “total_amount” when filtering by “order_date” but also selecting the amount.
Add the CONCURRENTLY keyword. ParadeDB builds the index in the background, letting inserts, updates, and deletes continue.It takes longer but avoids table-wide write locks.
The query SELECT * FROM Orders WHERE customer_id = 42 ORDER BY order_date DESC LIMIT 20;
benefits from a composite B-tree index on (customer_id, order_date DESC).
1) Name indexes clearly: idx_orders_customer_id_date
. 2) Match sort order in the index to ORDER BY direction. 3) Drop unused indexes with pg_stat_user_indexes
to save space.4) Always test with EXPLAIN
.
Each INSERT, UPDATE, or DELETE must also update every index on the table. Over-indexing slows writes and bloats storage. Monitor pg_indexes_size()
regularly.
Run EXPLAIN (ANALYZE, BUFFERS)
before and after creating the index. Look for Index Scan
or Index Only Scan
nodes referencing your new index.
.
Yes. Add a WHERE clause to index only hot rows, e.g., WHERE deleted_at IS NULL
.
No. Drop and recreate the index with the new USING clause. Use CONCURRENTLY to avoid downtime.
Single indexes can grow to terabytes. Monitor with pg_indexes_size()
and partition tables if needed.