Re: remove spurious CREATE INDEX CONCURRENTLY wait

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, James Coleman <jtc331(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: remove spurious CREATE INDEX CONCURRENTLY wait
Date: 2020-11-26 19:56:15
Message-ID: 20201126195615.GA1176@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

So let's discuss the next step in this series: what to do about REINDEX

I started with Dmitry's patch (an updated version of which I already
posted in [1]). However, Dmitry missed (and I hadn't noticed) that some
of the per-index loops are starting transactions also, and that we need
to set the flag in those. And what's more, in a couple of the
function-scope transactions we do set the flag pointlessly: the
transactions there do not acquire a snapshot, so there's no reason to
set the flag at all, because WaitForOlderSnapshots ignores sessions
whose Xmin is 0.

There are also transactions that wait first, without setting a snapshot,
and then do some catalog manipulations. I think it's prett much useless
to set the flag for those, because they're going to be very short
anyway. (There's also one case of this in CREATE INDEX CONCURRENTLY.)

But there's a more interesting point also. In Dmitry's patch, we
determine safety for *all* indexes being processed as a set, and then
apply the flag only if they're all deemed safe. But we can optimize
this, and set the flag for each index' transaction individually, and
only skip it for those specific indexes that are unsafe. So I propose
to change the data structure used in ReindexRelationConcurrently from
the current list of OIDs to a list of (oid,boolean) pairs, to be able to
track setting the flag individually.

There's one more useful observation: in the function-scope transactions
(outside the per-index loops), we don't touch the contents of any
indexes; we just wait or do some catalog manipulation. So we can set
the flag *regardless of the safety of any indexes*. We only need to
care about the safety of the indexes in the phases where we build the
indexes and when we validate them.


In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2020-11-26 20:59:20 Re: [PoC] Non-volatile WAL buffer
Previous Message Tomas Vondra 2020-11-26 19:34:04 Re: POC: postgres_fdw insert batching