Обсуждение: Patch: VACUUM should ignore (CREATE |RE)INDEX CONCURRENTLY for xmin horizon calculations
Patch: VACUUM should ignore (CREATE |RE)INDEX CONCURRENTLY for xmin horizon calculations
От
Hannu Krosing
Дата:
When VACUUM decides which rows are safe to freeze or permanently remove it currently ignores backends which have PROC_IN_VACUUM or PROC_IN_LOGICAL_DECODING bits set. This patch adds PROC_IN_SAFE_IC to this set, so backends running CREATE INDEX CONCURRENTLY or REINDEX CONCURRENTLY and where the index is "simple" - i.e. not expression indexes or conditional indexes are involved - these would be ignored too. The reasoning behind this is simple: 1) Why this is safe: a) The vacuum operation can not run on the same table that vacuum is working on because of locks. b) The CIC operation only runs on a single table in one transaction, so it can not touch other tables 2) Why this is useful: CIC can take significant amount of time, and in case of high-traffic database with vacuum cleanups blocked a significant amount of dead rows can accumulate which can have significant impact on certain workloads. The worst affected are the ones that are considered anti-patterns anyway, like updatein a single counter row from all DML, but this can work "well enough" if all the DML transactions are tiny and and the performance can be maintained between vacuum runs by just setting the deleted flags in indexes and heap which currentlyis also blocke. Future improvements It would be good to do some more introspection to determine if the CIC skipping is also safe for specifioc cases of expression and conditional indexes which are currently excluded from setting the PROC_IN_SAFE_IC flag. --- Hannu
Вложения
Re: Patch: VACUUM should ignore (CREATE |RE)INDEX CONCURRENTLY for xmin horizon calculations
От
Peter Geoghegan
Дата:
On Mon, Nov 24, 2025 at 4:18 PM Hannu Krosing <hannuk@google.com> wrote: > When VACUUM decides which rows are safe to freeze or permanently > remove it currently ignores backends which have PROC_IN_VACUUM or > PROC_IN_LOGICAL_DECODING bits set. > > This patch adds PROC_IN_SAFE_IC to this set, so backends running > CREATE INDEX CONCURRENTLY or REINDEX CONCURRENTLY and where the index > is "simple" - i.e. not expression indexes or conditional indexes are > involved - these would be ignored too. Are you aware of commit d9d076222f5b? It was subsequently reverted by commit e28bb885 because it led to subtle data corruption. Indexes had wrong contents due to an unforeseen interaction with pruning. -- Peter Geoghegan
On Tue, Nov 25, 2025 at 3:39 AM Peter Geoghegan <pg@bowt.ie> wrote: > > On Mon, Nov 24, 2025 at 4:18 PM Hannu Krosing <hannuk@google.com> wrote: > > When VACUUM decides which rows are safe to freeze or permanently > > remove it currently ignores backends which have PROC_IN_VACUUM or > > PROC_IN_LOGICAL_DECODING bits set. > > > > This patch adds PROC_IN_SAFE_IC to this set, so backends running > > CREATE INDEX CONCURRENTLY or REINDEX CONCURRENTLY and where the index > > is "simple" - i.e. not expression indexes or conditional indexes are > > involved - these would be ignored too. > > Are you aware of commit d9d076222f5b? It was subsequently reverted by > commit e28bb885 because it led to subtle data corruption. Indexes had > wrong contents due to an unforeseen interaction with pruning. Interesting, so although it's not a problem for the vacuum itself, vacuum would move the xmin forward and that will allow other backends to hot prune the tuples from the table needed by the index building snapshot. -- Regards, Dilip Kumar Google
Re: Patch: VACUUM should ignore (CREATE |RE)INDEX CONCURRENTLY for xmin horizon calculations
От
Matthias van de Meent
Дата:
On Mon, 24 Nov 2025 at 23:09, Peter Geoghegan <pg@bowt.ie> wrote: > > On Mon, Nov 24, 2025 at 4:18 PM Hannu Krosing <hannuk@google.com> wrote: > > When VACUUM decides which rows are safe to freeze or permanently > > remove it currently ignores backends which have PROC_IN_VACUUM or > > PROC_IN_LOGICAL_DECODING bits set. > > > > This patch adds PROC_IN_SAFE_IC to this set, so backends running > > CREATE INDEX CONCURRENTLY or REINDEX CONCURRENTLY and where the index > > is "simple" - i.e. not expression indexes or conditional indexes are > > involved - these would be ignored too. > > Are you aware of commit d9d076222f5b? It was subsequently reverted by > commit e28bb885 because it led to subtle data corruption. Indexes had > wrong contents due to an unforeseen interaction with pruning. Indeed, I don't think this is a correct change, given that these visibility horizons are calculated in every backend, and are also used for pruning. On-access pruning is one case where this is used and which would break - exactly the issue that caused d9d076222f5b to be reverted in e28bb885. Kind regards, Matthias van de Meent Databricks (https://www.databricks.com)