Improve checking for pg_index.xmin

From: Alexander Korotkov <a(dot)korotkov(at)postgrespro(dot)ru>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Improve checking for pg_index.xmin
Date: 2019-10-31 23:50:39
Message-ID: CAPpHfduk5Kh1bF9-8Xovgq78k9LyRUodFsfbmSAFuA_5kwbCPA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi!

Our customer faced with issue, when index is invisible after creation.
The reproducible case is following.

$ psql db2
# begin;
# select txid_current();
$ psql db1
# select i as id, 0 as v into t from generate_series(1, 100000) i;
# create unique index idx on t (id);
# update t set v = v + 1 where id = 10000;
# update t set v = v + 1 where id = 10000;
# update t set v = v + 1 where id = 10000;
# update t set v = v + 1 where id = 10000;
# update t set v = v + 1 where id = 10000;
# drop index idx;
# create unique index idx on t (id);
# explain analyze select v from t where id = 10000;

There is no issue if there is no parallel session in database db2.
The fact that index visibility depends on open transaction in
different database is ridiculous for users.

This happens so, because we're checking that there is no broken HOT
chains after index creation by comparison pg_index.xmin and
TransactionXmin. So, we check that pg_index.xmin is in the past for
current transaction in lossy way by comparison just xmins. Attached
patch changes this check to XidInMVCCSnapshot().

With patch the issue is gone. My doubt about this patch is that it
changes check with TransactionXmin to check with GetActiveSnapshot(),
which might be more recent. However, query shouldn't be executer with
older snapshot than one it was planned with.

Any thoughts?

------
Alexander Korotkov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

Attachment Content-Type Size
0001-improve-check-for-pg_index-xmin.patch application/octet-stream 1.9 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2019-10-31 23:54:41 Allow 'sslkey' and 'sslcert' in postgres_fdw user mappings
Previous Message Andres Freund 2019-10-31 23:43:02 Re: merging HashJoin and Hash nodes