From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andrew Gierth <andrew@tao11.riddles.org.uk>
Cc: Amit Kapila <amit.kapila16@gmail.com>
Cc: Maksim Milyutin <milyutinma@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: Slow planning time for simple query
Date: Sun, 17 Jun 2018 10:46:08 -0400
Message-ID: <7067.1529246768@sss.pgh.pa.us> (raw)
In-Reply-To: <87po0pr97m.fsf@news-spur.riddles.org.uk>
References: <36adf760-680b-7a4a-e019-64f4eaaf6ff7@gmail.com>
<9661.1528573749@sss.pgh.pa.us>
<CAA4eK1+oP+RRG0uJSWpw=oFf3q3TPdhhRRp5byY7PSwK9H8sMw@mail.gmail.com>
<87po0pr97m.fsf@news-spur.riddles.org.uk>
[ trimming cc's ]
Andrew Gierth <andrew@tao11.riddles.org.uk> writes:
> See index_fetch_heap:
> /*
> * If we scanned a whole HOT chain and found only dead tuples, tell index
> * AM to kill its entry for that TID (this will take effect in the next
> * amgettuple call, in index_getnext_tid). We do not do this when in
> * recovery because it may violate MVCC to do so. See comments in
> * RelationGetIndexScan().
> */
> if (!scan->xactStartedInRecovery)
> scan->kill_prior_tuple = all_dead;
So the referenced comment in RelationGetIndexScan says
* During recovery we ignore killed tuples and don't bother to kill them
* either. We do this because the xmin on the primary node could easily be
* later than the xmin on the standby node, so that what the primary
* thinks is killed is supposed to be visible on standby. So for correct
* MVCC for queries during recovery we must ignore these hints and check
* all tuples. Do *not* set ignore_killed_tuples to true when running in a
* transaction that was started during recovery. xactStartedInRecovery
* should not be altered by index AMs.
but it seems to me that this is not terribly carefully thought through.
1. If global xmin on the primary is later than on the standby, VACUUM could
remove tuples that should be visible on the standby, and that would shortly
propagate to the standby. Simply ignoring index kill bits on the standby
won't prevent that.
2. Although _bt_killitems doesn't WAL-log its setting of kill bits, those
bits could propagate to the standby anyway, as a result of a subsequent
WAL action on the index page that gets a full-page image added.
I believe that in some replication modes, #1 isn't a problem because we
have mechanisms to hold back the primary's global xmin. If that's true
always, then all of this logic is obsolete silliness that we could remove.
If it's not true always, we have bigger problems to fix.
Similarly, the possibility of #2 means the standby can't trust the kill
bits to reflect its own xmin anyway. So if we aren't junking this entire
stack of logic, we could perhaps allow the standby to set kill bits per
its own understanding of global xmin, and then allow the kill bits to be
used in SnapshotNonVacuumable scans even though they're unsafe for regular
MVCC scans.
However, I'm still caffeine-short so maybe there's something I missed.
regards, tom lane
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-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, andrew@tao11.riddles.org.uk, amit.kapila16@gmail.com, milyutinma@gmail.com, pgsql-hackers@lists.postgresql.org
Subject: Re: Slow planning time for simple query
In-Reply-To: <7067.1529246768@sss.pgh.pa.us>
References: <36adf760-680b-7a4a-e019-64f4eaaf6ff7@gmail.com> <9661.1528573749@sss.pgh.pa.us> <CAA4eK1+oP+RRG0uJSWpw=oFf3q3TPdhhRRp5byY7PSwK9H8sMw@mail.gmail.com> <87po0pr97m.fsf@news-spur.riddles.org.uk> <7067.1529246768@sss.pgh.pa.us>
* 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