Re: hash index improving v3 - Mailing list pgsql-patches

From Zdenek Kotala
Subject Re: hash index improving v3
Date
Msg-id 48C5349F.4080300@sun.com
Whole thread Raw
In response to Re: hash index improving v3  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: hash index improving v3  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-patches
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

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.
   */

pgsql-patches by date:

Previous
From: Zdenek Kotala
Date:
Subject: Re: hash index improving v3
Next
From: "Ryan Bradetich"
Date:
Subject: Re: [PgFoundry] Unsigned Data Types [1 of 2]