aboutsummaryrefslogtreecommitdiff
path: root/src/include/executor
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2014-09-10 21:24:52 +0300
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2014-09-10 21:24:52 +0300
commit45f6240a8fa9d35548eb2ef23dba2c11540aa02a (patch)
tree3c15869f843b90762a673d2af9fb5a7849fbb609 /src/include/executor
parent311da16439ef69fc2054af3f4377fd4acd29a0e3 (diff)
downloadpostgresql-45f6240a8fa9d35548eb2ef23dba2c11540aa02a.tar.gz
postgresql-45f6240a8fa9d35548eb2ef23dba2c11540aa02a.zip
Pack tuples in a hash join batch densely, to save memory.
Instead of palloc'ing each HashJoinTuple individually, allocate 32kB chunks and pack the tuples densely in the chunks. This avoids the AllocChunk header overhead, and the space wasted by standard allocator's habit of rounding sizes up to the nearest power of two. This doesn't contain any planner changes, because the planner's estimate of memory usage ignores the palloc overhead. Now that the overhead is smaller, the planner's estimates are in fact more accurate. Tomas Vondra, reviewed by Robert Haas.
Diffstat (limited to 'src/include/executor')
-rw-r--r--src/include/executor/hashjoin.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/include/executor/hashjoin.h b/src/include/executor/hashjoin.h
index 3beae403ce6..c9e61dfa39c 100644
--- a/src/include/executor/hashjoin.h
+++ b/src/include/executor/hashjoin.h
@@ -102,6 +102,25 @@ typedef struct HashSkewBucket
#define SKEW_WORK_MEM_PERCENT 2
#define SKEW_MIN_OUTER_FRACTION 0.01
+/*
+ * To reduce palloc overhead, the HashJoinTuples for the current batch are
+ * packed in 32kB buffers instead of pallocing each tuple individually.
+ */
+typedef struct HashMemoryChunkData
+{
+ int ntuples; /* number of tuples stored in this chunk */
+ size_t maxlen; /* size of the buffer holding the tuples */
+ size_t used; /* number of buffer bytes already used */
+
+ struct HashMemoryChunkData *next; /* pointer to the next chunk (linked list) */
+
+ char data[1]; /* buffer allocated at the end */
+} HashMemoryChunkData;
+
+typedef struct HashMemoryChunkData *HashMemoryChunk;
+
+#define HASH_CHUNK_SIZE (32 * 1024L)
+#define HASH_CHUNK_THRESHOLD (HASH_CHUNK_SIZE / 4)
typedef struct HashJoinTableData
{
@@ -157,6 +176,9 @@ typedef struct HashJoinTableData
MemoryContext hashCxt; /* context for whole-hash-join storage */
MemoryContext batchCxt; /* context for this-batch-only storage */
+
+ /* used for dense allocation of tuples (into linked chunks) */
+ HashMemoryChunk chunks; /* one list for the whole batch */
} HashJoinTableData;
#endif /* HASHJOIN_H */