(评论)
(comments)

原始链接: https://news.ycombinator.com/item?id=40028111

这是一个 Postgres 扩展,可以确定查询是否应该有索引。 例如,对于此表: create table book( id int Primary Key, title text not null ); 您可以运行“index_advisor()”来查看 select 语句上是否应该有索引: select * from index_advisor('select book.id from book where title = $1'); 它将返回(总结): {"CREATE INDEX ON public.book USING btree (title)"} 它与 pg_stat_statements[0] 配合得特别好,它跟踪在 Postgres 数据库上执行的所有 SQL 语句的执行统计信息。它很大程度上依赖于 HypoPG[1],一个优秀的扩展,用于确定 PostgreSQL 是否将使用给定索引而不花费资源来创建它们。[0] pg_stat_statements:https://www.postgresql.org/docs/current/pgstatstatements.htm...[1] https://github.com/HypoPG/hypopg

相关文章

原文
This 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

联系我们 contact @ memedata.com