Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hSJJQ-0000x8-VN for pgsql-general@arkaria.postgresql.org; Sun, 19 May 2019 10:45:05 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hSJIQ-0007Dh-Cu for pgsql-general@arkaria.postgresql.org; Sun, 19 May 2019 10:44:02 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hSJIP-0007Da-On for pgsql-general@lists.postgresql.org; Sun, 19 May 2019 10:44:01 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hSJIJ-0008BN-CW for pgsql-general@lists.postgresql.org; Sun, 19 May 2019 10:44:00 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id 4D6F726C7; Sun, 19 May 2019 12:43:52 +0200 (CEST) Date: Sun, 19 May 2019 12:43:52 +0200 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: bigint out of range Message-ID: <20190519104352.fty5grjwrsj5p4zp@hjp.at> References: <20190518093519.2kd6hyw37wcx6qwc@hjp.at> <20190518192703.ml6duizgdyfyetva@hjp.at> <20190518204941.d2o5xy2b53r266ws@hjp.at> <55d8ce6e-2a94-1003-0fc1-66a39d6d2e8a@gmail.com> <20190518223952.g5jrsyj5us7kytpb@hjp.at> <0bea576e-43df-9176-a5da-1aea2bb1b337@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="rpkoewjuzkcdzxzk" Content-Disposition: inline In-Reply-To: <0bea576e-43df-9176-a5da-1aea2bb1b337@gmail.com> User-Agent: NeoMutt/20170113 (1.7.2) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --rpkoewjuzkcdzxzk Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2019-05-18 19:16:19 -0500, Ron wrote: > On 5/18/19 5:39 PM, Peter J. Holzer wrote: > > On 2019-05-18 17:14:59 -0500, Ron wrote: > > > On 5/18/19 3:49 PM, Peter J. Holzer wrote: > > > On 2019-05-18 15:19:22 -0500, Ron wrote: > > > On 5/18/19 2:27 PM, Peter J. Holzer wrote: > > > On 2019-05-18 10:49:53 -0700, David G. Johnston wrote: > > >=20 > > > You don=E2=80=99t perform math on a hash > > >=20 > > > That's not generally true. Hashes are used for further c= omputation for > > > example in hash tables or in cryptography. > > >=20 > > > How is it "using math" to use a hash key in a hash lookup ta= ble? > > >=20 > > > hash modulo table size. > > >=20 > > >=20 > > > I've seen that used when the tablespace is pre-allocated, and you has= h modulo > > > the tablespace page number.=C2=A0 (Yes, performance tanks when you st= art filling up > > > pages.)=C2=A0 How do you hash on the (ever growing) table size? > > The hash function returns a number in a range much larger than the > > possible number of buckets. 64 bits is a good choice today. > >=20 > > To determine the bucket you need to reduce this number to something in > > the range [0, nr_buckets). This is where modulo comes in: > >=20 > > i =3D h % nr_buckets > >=20 > > If the the table fills up, you increase nr_buckets, reallocate and > > rehash all entries. >=20 > Ouch.=C2=A0 Response time on a big table would take a serious hit if that= rehash > happened in the middle of the day on a big OLTP system. So that might be a reason not to use hash indexes tables where the worst case insert time is a concern (the average insert time is still O(1)). But please be aware that I answered your question 'How is it "using math" to use a hash key?', not 'How are hash indexes in PostgreSQL implemented?'. So my answer covered the most simple and generic implementation. You can split buckets lazily, and in fact PostgreSQL does this. I just looked at the code briefly, but I don't really understand how it works. Guess I would have to read Margo Seltzer's paper paper for that. Still, even with that optimization (or tradeoff - it may make the lookup slower) the README notes that splits are expensive. hp --=20 _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp@hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson --rpkoewjuzkcdzxzk Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAlzhM2MACgkQ8g5IURL+ KF3Cjw/+MBqtVzHSCIdbbH+BVwmAESUjykF7qz918XpGAo7IkXSaHO/1DiwxHXNh NMDYgfte4UW6iWLopokxcVeohSdGCoXm/68Dx4BovmP3vHh8TR5OaJxTJK1orH7z wjahBRTHr4ZKzO75QruZvWXtVmxEQc+3iFeEUaU6lUkzmDwxOOaic7lnwYWzbw3n b5nFMhfZQ+r6HY/+AKIRZxayyTuSHaKnMQT0d9EnPEV+4U+AWn2rhpRJhzHq+Dvi j/N2Sw3hvVK6w9nib82xZ3BpuX3ZpQfoY+WGbbjOAJHfkh3boVzHy6vIh6MaMo+R vEZEKSAqqy9ADjRuIVv3U85sxPUU58ULVQWMG0mB01kIu+oLmmYT/A/QB/9ywahS LcjVSfpqKHmXQcI50kEhpG19NZd+PMIWeoxjsa+6KCKw+/WaSoxyTP/l6O+8lav5 oXFIgGS7nUfhZp53lpc6iDa+2vQwMl3wz5q8Mg5QTnHaP8kXEEKQayeNPY4TjH6D AwTPMVomUAgOLsmvzDpzEf/ttuU2jIAFDP6PMTjfILzV5PHuHbMCLCEzPgkWUPLW tsSaqJ9KmfA29KCk6hZgaEq+67RpcAuXGDQmf0vE1GuHNDswmAYoBLWt6PQ3MMHS 0+JRawdC9H6TRvnevFEtTC2cNhM8w0/Hz0zftzN7Klm3FZvnHyE= =vius -----END PGP SIGNATURE----- --rpkoewjuzkcdzxzk--