Show HN: PostgreSQL index advisor (opens in a new tab)github.com
417 pointsThis is a Postgres extension that can determine if a query should have an index. For example, for this table:
create table book(
id int primary key,
title text not null
);
You can run `index_advisor()` to see if there should be an index on a select statement: select *
from index_advisor('select book.id from book where title = $1');
And it will return (summarized): {"CREATE INDEX ON public.book USING btree (title)"}
It works particularly well with pg_stat_statements[0] which tracks execution statistics of all SQL statements executed on your Postgres database.It leans heavily on HypoPG[1], an excellent extension to determine if PostgreSQL will use a given index without spending resources to create them.
[0] pg_stat_statements: https://www.postgresql.org/docs/current/pgstatstatements.htm...
[1] https://github.com/HypoPG/hypopg
Comments (97) 22 threads
Earlier comments1. Enable hypopg
2. Copy/paste the plpgsql file:https://github.com/supabase/index_advisor/blob/main/index_ad...
We are also developing the Trusted Language Extension with the RDS team, so at some point it should be easier to do this through database.dev:
https://database.dev/olirice/index_advisor
All comments shown.
Couldn't load more comments. Check your connection and try again.