{"by":"kiwicopple","descendants":97,"id":40028111,"kids":[40028894,40031524,40028694,40029226,40029335,40029004,40029409,40060222,40029971,40031713,40029276,40028821,40028879,40030302,40029209,40031943,40031774,40031306,40029083,40032061,40028112,40030132],"score":417,"text":"This is a Postgres extension that can determine if a query should have an index. For example, for this table:<p><pre><code>    create table book(\n      id int primary key,\n      title text not null\n    );\n</code></pre>\nYou can run `index_advisor()` to see if there should be an index on a select statement:<p><pre><code>    select *\n    from index_advisor(&#x27;select book.id from book where title = $1&#x27;);\n</code></pre>\nAnd it will return (summarized):<p><pre><code>    {&quot;CREATE INDEX ON public.book USING btree (title)&quot;}\n</code></pre>\nIt works particularly well with pg_stat_statements[0] which tracks execution statistics of all SQL statements executed on your Postgres database.<p>It leans heavily on HypoPG[1], an excellent extension to determine if PostgreSQL will use a given index without spending resources to create them.<p>[0] pg_stat_statements: <a href=\"https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;pgstatstatements.html\" rel=\"nofollow\">https:&#x2F;&#x2F;www.postgresql.org&#x2F;docs&#x2F;current&#x2F;pgstatstatements.htm...</a><p>[1] <a href=\"https:&#x2F;&#x2F;github.com&#x2F;HypoPG&#x2F;hypopg\">https:&#x2F;&#x2F;github.com&#x2F;HypoPG&#x2F;hypopg</a>","time":1713060876,"title":"Show HN: PostgreSQL index advisor","type":"story","url":"https://github.com/supabase/index_advisor"}