Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gGMdv-00075G-HE for pgsql-hackers@arkaria.postgresql.org; Sat, 27 Oct 2018 11:20:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gGMds-0001HV-DW for pgsql-hackers@arkaria.postgresql.org; Sat, 27 Oct 2018 11:20:32 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gGMds-0001HN-36 for pgsql-hackers@lists.postgresql.org; Sat, 27 Oct 2018 11:20:32 +0000 Received: from mx2a.mailbox.org ([2001:67c:2050:104:0:2:25:2] helo=mx2.mailbox.org) by makus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gGMdj-0004jI-Lx for pgsql-hackers@postgresql.org; Sat, 27 Oct 2018 11:20:30 +0000 Received: from smtp2.mailbox.org (unknown [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx2.mailbox.org (Postfix) with ESMTPS id DBC15A1107; Sat, 27 Oct 2018 13:20:16 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter01.heinlein-hosting.de (spamfilter01.heinlein-hosting.de [80.241.56.115]) (amavisd-new, port 10030) with ESMTP id RoxlrfvMSjVy; Sat, 27 Oct 2018 13:20:15 +0200 (CEST) From: Antonin Houska To: Thomas Munro cc: Pg Hackers Subject: Re: Comment fix and question about dshash.c In-reply-to: References: <8726.1540553521@localhost> Comments: In-reply-to Thomas Munro message dated "Sat, 27 Oct 2018 10:03:21 +1300." MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 27 Oct 2018 13:22:01 +0200 Message-ID: <15639.1540639321@localhost> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Thomas Munro wrote: > On Sat, Oct 27, 2018 at 12:30 AM Antonin Houska wrote: >=20 > Thanks, will fix. >=20 > > 2. Can anyone please explain this macro? > > > > /* Max entries before we need to grow. Half + quarter =3D 75% load fac= tor. */ > > #define MAX_COUNT_PER_PARTITION(hash_table) = \ > > (BUCKETS_PER_PARTITION(hash_table->size_log2) / 2 + \ > > BUCKETS_PER_PARTITION(hash_table->size_log2) / 4) > > > > I'm failing to understand why the maximum number of hash table entries = in a > > partition should be smaller than the number of buckets in that partitio= n. > > > > The fact that MAX_COUNT_PER_PARTITION refers to entries and not buckets= is > > obvious from this condition in dshash_find_or_insert() > > > > /* Check if we are getting too full. */ > > if (partition->count > MAX_COUNT_PER_PARTITION(hash_table)) >=20 > Are you saying there is a bug in this logic (which is nbuckets * 0.75 > expressed as integer maths), or saying that 0.75 is not a good maximum > load factor? I looked around at a couple of general purpose hash > tables and saw that some used 0.75 and some used 1.0, as a wasted > space-vs-collision trade-off. If I have my maths right[1], with 0.75 > you expect to have 75 entries in ~53 buckets, but with 1.0 you expect > to have 100 entries in ~64 buckets. I don't know how exactly you apply the [1] formula (what is "n" and what is "N" in your case?), but my consideration was much simpler: For example, if BUCKETS_PER_PARTITION returns 8 (power of 2 is expected here and also more convenient), then MAX_COUNT_PER_PARTITION returns 8 / 2 + 8 / 4 =3D 6. Thus= the hashtable gets resized if we're going to add the 7th entry to the partition, i.e. we the number of entries in the partition is lower than the number of buckets. Is that o.k.? > [1] https://math.stackexchange.com/questions/470662/average-number-of-bin= s-occupied-when-throwing-n-balls-into-n-bins --=20 Antonin Houska Cybertec Sch=C3=B6nig & Sch=C3=B6nig GmbH Gr=C3=B6hrm=C3=BChlgasse 26, A-2700 Wiener Neustadt Web: https://www.cybertec-postgresql.com