pgsql: localbuf: Introduce TerminateLocalBufferIO()

2025-03-15 Thread Andres Freund
localbuf: Introduce TerminateLocalBufferIO() Previously TerminateLocalBufferIO() was open-coded in multiple places, which doesn't seem like a great idea. While TerminateLocalBufferIO() currently is rather simple, an upcoming patch requires additional code to be added to TerminateLocalBufferIO(), m

pgsql: localbuf: Introduce InvalidateLocalBuffer()

2025-03-15 Thread Andres Freund
localbuf: Introduce InvalidateLocalBuffer() Previously, there were three copies of this code, two of them identical. There's no good reason for that. This change is nice on its own, but the main motivation is the AIO patchset, which needs to add extra checks the deduplicated code, which of course

pgsql: localbuf: Fix dangerous coding pattern in GetLocalVictimBuffer()

2025-03-15 Thread Andres Freund
localbuf: Fix dangerous coding pattern in GetLocalVictimBuffer() If PinLocalBuffer() were to modify the buf_state, the buf_state in GetLocalVictimBuffer() would be out of date. Currently that does not happen, as PinLocalBuffer() only modifies the buf_state if adjust_usagecount=true and GetLocalVic

pgsql: localbuf: Introduce StartLocalBufferIO()

2025-03-15 Thread Andres Freund
localbuf: Introduce StartLocalBufferIO() To initiate IO on a shared buffer we have StartBufferIO(). For temporary table buffers no similar function exists - likely because the code for that currently is very simple due to the lack of concurrency. However, the upcoming AIO support will make it pos

pgsql: localbuf: Introduce FlushLocalBuffer()

2025-03-15 Thread Andres Freund
localbuf: Introduce FlushLocalBuffer() Previously we had two paths implementing writing out temporary table buffers. For shared buffers, the logic for that is centralized in FlushBuffer(). Introduce FlushLocalBuffer() to do the same for local buffers. Besides being a nice cleanup on its own, it a

pgsql: Silence perl critic

2025-03-15 Thread Andrew Dunstan
Silence perl critic Commit 27bdec06841 uses a loop variable that is not strictly local to the loop. Perlcritic disapproves, and there's really no reason as the variable is not used outside the loop. Per buildfarm animals koel and crake. Branch -- master Details --- https://git.postgresq

pgsql: Optimization for lower(), upper(), casefold() functions.

2025-03-15 Thread Jeff Davis
Optimization for lower(), upper(), casefold() functions. Improve performance and reduce table sizes for case mapping. The main case mapping table stores only 16-bit offsets, which can be used to look up the mapped code point in any of the case tables (fold, lower, upper, or title case). Simple ca

pgsql: Simplify and generalize PrepareSortSupportFromIndexRel()

2025-03-15 Thread Peter Eisentraut
Simplify and generalize PrepareSortSupportFromIndexRel() PrepareSortSupportFromIndexRel() was accepting btree strategy numbers purely for the purpose of comparing it later against btree strategies to determine if the sort direction was forward or reverse. Change that. Instead, pass a bool direct

pgsql: Fix ARRAY_SUBLINK and ARRAY[] for int2vector and oidvector input

2025-03-15 Thread Tom Lane
Fix ARRAY_SUBLINK and ARRAY[] for int2vector and oidvector input. If the given input_type yields valid results from both get_element_type and get_array_type, initArrayResultAny believed the former and treated the input as an array type. However this is inconsistent with what get_promoted_array_ty

Re: pgsql: pg_logicalinspect: Fix possible crash when passing a directory p

2025-03-15 Thread Peter Eisentraut
On 12.03.25 03:08, David Rowley wrote: On Wed, 12 Mar 2025 at 05:57, Masahiko Sawada wrote: contrib/pg_logicalinspect/pg_logicalinspect.c | 55 --- This introduces a new compiler warning for compilers that don't know the ereport(ERROR) does not return. Which compiler is that

pgsql: Fix a few more redundant calls of GetLatestSnapshot()

2025-03-15 Thread Heikki Linnakangas
Fix a few more redundant calls of GetLatestSnapshot() Commit 2367503177 fixed this in RelationFindReplTupleByIndex(), but I missed two other similar cases. Per report from Ranier Vilela. Discussion: https://www.postgresql.org/message-id/caeudqarut1de45wn87f-gb7xmy_hw6x1dfd3sqdhhxp-rmd...@mail.g

