Preserve index data in pg_statistic across REINDEX CONCURRENTLY
authorMichael Paquier <michael@paquier.xyz>
Sun, 1 Nov 2020 12:22:07 +0000 (21:22 +0900)
committerMichael Paquier <michael@paquier.xyz>
Sun, 1 Nov 2020 12:22:07 +0000 (21:22 +0900)
commitb17ff07aa3eb142d2cde2ea00e4a4e8f63686f96
tree4a0e8b7b6f6584f0776963da80f072b4b7249363
parentaecaa04418f39c32adb3dbf91c4aa7f6e175f01c
Preserve index data in pg_statistic across REINDEX CONCURRENTLY

Statistics associated to an index got lost after running REINDEX
CONCURRENTLY, while the non-concurrent case preserves these correctly.
The concurrent and non-concurrent operations need to be consistent for
the end-user, and missing statistics would force to wait for a new
analyze to happen, which could take some time depending on the activity
of the existing autovacuum workers.  This issue is fixed by copying any
existing entries in pg_statistic associated to the old index to the new
one.  Note that this copy is already done with the data of the index in
the stats collector.

Reported-by: Fabrízio de Royes Mello
Author: Michael Paquier, Fabrízio de Royes Mello
Reviewed-by: Justin Pryzby
Discussion: https://postgr.es/m/CAFcNs+qpFPmiHd1oTXvcPdvAHicJDA9qBUSujgAhUMJyUMb+SA@mail.gmail.com
Backpatch-through: 12
src/backend/catalog/heap.c
src/backend/catalog/index.c
src/include/catalog/heap.h
src/test/regress/expected/create_index.out
src/test/regress/sql/create_index.sql