pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Yura Sokolov <y.sokolov@postgrespro.ru>
To: Ranier Vilela <ranier.vf@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Andres Freund <andres@anarazel.de>
Cc: Tomas Vondra <tomas.vondra@2ndquadrant.com>
Subject: Re: Bug in huge simplehash
Date: Tue, 10 Aug 2021 15:10:49 +0300
Message-ID: <c900cc323249dfdecb2a151c8aa4b579@postgrespro.ru> (raw)
In-Reply-To: <CAEudQAq_Y-KhtC+=jHRT+3Mhwu17WB8eutTJDy_LBLAPJ-+U4Q@mail.gmail.com>
References: <b1f7f32737c3438136f64b26f4852b96@postgrespro.ru>
	<CAEudQAq_Y-KhtC+=jHRT+3Mhwu17WB8eutTJDy_LBLAPJ-+U4Q@mail.gmail.com>

Ranier Vilela писал 2021-08-10 14:21:
> Em ter., 10 de ago. de 2021 às 05:53, Yura Sokolov
> <y.sokolov@postgrespro.ru> escreveu:
> 
>> 
>> I went to check SH_GROW and.... It is `SH_GROW(SH_TYPE *tb, uint32
>> newsize)`
>> :-(((
>> Therefore when `tb->size == SH_MAX_SIZE/2` and we call `SH_GROW(tb,
>> tb->size * 2)`,
>> then SH_GROW(tb, 0) is called due to truncation.
>> And SH_COMPUTE_PARAMETERS is also accepts `uint32 newsize`.
>> 
>> Ahh... ok, patch is updated to fix this as well.
> 
> It seems that we need to fix the function prototype too.
> 
> /* void <prefix>_grow(<prefix>_hash *tb) */
> -SH_SCOPE void SH_GROW(SH_TYPE * tb, uint32 newsize); +SH_SCOPE void
> SH_GROW(SH_TYPE * tb, uint64 newsize);

Ahh... Thank you, Ranier.
Attached v2.

regards,

-----

Yura Sokolov

Attachments:

UTF-8''v2-0001-Fix-new-size-and-sizemask-computaton-in-simplehash.h.patch (text/x-diff, 2.0K) download From 82f449896d62be8440934d955d4e368f057005a6 Mon Sep 17 00:00:00 2001 From: Yura Sokolov <y.sokolov@postgrespro.ru> Date: Tue, 10 Aug 2021 11:51:16 +0300 Subject: [PATCH] Fix new size and sizemask computaton in simplehash.h Fix couple of 32/64bit related errors in simplehash.h: - size of SH_GROW and SH_COMPUTE_PARAMETERS arguments - computation of tb->sizemask. --- src/include/lib/simplehash.h | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/include/lib/simplehash.h b/src/include/lib/simplehash.h index da51781e98e..adda5598338 100644 --- a/src/include/lib/simplehash.h +++ b/src/include/lib/simplehash.h @@ -198,8 +198,8 @@ SH_SCOPE void SH_DESTROY(SH_TYPE * tb); /* void <prefix>_reset(<prefix>_hash *tb) */ SH_SCOPE void SH_RESET(SH_TYPE * tb); -/* void <prefix>_grow(<prefix>_hash *tb) */ -SH_SCOPE void SH_GROW(SH_TYPE * tb, uint32 newsize); +/* void <prefix>_grow(<prefix>_hash *tb, uint64 newsize) */ +SH_SCOPE void SH_GROW(SH_TYPE * tb, uint64 newsize); /* <element> *<prefix>_insert(<prefix>_hash *tb, <key> key, bool *found) */ SH_SCOPE SH_ELEMENT_TYPE *SH_INSERT(SH_TYPE * tb, SH_KEY_TYPE key, bool *found); @@ -302,7 +302,7 @@ SH_SCOPE void SH_STAT(SH_TYPE * tb); * the hashtable. */ static inline void -SH_COMPUTE_PARAMETERS(SH_TYPE * tb, uint32 newsize) +SH_COMPUTE_PARAMETERS(SH_TYPE * tb, uint64 newsize) { uint64 size; @@ -322,11 +322,7 @@ SH_COMPUTE_PARAMETERS(SH_TYPE * tb, uint32 newsize) /* now set size */ tb->size = size; - - if (tb->size == SH_MAX_SIZE) - tb->sizemask = 0; - else - tb->sizemask = tb->size - 1; + tb->sizemask = (uint32)(size - 1); /* * Compute the next threshold at which we need to grow the hash table @@ -476,7 +472,7 @@ SH_RESET(SH_TYPE * tb) * performance-wise, when known at some point. */ SH_SCOPE void -SH_GROW(SH_TYPE * tb, uint32 newsize) +SH_GROW(SH_TYPE * tb, uint64 newsize) { uint64 oldsize = tb->size; SH_ELEMENT_TYPE *olddata = tb->data; -- 2.32.0

view thread (11+ messages)  latest in thread

Message-ID: <c900cc323249dfdecb2a151c8aa4b579@postgrespro.ru>
Permalink:  ../c900cc323249dfdecb2a151c8aa4b579@postgrespro.ru/
Also on:    postgresql.org/message-id/c900cc323249dfdecb2a151c8aa4b579@postgrespro.ru

 ·  · 

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-hackers@postgresql.org
  Cc: y.sokolov@postgrespro.ru, ranier.vf@gmail.com, pgsql-hackers@lists.postgresql.org, andres@anarazel.de, tomas.vondra@2ndquadrant.com
  Subject: Re: Bug in huge simplehash
  In-Reply-To: <c900cc323249dfdecb2a151c8aa4b579@postgrespro.ru>

* 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