Skip to content
Advertisement

Do EXTENDED STATISTICS have any influence on INSERT/UPDATE/DELETE in PostgreSQL?

Obviously correctly created extended statistics can have some effect on how effectively does the query planner evaluate SELECT queries when some mutualy dependant data is being selected, but do they have any influence to operation like INSERT, UPDATE and DELETE to tables that have any EXTENDED STATISTICS defined on any of its columns?

Advertisement

Answer

UPDATE and DELETE are affected because, like SELECT, you specify the conditions for rows which should be updated/deleted. The planner will then build a query plan to find those rows, same as SELECT, relying on the same statistics information.

The behavior of INSERT, and the writing-new-row-versions part of UPDATE, are not affected by statistics. They both behave in the same, deterministic way: they insert their row version into the first available data page that has sufficient free space to hold the row, which is found using the free space map.

See https://github.com/postgres/postgres/blob/master/src/backend/storage/freespace/README for more information about how the free space map and how PG determines where to write a new row version.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement