Re: REINDEX CONCURRENTLY unexpectedly fails

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Michael Paquier <michael(at)paquier(dot)xyz>, Andres Freund <andres(at)anarazel(dot)de>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Manuel Rigger <rigger(dot)manuel(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: REINDEX CONCURRENTLY unexpectedly fails
Date: 2020-01-07 15:33:23
Message-ID: 8f0bde7b-2d96-fb5c-cd0e-553694c1d376@iki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 23/12/2019 03:59, Michael Paquier wrote:
> +/*
> + * RelationSupportsConcurrentIndexing
> + *
> + * Check if a relation supports concurrent builds or not. This is
> + * used as a sanity check prior processing CREATE INDEX, DROP INDEX
> + * or REINDEX when using CONCURRENTLY.
> + */
> +bool
> +RelationSupportsConcurrentIndexing(char relpersistence)
> +{
> + /*
> + * Build indexes non-concurrently for temporary relations. Such
> + * relations only work with the session assigned to them, so they are
> + * not subject to concurrent concerns, and a concurrent build would
> + * cause issues with ON COMMIT actions triggered by the transactions
> + * of the concurrent build. A non-concurrent reindex is also more
> + * efficient in this case.
> + */
> + if (relpersistence == RELPERSISTENCE_TEMP)
> + return false;
> +
> + return true;
> +}
> +

The comment says "this is used as a sanity check". "Sanity check"
implies that it should never happen, but it is perfectly normal for it
to return false.

The caller in DefineIndex() calls RelationSupportsConcurrentIndexing()
only after choosing the lock mode. That's fine for temporary tables, but
if wouldn't work right if RelationSupportsConcurrentIndexing() started
to return false for some other tables. Maybe it would be clearer to just
check "relpersistence == RELPERSISTENCE_TEMP" directly in the callers,
and not have the RelationSupportsConcurrentIndexing() function.

The new text in drop_index.sgml talks about index creation, copy-pasted
from create_index.sgml.

- Heikki

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Robert Haas 2020-01-07 15:59:22 Re: Assert failure due to "drop schema pg_temp_3 cascade" for temporary tables and \d+ is not showing any info after drooping temp table schema
Previous Message Tom Lane 2020-01-07 15:08:07 Re: BUG #16122: segfault pg_detoast_datum (datum=0x0) at fmgr.c:1833 numrange query