From 296601b1d7aba7f23aea3d47c617e2d6df81de3e Mon Sep 17 00:00:00 2001 From: Alexander Kuzmenkov Date: Tue, 28 Jun 2022 17:49:23 +0300 Subject: [PATCH] Synchronize chunk cache sizes Specifically, flush the chunk multi-insert states when the number of it reaches the size of the chunk cache. Otherwise, the chunks corresponding to the multi-insert states go out of cache and have to be looked up again when the multi-insert state is flushed, which leads to a performance hit. --- src/copy.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/copy.c b/src/copy.c index e808c62d5..e92e26c54 100644 --- a/src/copy.c +++ b/src/copy.c @@ -263,6 +263,17 @@ TSCopyMultiInsertInfoIsFull(TSCopyMultiInsertInfo *miinfo) if (miinfo->bufferedTuples >= MAX_BUFFERED_TUPLES || miinfo->bufferedBytes >= MAX_BUFFERED_BYTES) return true; + + if (hash_get_num_entries(miinfo->multiInsertBuffers) >= ts_guc_max_open_chunks_per_insert) + { + /* + * Flushing each multi-insert buffer will require looking up the + * corresponding chunk insert state in the cache, so don't accumulate + * more inserts than the cache can fit, to avoid thrashing. + */ + return true; + } + return false; }