Re: When creating index, why pointing to old version of tuple - Mailing list pgsql-hackers

From Tom Lane
Subject Re: When creating index, why pointing to old version of tuple
Date
Msg-id 2262188.1754058131@sss.pgh.pa.us
Whole thread Raw
In response to When creating index, why pointing to old version of tuple  (Chao Li <li.evan.chao@gmail.com>)
List pgsql-hackers
Chao Li <li.evan.chao@gmail.com> writes:
> I understand that, for updated tuples, old version's ctid points to new
> version, that builds a chain of all versions. But my confusion is that,
> when an index is created, older transactions and in-progress transactions
> won't see the newly created index.

I think this misunderstanding is the root of your confusion.  Yes,
transactions with older snapshots can see and use such an index.
In fact, they *must* see it, because they had better update it
if they make any new insertions in the table.

This means that index creation has to index any row version that
is even potentially still-visible to any open transaction.

Moreover, since our tracking of visibility is approximate (OldestXmin
certainly doesn't capture everything), that will result in sometimes
indexing things that an omniscient observer could know aren't visible
to any remaining transaction.  I'm not sure if that applies to your
test case, but maybe it does, depending on what else was happening in
the system.

Also, there are a bunch of edge cases concerning HOT updates, which
are described in src/backend/access/heap/README.HOT.  I'm not
sure whether your test case is affected by those rules, but
that could be an independent reason for index entries that
point somewhere other than where you expected.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: Enhance pg_createsubscriber to create required standby.
Next
From: Tom Lane
Date:
Subject: Re: C11 / VS 2019