summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorThomas Munro2019-12-23 22:31:24 +0000
committerThomas Munro2019-12-24 00:05:43 +0000
commite69d644547785cc9f079650d29118a3688bc5039 (patch)
treed7762c8e93743b87a3786a372c925aab46277111 /src/include
parentd5b9c2baff662aac22cd2a497d5bcd3b5a916fd0 (diff)
Rotate instead of shifting hash join batch number.
Our algorithm for choosing batch numbers turned out not to work effectively for multi-billion key inner relations. We would use more hash bits than we have, and effectively concentrate all tuples into a smaller number of batches than we intended. While ideally we should switch to wider hashes, for now, change the algorithm to one that effectively gives up bits from the bucket number when we don't have enough bits. That means we'll finish up with longer bucket chains than would be ideal, but that's better than having batches that don't fit in work_mem and can't be divided. Batch-patch to all supported releases. Author: Thomas Munro Reviewed-by: Tom Lane, thanks also to Tomas Vondra, Alvaro Herrera, Andres Freund for testing and discussion Reported-by: James Coleman Discussion: https://postgr.es/m/16104-dc11ed911f1ab9df%40postgresql.org
Diffstat (limited to 'src/include')
-rw-r--r--src/include/port/pg_bitutils.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/include/port/pg_bitutils.h b/src/include/port/pg_bitutils.h
index 5197926696f..d1544834a6b 100644
--- a/src/include/port/pg_bitutils.h
+++ b/src/include/port/pg_bitutils.h
@@ -136,4 +136,13 @@ extern int (*pg_popcount64) (uint64 word);
/* Count the number of one-bits in a byte array */
extern uint64 pg_popcount(const char *buf, int bytes);
+/*
+ * Rotate the bits of "word" to the right by n bits.
+ */
+static inline uint32
+pg_rotate_right32(uint32 word, int n)
+{
+ return (word >> n) | (word << (sizeof(word) * BITS_PER_BYTE - n));
+}
+
#endif /* PG_BITUTILS_H */