From fae55f0bb38504b3774fa50152d3c14d2f09aa15 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 13 Sep 2024 16:16:47 -0400 Subject: [PATCH] Allow _h_indexbuild() to be interrupted. When we are building a hash index that is large enough to need pre-sorting (larger than either maintenance_work_mem or NBuffers), the initial sorting phase is interruptible, but the insertion phase wasn't. Add the missing CHECK_FOR_INTERRUPTS(). Per bug #18616 from Alexander Lakhin. Back-patch to all supported branches. Pavel Borisov Discussion: https://postgr.es/m/18616-acbb9e5caf41e964@postgresql.org --- src/backend/access/hash/hashsort.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/backend/access/hash/hashsort.c b/src/backend/access/hash/hashsort.c index 149cd9fc05..e608d53362 100644 --- a/src/backend/access/hash/hashsort.c +++ b/src/backend/access/hash/hashsort.c @@ -148,6 +148,9 @@ _h_indexbuild(HSpool *hspool, Relation heapRel) /* the tuples are sorted by hashkey, so pass 'sorted' as true */ _hash_doinsert(hspool->index, itup, heapRel, true); + /* allow insertion phase to be interrupted, and track progress */ + CHECK_FOR_INTERRUPTS(); + pgstat_progress_update_param(PROGRESS_CREATEIDX_TUPLES_DONE, ++tups_done); }