pg.ddx.io pgsql-bugs@postgresql.org mailing list archivehelp / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: Manuel Rigger <rigger.manuel@gmail.com>
Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Subject: Re: REINDEX CONCURRENTLY causes ALTER TABLE to fail
Date: Thu, 18 Jul 2019 12:02:32 +0900
Message-ID: <20190718030232.GD1416@paquier.xyz> (raw)
In-Reply-To: <CA+u7OA5Hp0ra235F3czPom_FyAd-3+XwSJmX95r1+sRPOJc9VQ@mail.gmail.com>
References: <CA+u7OA5Hp0ra235F3czPom_FyAd-3+XwSJmX95r1+sRPOJc9VQ@mail.gmail.com>
On Wed, Jul 17, 2019 at 02:53:54PM +0200, Manuel Rigger wrote:
> The REINDEX TABLE CONCURRENTLY causes the ALTER TABLE to fail, which
> is unexpected. Without the CONCURRENTLY, the ALTER TABLE works as
> expected. When first executing a concurrent reindex, which is followed
> by a non-current one, the error still occurs, which might suggest that
> the concurrent reindex breaks some internal state.
Thanks. The issue comes from the handling of the collation part
within the index predicates in pg_index.indpred. I can see a slight
difference in the tree with a switch from COLLATE to REFLABEL for
example.
In your test case, if you actually remove the collation part, this
fails similarly:
=# CREATE UNIQUE INDEX i0 ON t0((1 / t0.c0)) WHERE ('-H') >=
(t0.c1::TEXT);
ERROR: 23505: could not create unique index "i0"
DETAIL: Key ((1 / c0))=(0) is duplicated.
The root of the problem comes from the fact that we rely on
BuildIndexInfo() for the index information. This uses
RelationGetIndexExpressions() to fetch the set of expressions and
RelationGetIndexPredicate() for the predicates. However, the issue is
that those routines apply some extra flattening operations for the
planner when storing this data in the relation cache, causing the
expressions stored in the catalogs for the copy to be changed. So
what we store are the expressions that the planner uses. No wonder
that this gets broken.
There are a couple of approaches that we could do to fix that. The
first one I could think about is to change the relcache level so as we
don't apply planner-level optimizations when creating a concurrent
index entry. Another one, which is less invasive, is to just update
the list of expressions and predicates after calling
BuildIndexInfo(). Still that means overriding the contents of the
relcache with what has been optimized for the planner to what we want
to use for the reindex build and I think that this weakens the logic
of index_build.
--
Michael
Attachments:
signature.asc (application/pgp-signature, 832B) download
view thread (10+ messages) latest in thread
Message-ID: <20190718030232.GD1416@paquier.xyz> Permalink: ../20190718030232.GD1416@paquier.xyz/ Also on: postgresql.org/message-id/20190718030232.GD1416@paquier.xyz ·
reply
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Reply to all the recipients from your mail client; the link fills in the headers below: reply via email Some clients, webmail especially, drop In-Reply-To and References from a link, and the reply then starts a new thread: use the mbox below. To: pgsql-bugs@postgresql.org Cc: michael@paquier.xyz, rigger.manuel@gmail.com Subject: Re: REINDEX CONCURRENTLY causes ALTER TABLE to fail In-Reply-To: <20190718030232.GD1416@paquier.xyz> References: <CA+u7OA5Hp0ra235F3czPom_FyAd-3+XwSJmX95r1+sRPOJc9VQ@mail.gmail.com> <20190718030232.GD1416@paquier.xyz> * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox