On Mon, Jun 06, 2022 at 04:23:34PM +0900, Michael Paquier wrote: > On Sat, Jun 04, 2022 at 08:42:33PM -0500, Justin Pryzby wrote: > > The fix seems to be to CHECK_FOR_INTERRUPTS() within multi_sort_compare(). > > That would supercede the other two CHECK_FOR_INTERRUPTS I'd proposed, and > > handle mcv, depends, and ndistinct all at once. > > Hmm. I have to admit that adding a CFI() in multi_sort_compare() > stresses me a bit as it is dependent on the number of rows involved, > and it can be used as a qsort routine.
That's exactly the problem for which I showed a backtrace - it took 10s of seconds to do qsort, which is (uh) a human timescale and too long to be unresponsive, even if I create on a table with many rows a stats object with a lot of columns and a high stats target.
>From 1c5fe1fb1cf4d2e38cf3b8edef1288cb63388cc4 Mon Sep 17 00:00:00 2001 From: Justin Pryzby <pryz...@telsasoft.com> Date: Sun, 8 May 2022 19:36:43 -0500 Subject: [PATCH] wip: check for interrupts during extended stats It's possible to handle this partially by adding CFI at higher levels (statext_dependencies_build and statext_ndistinct_build), but in order to handle MCV, CFI has to be done at a low level here. --- src/backend/statistics/extended_stats.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index cb0a22b73e8..c6ba352e414 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -894,6 +894,8 @@ multi_sort_compare(const void *a, const void *b, void *arg) SortItem *ib = (SortItem *) b; int i; + CHECK_FOR_INTERRUPTS(); + for (i = 0; i < mss->ndims; i++) { int compare; -- 2.17.1