Invent qsort_interruptible().
Tom Lane <tgl@sss.pgh.pa.us>
Invent qsort_interruptible(). Justin Pryzby reported that some scenarios could cause gathering of extended statistics to spend many seconds in an un-cancelable qsort() operation. To fix, invent qsort_interruptible(), which is just like qsort_arg() except that it will also do CHECK_FOR_INTERRUPTS every so often. This bloats the backend by a couple of kB, which seems like a good investment. (We considered just enabling CHECK_FOR_INTERRUPTS in the existing qsort and qsort_arg functions, but there are some callers for which that'd demonstrably be unsafe. Opt-in seems like a better way.) For now, just apply qsort_interruptible() in statistics collection. There's probably more places where it could be useful, but we can always change other call sites as we find problems. Back-patch to v14. Before that we didn't have extended stats on expressions, so that the problem was less severe. Also, this patch depends on the sort_template infrastructure introduced in v14. Tom Lane and Justin Pryzby Discussion: https://postgr.es/m/20220509000108.GQ28830@telsasoft.com
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/commands/analyze.c | modified | +13 −12 |
| src/backend/statistics/extended_stats.c | modified | +2 −2 |
| src/backend/statistics/mcv.c | modified | +7 −7 |
| src/backend/statistics/mvdistinct.c | modified | +2 −2 |
| src/backend/tsearch/ts_typanalyze.c | modified | +12 −10 |
| src/backend/utils/adt/array_typanalyze.c | modified | +16 −15 |
| src/backend/utils/adt/rangetypes_typanalyze.c | modified | +8 −7 |
| src/backend/utils/sort/Makefile | modified | +1 −0 |
| src/backend/utils/sort/qsort_interruptible.c | added | +16 −0 |
| src/include/port.h | modified | +3 −0 |
Discussion
- should check interrupts in BuildRelationExtStatistics ? 20 messages · 2022-05-09 → 2022-07-12