pgsql: Fix snapshot used in logical replication index lookup

2025-03-15 Thread Heikki Linnakangas
Fix snapshot used in logical replication index lookup The function calls GetLatestSnapshot() to acquire a fresh snapshot, makes it active, and was meant to pass it to table_tuple_lock(), but instead called GetLatestSnapshot() again to acquire yet another snapshot. It was harmless because the heap

pgsql: Doc: remove obsolete comment.

2025-03-15 Thread Tom Lane
Doc: remove obsolete comment. This para should have been removed by 2f9661311, which made it both false and irrelevant. Noted while looking at SQL function plancache patch. Branch -- master Details --- https://git.postgresql.org/pg/commitdiff/1c9242b2cdc358b8be9c4e9967823a24a7807525 Mo

pgsql: Fix ARRAY_SUBLINK and ARRAY[] for int2vector and oidvector input

2025-03-15 Thread Tom Lane
Fix ARRAY_SUBLINK and ARRAY[] for int2vector and oidvector input. If the given input_type yields valid results from both get_element_type and get_array_type, initArrayResultAny believed the former and treated the input as an array type. However this is inconsistent with what get_promoted_array_ty

pgsql: Fix a few more redundant calls of GetLatestSnapshot()

2025-03-15 Thread Heikki Linnakangas
Fix a few more redundant calls of GetLatestSnapshot() Commit 2367503177 fixed this in RelationFindReplTupleByIndex(), but I missed two other similar cases. Per report from Ranier Vilela. Discussion: https://www.postgresql.org/message-id/caeudqarut1de45wn87f-gb7xmy_hw6x1dfd3sqdhhxp-rmd...@mail.g

pgsql: CREATE INDEX: do update index stats if autovacuum=off.

2025-03-15 Thread Tom Lane
CREATE INDEX: do update index stats if autovacuum=off. This fixes a thinko from commit d611f8b15. The intent was to prevent updating the stats of the pre-existing heap if autovacuum is off, but it also disabled updating the stats of the just-created index. There is AFAICS no good reason to do the

pgsql: Organize and deduplicate statistics import tests.

2025-03-15 Thread Jeff Davis
Organize and deduplicate statistics import tests. Author: Corey Huinker Reported-by: Melanie Plageman Discussion: https://postgr.es/m/CAAKRu_bWEqUfxhODfJ-XbZC75vq=P6DYOKK6biyey=ym1ah...@mail.gmail.com Discussion: https://postgr.es/m/CADkLM=f1n2_Vomq0gKab7xdxDHmJGgn=de48p8fzqop3mrs...@mail.gmai

pgsql: Remove table AM callback scan_bitmap_next_block

2025-03-15 Thread Melanie Plageman
Remove table AM callback scan_bitmap_next_block After pushing the bitmap iterator into table-AM specific code (as part of making bitmap heap scan use the read stream API in 2b73a8cd33b7), scan_bitmap_next_block() no longer returns the current block number. Since scan_bitmap_next_block() isn't retu

pgsql: Separate TBM[Shared|Private]Iterator and TBMIterateResult

2025-03-15 Thread Melanie Plageman
Separate TBM[Shared|Private]Iterator and TBMIterateResult Remove the TBMIterateResult member from the TBMPrivateIterator and TBMSharedIterator and make tbm_[shared|private_]iterate() take a TBMIterateResult as a parameter. This allows tidbitmap API users to manage multiple TBMIterateResults per s

pgsql: BitmapHeapScan uses the read stream API

2025-03-15 Thread Melanie Plageman
BitmapHeapScan uses the read stream API Make Bitmap Heap Scan use the read stream API instead of invoking ReadBuffer() for each block indicated by the bitmap. The read stream API handles prefetching, so remove all of the explicit prefetching from bitmap heap scan code. Now, heap table AM impleme

pgsql: Simplify distance heuristics in read_stream.c.

2025-03-15 Thread Thomas Munro
Simplify distance heuristics in read_stream.c. Make the distance control heuristics simpler and more aggressive in preparation for asynchronous I/O. The v17 version of read_stream.c made a conservative choice to limit the look-ahead distance when streaming sequential blocks, because it couldn't b