Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 07cbcdd

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 9878b643, 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 e710f3b commit 07cbcdd

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)