• Robert Haas's avatar
    Cache hash index's metapage in rel->rd_amcache. · 293e24e5
    Robert Haas authored
    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.
    293e24e5
hashpage.c 40.7 KB