pgsql: Cache hash index's metapage in rel->rd_amcache.

From: Robert Haas <rhaas(at)postgresql(dot)org>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Cache hash index's metapage in rel->rd_amcache.
Date: 2017-02-07 17:40:39
Message-ID: E1cb9kt-0001DY-Ax@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Cache hash index's metapage in rel->rd_amcache.

This avoids a very significant amount of buffer manager traffic and
contention when scanning hash indexes, because it's no longer
necessary to lock and pin the metapage for every scan. We do need
some way of figuring out when the cache is too stale to use any more,
so that when we lock the primary bucket page to which the cached
metapage points us, we can tell whether a split has occurred since we
cached the metapage data. To do that, we use the hash_prevblkno field
in the primary bucket page, which would otherwise always be set to
InvalidBuffer.

This patch contains code so that it will continue working (although
less efficiently) with hash indexes built before this change, but
perhaps we should consider bumping the hash version and ripping out
the compatibility code. That decision can be made later, though.

Mithun Cy, reviewed by Jesper Pedersen, Amit Kapila, and by me.
Before committing, I made a number of cosmetic changes to the last
posted version of the patch, adjusted _hash_getcachedmetap to be more
careful about order of operation, and made some necessary updates to
the pageinspect documentation and regression tests.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/293e24e507838733aba4748b514536af2d39d7f2

Modified Files
--------------
contrib/pageinspect/expected/hash.out | 8 +-
doc/src/sgml/pageinspect.sgml | 2 +-
src/backend/access/hash/README | 68 ++++++++++-----
src/backend/access/hash/hash.c | 59 +++++++------
src/backend/access/hash/hashinsert.c | 83 ++++---------------
src/backend/access/hash/hashpage.c | 151 +++++++++++++++++++++++++++++++++-
src/backend/access/hash/hashsearch.c | 69 +++-------------
src/include/access/hash.h | 20 ++++-
8 files changed, 279 insertions(+), 181 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Pavan Deolasee 2017-02-07 18:00:50 Re: [COMMITTERS] pgsql: Release note updates.
Previous Message Alvaro Herrera 2017-02-07 15:59:31 Re: [COMMITTERS] pgsql: Release note updates.