pg.ddx.io  pgsql-patches@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Zdenek Kotala <Zdenek.Kotala@Sun.COM>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Alex Hunsaker <badalex@gmail.com>
Cc: Xiao Meng <mx.cogito@gmail.com>
Cc: pgsql-patches@postgresql.org, "Jonah H. Harris" <jonah.harris@gmail.com>
Subject: Re: hash index improving v3
Date: Mon, 08 Sep 2008 16:20:15 +0200
Message-ID: <48C5349F.4080300@sun.com> (raw)
In-Reply-To: <22574.1220728178@sss.pgh.pa.us>
References: <ded849dd0808171846g2c6c65adub942bd2510a6c94f@mail.gmail.com>
	<7627.1220569888@sss.pgh.pa.us>
	<34d269d40809041742r6a0703dbgfbdd012f7f19de2e@mail.gmail.com>
	<10995.1220577198@sss.pgh.pa.us>
	<11525.1220579153@sss.pgh.pa.us>
	<34d269d40809041854g355a8f68ga3a037a69e3d9fcb@mail.gmail.com>
	<11962.1220581027@sss.pgh.pa.us>
	<34d269d40809042048m3b532a5ej7a9588f63a788d0c@mail.gmail.com>
	<34d269d40809050912u33f2afc8mb90e316bc465136e@mail.gmail.com>
	<34d269d40809051321w2ed16037od0373a4a29c311f1@mail.gmail.com>
	<34d269d40809052249h59750f83v4b19a50d0555580@mail.gmail.com>
	<22574.1220728178@sss.pgh.pa.us>

Tom Lane napsal(a):
> "Alex Hunsaker" <badalex@gmail.com> writes:
>> On Fri, Sep 5, 2008 at 2:21 PM, Alex Hunsaker <badalex@gmail.com> wrote:
>>> Ok now that I made it so it actually *test* collisions, with the patch
>>> it always returns all rows that matched the hashed "key".
> 
>> And here is the fix, we just forget to set the recheck flag for bitmap scans.
> 
> For the convenience of anyone intending to test, here is an updated
> patch against CVS HEAD that incorporates Alex's fix.
> 

Tom,
I attach cleanup patch which we discussed last commit fest. It introduce new 
macros HashGetMetaPage and HashGetBitmap and of course, it break backward on 
disk format compatibility which we will break it anyway when Xiao's patch will 
be committed.

		Zdenek



-- 
Zdenek Kotala              Sun Microsystems
Prague, Czech Republic     http://sun.com/postgresql

Attachments:

