pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@2ndquadrant.com>
To: Kevin Grittner <kgrittn@ymail.com>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Subject: Re: brin index vacuum versus transaction snapshots
Date: Fri, 31 Jul 2015 17:51:51 -0300
Message-ID: <20150731205151.GD2441@postgresql.org> (raw)
In-Reply-To: <64199124.3265995.1438374075160.JavaMail.yahoo@mail.yahoo.com>
References: <20150731194524.GB2441@postgresql.org>
	<64199124.3265995.1438374075160.JavaMail.yahoo@mail.yahoo.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

Kevin Grittner wrote:
> Alvaro Herrera <alvherre@2ndquadrant.com> wrote:
> 
> >> I think the real solution to this problem is to avoid use of
> >> GetTransactionSnapshot(), and instead use GetLatestSnapshot().  As far
> >> as I can see, that should completely close the hole.  This requires
> >> patching IndexBuildHeapRangeScan() to allow for that.
> >
> > Actually I think there's another problem: if a transaction starts and
> > inserts a tuple into the page range, then goes to sleep, and then
> > another session does the summarization of the page range, session 1 is
> > seen as "in progress" by session 2 (so the scan does not see the new
> > tuple), but the placeholder tuple was not modified either because it was
> > inserted later than the snapshot.  So the update is lost.
> >
> > I think the only way to close this hole is to have summarize_range()
> > sleep until all open snapshots are gone after inserting the placeholder
> > tuple and before acquiring the snapshot, similarly to how CREATE INDEX
> > CONCURRENTLY does it.
> 
> Please excuse my naiveté on the topic, but could you explain (or
> point me to the documented explanation) of why we don't scan using
> a non-MVCC snapshot and build the page range based on all non-dead
> tuples?

Because I don't know of any mechanism to lock insertion into the block
range while the scan takes place.  If you can suggest something
workable, that might be better than what I'm proposing.

Note that in my proposal, we would have to wait for all snapshots to go
away *for every page range*, which seems very troublesome.  A better
answer might be to insert all placeholder tuples first, then wait for
concurrent snapshots to go away, then do each scan.  But this is a
larger rework of code.

> I understand that the range being scanned would need to be
> locked, but we're OK with doing that for creation of other indexes.

That might be so, but this is not index creation; it's not acceptable to
lock the table during vacuuming.  Do we have anything with finer
granularity than locking the entire table?  (I don't think holding
buffer lock on all the pages in the range is acceptable.)

> (There is no mention of snapshots or locks in the BRIN README....)

Um.

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



view thread (20+ messages)  latest in thread

Message-ID: <20150731205151.GD2441@postgresql.org>
Permalink:  ../20150731205151.GD2441@postgresql.org/
Also on:    postgresql.org/message-id/20150731205151.GD2441@postgresql.org

 · 

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-hackers@postgresql.org
  Cc: alvherre@2ndquadrant.com, kgrittn@ymail.com
  Subject: Re: brin index vacuum versus transaction snapshots
  In-Reply-To: <20150731205151.GD2441@postgresql.org>
  References: <20150731194524.GB2441@postgresql.org> <64199124.3265995.1438374075160.JavaMail.yahoo@mail.yahoo.com> <20150731205151.GD2441@postgresql.org>

* 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