Skip to content

Commit fd734f3

Browse files
committed
Use pg_bitutils for HyperLogLog.
Using pg_leftmost_one_post32() yields substantial performance benefits. Backpatching to version 13 because HLL is used for HashAgg improvements in 9878b64, which was also backpatched to 13. Reviewed-by: Peter Geoghegan Discussion: https://postgr.es/m/CAH2-WzkGvDKVDo+0YvfvZ+1CE=iCi88DCOGFF3i1hTGGaxcKPw@mail.gmail.com Backpatch-through: 13
1 parent f1af75c commit fd734f3

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/backend/lib/hyperloglog.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include <math.h>
5050

5151
#include "lib/hyperloglog.h"
52+
#include "port/pg_bitutils.h"
5253

5354
#define POW_2_32 (4294967296.0)
5455
#define NEG_POW_2_32 (-4294967296.0)
@@ -242,11 +243,13 @@ rho(uint32 x, uint8 b)
242243
{
243244
uint8 j = 1;
244245

245-
while (j <= b && !(x & 0x80000000))
246-
{
247-
j++;
248-
x <<= 1;
249-
}
246+
if (x == 0)
247+
return b + 1;
248+
249+
j = 32 - pg_leftmost_one_pos32(x);
250+
251+
if (j > b)
252+
return b + 1;
250253

251254
return j;
252255
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy