Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fd734f3

Browse filesBrowse 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
Copy full SHA for fd734f3

File tree

Expand file treeCollapse file tree

1 file changed

+8
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-5
lines changed

‎src/backend/lib/hyperloglog.c

Copy file name to clipboardExpand all lines: src/backend/lib/hyperloglog.c
+8-5Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.