pgsql: Make some minor improvements in memory-context infrastructure.

2022-10-14 Thread Tom Lane
Make some minor improvements in memory-context infrastructure. We lack a version of repalloc() that supports MCXT_ALLOC_NO_OOM semantics, so invent repalloc_extended() with the usual set of flags. repalloc_huge() becomes a legacy wrapper for that. Also, fix dynahash.c so that it can support HASH

pgsql: Store GUC data in a memory context, instead of using malloc().

2022-10-14 Thread Tom Lane
Store GUC data in a memory context, instead of using malloc(). The only real argument for using malloc directly was that we needed the ability to not throw error on OOM; but mcxt.c grew that feature awhile ago. Keeping the data in a memory context improves accountability and debuggability --- for

pgsql: Replace the sorted array of GUC variables with a hash table.

2022-10-14 Thread Tom Lane
Replace the sorted array of GUC variables with a hash table. This gets rid of bsearch() in favor of hashed lookup. The main advantage is that it becomes far cheaper to add new GUCs, since we needn't re-sort the pointer array. Adding N new GUCs had been O(N^2 log N), but now it's closer to O(N).

pgsql: Add auxiliary lists to GUC data structures for better performanc

2022-10-14 Thread Tom Lane
Add auxiliary lists to GUC data structures for better performance. The previous patch made addition of new GUCs cheap, but other GUC operations aren't improved and indeed get a bit slower, because hash_seq_search() is slower than just scanning a pointer array. However, most performance-critical G

pgsql: libpq: Reset singlerow flag correctly in pipeline mode

2022-10-14 Thread Alvaro Herrera
libpq: Reset singlerow flag correctly in pipeline mode When a query whose results were requested in single-row mode is the last in the queue by the time those results are being read, the single-row flag was not being reset, because we were returning early from pqPipelineProcessQueue. Move that st

pgsql: libpq: Reset singlerow flag correctly in pipeline mode

2022-10-14 Thread Alvaro Herrera
libpq: Reset singlerow flag correctly in pipeline mode When a query whose results were requested in single-row mode is the last in the queue by the time those results are being read, the single-row flag was not being reset, because we were returning early from pqPipelineProcessQueue. Move that st

pgsql: libpq: Reset singlerow flag correctly in pipeline mode

2022-10-14 Thread Alvaro Herrera
libpq: Reset singlerow flag correctly in pipeline mode When a query whose results were requested in single-row mode is the last in the queue by the time those results are being read, the single-row flag was not being reset, because we were returning early from pqPipelineProcessQueue. Move that st

pgsql: pgstat: Track time of the last scan of a relation

2022-10-14 Thread Andres Freund
pgstat: Track time of the last scan of a relation It can be useful to know when a relation has last been used, e.g., when evaluating whether an index is still required. It was already possible to infer the time of the last usage by tracking, e.g., pg_stat_all_indexes.idx_scan over time. But far fr

pgsql: Have GetCurrentTransactionStopTimestamp() set xactStopTimestamp

2022-10-14 Thread Andres Freund
Have GetCurrentTransactionStopTimestamp() set xactStopTimestamp if unset Previously GetCurrentTransactionStopTimestamp() computed a new timestamp whenever xactStopTimestamp was unset and xactStopTimestamp was only set when a commit or abort record was written. An upcoming patch will add additiona

pgsql: Fix some comments in proc.h

2022-10-14 Thread Michael Paquier
Fix some comments in proc.h There was a typo and two places where delayChkpt was still mentioned, but it is called delayChkptFlags these days. Author: David Christensen Discussion: https://postgr.es/m/CAOxo6XLB=ab_Y9jRw4iKyMZDns0wo=egsrvijhhal67rzqb...@mail.gmail.com Branch -- master Detai