18

对不起,如果这是一个愚蠢的问题,但我是否需要在每次插入行时重新索引我的表,或者新行在添加时是否被索引?

4

4 回答 4

27

手册

一旦创建了索引,就不需要进一步干预:系统会在修改表时更新索引

于 2013-07-07T07:55:25.020 回答
6

http://postgresguide.com/performance/indexes.html

我认为当您插入行时,索引确实会更新。它在您插入数据时维护索引表的排序。因此,如果您尝试一次添加大量行,则会在表上出现性能问题或停机时间。

于 2013-07-07T05:25:33.120 回答
3

除了其他答案之外:PostgreSQL 是一流的关系数据库。我不知道索引不会自动更新的任何关系数据库系统。

于 2013-07-07T11:48:48.007 回答
1

It seems to depend on the type of index. For example, according to https://www.postgresql.org/docs/9.5/brin-intro.html, for BRIN indexes:

When a new page is created that does not fall within the last summarized range, that range does not automatically acquire a summary tuple; those tuples remain unsummarized until a summarization run is invoked later, creating initial summaries. This process can be invoked manually using the brin_summarize_new_values(regclass) function, or automatically when VACUUM processes the table.

Although this seems to have changed in version 10.

于 2019-09-16T23:24:39.577 回答