Home > OS >  Does postgresql update index even when the updated columns aren't the indexed ones?
Does postgresql update index even when the updated columns aren't the indexed ones?

Time:03-26

I want to index an array column with either GIN or GiST. The fact that GIN is slower in insert/update operations, however, made me wonder if it would have any impact on performance - even though the indexed column itself will remain static. So, assuming that, for instance, I have a table with columns (A, B, C) and that B is indexed, does the index get updated if I update only column C?

CodePudding user response:

It depends :^)

Normally, PostgreSQL will have to modify the index, even if nothing changes in the indexed column, because an UPDATE in PostgreSQL creates a new row version, so you need a new index entry to point to the new location of the row in the table.

Since this is unfortunate, there is an optimization called “HOT update”: If none of the indexed columns are modified and there is enough free space in the block that contains the original row, PostgreSQL can create a “heap-only tuple” that is not referenced from the outside and therefore does not require a new index entry.

You can lower the fillfactor on the table to increase the likelihood for HOT updates.

For details, you may want to read my article on the topic.

  • Related