hash_cleanup.patch (text/x-diff, 9.1K) download běžné podadresáře: pgsql_hash.be486df40421/src a pgsql_hash/src běžné podadresáře: pgsql_hash.be486df40421/src/backend a pgsql_hash/src/backend běžné podadresáře: pgsql_hash.be486df40421/src/include a pgsql_hash/src/include běžné podadresáře: pgsql_hash.be486df40421/src/backend/access a pgsql_hash/src/backend/access běžné podadresáře: pgsql_hash.be486df40421/src/backend/access/hash a pgsql_hash/src/backend/access/hash diff -rc pgsql_hash.be486df40421/src/backend/access/hash/hash.c pgsql_hash/src/backend/access/hash/hash.c *** pgsql_hash.be486df40421/src/backend/access/hash/hash.c po zář 8 16:14:00 2008 --- pgsql_hash/src/backend/access/hash/hash.c po zář 8 16:14:00 2008 *************** *** 527,533 **** * each bucket. */ metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_READ, LH_META_PAGE); ! metap = (HashMetaPage) BufferGetPage(metabuf); orig_maxbucket = metap->hashm_maxbucket; orig_ntuples = metap->hashm_ntuples; memcpy(&local_metapage, metap, sizeof(local_metapage)); --- 527,533 ---- * each bucket. */ metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_READ, LH_META_PAGE); ! metap = HashPageGetMeta(BufferGetPage(metabuf)); orig_maxbucket = metap->hashm_maxbucket; orig_ntuples = metap->hashm_ntuples; memcpy(&local_metapage, metap, sizeof(local_metapage)); *************** *** 629,635 **** /* Write-lock metapage and check for split since we started */ metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_WRITE, LH_META_PAGE); ! metap = (HashMetaPage) BufferGetPage(metabuf); if (cur_maxbucket != metap->hashm_maxbucket) { --- 629,635 ---- /* Write-lock metapage and check for split since we started */ metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_WRITE, LH_META_PAGE); ! metap = HashPageGetMeta(BufferGetPage(metabuf)); if (cur_maxbucket != metap->hashm_maxbucket) { diff -rc pgsql_hash.be486df40421/src/backend/access/hash/hashinsert.c pgsql_hash/src/backend/access/hash/hashinsert.c *** pgsql_hash.be486df40421/src/backend/access/hash/hashinsert.c po zář 8 16:14:00 2008 --- pgsql_hash/src/backend/access/hash/hashinsert.c po zář 8 16:14:00 2008 *************** *** 69,75 **** /* Read the metapage */ metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_READ, LH_META_PAGE); ! metap = (HashMetaPage) BufferGetPage(metabuf); /* * Check whether the item can fit on a hash page at all. (Eventually, we --- 69,75 ---- /* Read the metapage */ metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_READ, LH_META_PAGE); ! metap = HashPageGetMeta(BufferGetPage(metabuf)); /* * Check whether the item can fit on a hash page at all. (Eventually, we diff -rc pgsql_hash.be486df40421/src/backend/access/hash/hashovfl.c pgsql_hash/src/backend/access/hash/hashovfl.c *** pgsql_hash.be486df40421/src/backend/access/hash/hashovfl.c po zář 8 16:14:00 2008 --- pgsql_hash/src/backend/access/hash/hashovfl.c po zář 8 16:14:00 2008 *************** *** 187,193 **** _hash_chgbufaccess(rel, metabuf, HASH_NOLOCK, HASH_WRITE); _hash_checkpage(rel, metabuf, LH_META_PAGE); ! metap = (HashMetaPage) BufferGetPage(metabuf); /* start search at hashm_firstfree */ orig_firstfree = metap->hashm_firstfree; --- 187,193 ---- _hash_chgbufaccess(rel, metabuf, HASH_NOLOCK, HASH_WRITE); _hash_checkpage(rel, metabuf, LH_META_PAGE); ! metap = HashPageGetMeta(BufferGetPage(metabuf)); /* start search at hashm_firstfree */ orig_firstfree = metap->hashm_firstfree; *************** *** 450,456 **** /* Read the metapage so we can determine which bitmap page to use */ metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_READ, LH_META_PAGE); ! metap = (HashMetaPage) BufferGetPage(metabuf); /* Identify which bit to set */ ovflbitno = blkno_to_bitno(metap, ovflblkno); --- 450,456 ---- /* Read the metapage so we can determine which bitmap page to use */ metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_READ, LH_META_PAGE); ! metap = HashPageGetMeta(BufferGetPage(metabuf)); /* Identify which bit to set */ ovflbitno = blkno_to_bitno(metap, ovflblkno); diff -rc pgsql_hash.be486df40421/src/backend/access/hash/hashpage.c pgsql_hash/src/backend/access/hash/hashpage.c *** pgsql_hash.be486df40421/src/backend/access/hash/hashpage.c po zář 8 16:14:00 2008 --- pgsql_hash/src/backend/access/hash/hashpage.c po zář 8 16:14:00 2008 *************** *** 395,401 **** pageopaque->hasho_flag = LH_META_PAGE; pageopaque->hasho_page_id = HASHO_PAGE_ID; ! metap = (HashMetaPage) pg; metap->hashm_magic = HASH_MAGIC; metap->hashm_version = HASH_VERSION; --- 395,401 ---- pageopaque->hasho_flag = LH_META_PAGE; pageopaque->hasho_page_id = HASHO_PAGE_ID; ! metap = HashPageGetMeta(pg); metap->hashm_magic = HASH_MAGIC; metap->hashm_version = HASH_VERSION; *************** *** 402,414 **** metap->hashm_ntuples = 0; metap->hashm_nmaps = 0; metap->hashm_ffactor = ffactor; ! metap->hashm_bsize = BufferGetPageSize(metabuf); /* find largest bitmap array size that will fit in page size */ for (i = _hash_log2(metap->hashm_bsize); i > 0; --i) { ! if ((1 << i) <= (metap->hashm_bsize - ! (MAXALIGN(sizeof(PageHeaderData)) + ! MAXALIGN(sizeof(HashPageOpaqueData))))) break; } Assert(i > 0); --- 402,412 ---- metap->hashm_ntuples = 0; metap->hashm_nmaps = 0; metap->hashm_ffactor = ffactor; ! metap->hashm_bsize = HashGetMaxBitmapSize(pg); /* find largest bitmap array size that will fit in page size */ for (i = _hash_log2(metap->hashm_bsize); i > 0; --i) { ! if ((1 << i) <= metap->hashm_bsize) break; } Assert(i > 0); *************** *** 532,538 **** _hash_chgbufaccess(rel, metabuf, HASH_NOLOCK, HASH_WRITE); _hash_checkpage(rel, metabuf, LH_META_PAGE); ! metap = (HashMetaPage) BufferGetPage(metabuf); /* * Check to see if split is still needed; someone else might have already --- 530,536 ---- _hash_chgbufaccess(rel, metabuf, HASH_NOLOCK, HASH_WRITE); _hash_checkpage(rel, metabuf, LH_META_PAGE); ! metap = HashPageGetMeta(BufferGetPage(metabuf)); /* * Check to see if split is still needed; someone else might have already diff -rc pgsql_hash.be486df40421/src/backend/access/hash/hashsearch.c pgsql_hash/src/backend/access/hash/hashsearch.c *** pgsql_hash.be486df40421/src/backend/access/hash/hashsearch.c po zář 8 16:14:00 2008 --- pgsql_hash/src/backend/access/hash/hashsearch.c po zář 8 16:14:00 2008 *************** *** 186,192 **** /* Read the metapage */ metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_READ, LH_META_PAGE); ! metap = (HashMetaPage) BufferGetPage(metabuf); /* * Compute the target bucket number, and convert to block number. --- 186,192 ---- /* Read the metapage */ metabuf = _hash_getbuf(rel, HASH_METAPAGE, HASH_READ, LH_META_PAGE); ! metap = HashPageGetMeta(BufferGetPage(metabuf)); /* * Compute the target bucket number, and convert to block number. diff -rc pgsql_hash.be486df40421/src/backend/access/hash/hashutil.c pgsql_hash/src/backend/access/hash/hashutil.c *** pgsql_hash.be486df40421/src/backend/access/hash/hashutil.c po zář 8 16:14:00 2008 --- pgsql_hash/src/backend/access/hash/hashutil.c po zář 8 16:14:00 2008 *************** *** 190,196 **** */ if (flags == LH_META_PAGE) { ! HashMetaPage metap = (HashMetaPage) page; if (metap->hashm_magic != HASH_MAGIC) ereport(ERROR, --- 190,196 ---- */ if (flags == LH_META_PAGE) { ! HashMetaPage metap = HashPageGetMeta(page); if (metap->hashm_magic != HASH_MAGIC) ereport(ERROR, běžné podadresáře: pgsql_hash.be486df40421/src/include/access a pgsql_hash/src/include/access diff -rc pgsql_hash.be486df40421/src/include/access/hash.h pgsql_hash/src/include/access/hash.h *** pgsql_hash.be486df40421/src/include/access/hash.h po zář 8 16:14:00 2008 --- pgsql_hash/src/include/access/hash.h po zář 8 16:14:00 2008 *************** *** 138,144 **** typedef struct HashMetaPageData { - PageHeaderData hashm_phdr; /* pad for page header (do not use) */ uint32 hashm_magic; /* magic no. for hash tables */ uint32 hashm_version; /* version ID */ double hashm_ntuples; /* number of tuples stored in the table */ --- 138,143 ---- *************** *** 191,199 **** #define BMPGSZ_BIT(metap) ((metap)->hashm_bmsize << BYTE_TO_BIT) #define BMPG_SHIFT(metap) ((metap)->hashm_bmshift) #define BMPG_MASK(metap) (BMPGSZ_BIT(metap) - 1) - #define HashPageGetBitmap(pg) \ - ((uint32 *) (((char *) (pg)) + MAXALIGN(sizeof(PageHeaderData)))) /* * The number of bits in an ovflpage bitmap word. */ --- 190,207 ---- #define BMPGSZ_BIT(metap) ((metap)->hashm_bmsize << BYTE_TO_BIT) #define BMPG_SHIFT(metap) ((metap)->hashm_bmshift) #define BMPG_MASK(metap) (BMPGSZ_BIT(metap) - 1) + #define HashPageGetBitmap(page) \ + ((uint32*) PageGetContents(page)) + + #define HashGetMaxBitmapSize(page) \ + (PageGetPageSize((Page) page)- \ + (MAXALIGN(SizeOfPageHeaderData) + \ + MAXALIGN(sizeof(HashPageOpaqueData))) ) + + #define HashPageGetMeta(page) \ + ((HashMetaPage) PageGetContents(page)) + /* * The number of bits in an ovflpage bitmap word. */

view thread (63+ messages)  latest in thread

Message-ID: <48C5349F.4080300@sun.com>
Permalink:  ../48C5349F.4080300@sun.com/
Also on:    postgresql.org/message-id/48C5349F.4080300@sun.com

 ·  · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-patches@postgresql.org
  Cc: Zdenek.Kotala@Sun.COM, tgl@sss.pgh.pa.us, badalex@gmail.com, mx.cogito@gmail.com, jonah.harris@gmail.com
  Subject: Re: hash index improving v3
  In-Reply-To: <48C5349F.4080300@sun.com>

* 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