pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Robert Haas <rhaas@postgresql.org>
To: pgsql-committers@postgresql.org
Subject: pgsql: Improve hash index bucket split behavior.
Date: Wed, 30 Nov 2016 20:43:41 +0000
Message-ID: <E1cCBjB-00035U-71@gemulon.postgresql.org> (raw)
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-committers>

Improve hash index bucket split behavior.

Previously, the right to split a bucket was represented by a
heavyweight lock on the page number of the primary bucket page.
Unfortunately, this meant that every scan needed to take a heavyweight
lock on that bucket also, which was bad for concurrency.  Instead, use
a cleanup lock on the primary bucket page to indicate the right to
begin a split, so that scans only need to retain a pin on that page,
which is they would have to acquire anyway, and which is also much
cheaper.

In addition to reducing the locking cost, this also avoids locking out
scans and inserts for the entire lifetime of the split: while the new
bucket is being populated with copies of the appropriate tuples from
the old bucket, scans and inserts can happen in parallel.  There are
minor concurrency improvements for vacuum operations as well, though
the situation there is still far from ideal.

This patch also removes the unworldly assumption that a split will
never be interrupted.  With the new code, a split is done in a series
of small steps and the system can pick up where it left off if it is
interrupted prior to completion.  While this patch does not itself add
write-ahead logging for hash indexes, it is clearly a necessary first
step, since one of the things that could interrupt a split is the
removal of electrical power from the machine performing it.

Amit Kapila.  I wrote the original design on which this patch is
based, and did a good bit of work on the comments and README through
multiple rounds of review, but all of the code is Amit's.  Also
reviewed by Jesper Pedersen, Jeff Janes, and others.

Discussion: http://postgr.es/m/CAA4eK1LfzcZYxLoXS874Ad0+S-ZM60U9bwcyiUZx9mHZ-KCWhw@mail.gmail.com

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/6d46f4783efe457f74816a75173eb23ed8930020

Modified Files
--------------
src/backend/access/hash/Makefile      |   4 +-
src/backend/access/hash/README        | 311 +++++++++++---------
src/backend/access/hash/hash.c        | 350 +++++++++++++++-------
src/backend/access/hash/hashinsert.c  |  86 ++++--
src/backend/access/hash/hashovfl.c    | 154 ++++++----
src/backend/access/hash/hashpage.c    | 527 +++++++++++++++++++++++++++-------
src/backend/access/hash/hashscan.c    | 153 ----------
src/backend/access/hash/hashsearch.c  | 225 +++++++++++++--
src/backend/access/hash/hashutil.c    |  94 ++++++
src/backend/utils/resowner/resowner.c |   3 -
src/include/access/hash.h             |  82 ++++--
src/include/access/itup.h             |   2 +-
12 files changed, 1365 insertions(+), 626 deletions(-)


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


Message-ID: <E1cCBjB-00035U-71@gemulon.postgresql.org>
Permalink:  ../E1cCBjB-00035U-71@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1cCBjB-00035U-71@gemulon.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-committers@postgresql.org
  Cc: rhaas@postgresql.org
  Subject: Re: pgsql: Improve hash index bucket split behavior.
  In-Reply-To: <E1cCBjB-00035U-71@gemulon.postgresql.org>
  References: <E1cCBjB-00035U-71@gemulon.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