Re: pgsql: Add assert checking to pg_leftmost_one_pos32() and friends

2023-02-20 Thread John Naylor
On Mon, Feb 20, 2023 at 10:17 PM Tom Lane wrote: > > John Naylor writes: > > Add assert checking to pg_leftmost_one_pos32() and friends > > I can see that this was worth writing for testing purposes, but > is it really worth carrying permanently? Even in a debug build, > the ratio of cycles expe

pgsql: Detect overflow in timestamp[tz] subtraction.

2023-02-20 Thread Tom Lane
Detect overflow in timestamp[tz] subtraction. It's possible to overflow the int64 microseconds field of the output interval when subtracting two timestamps. Detect that instead of silently returning a bogus result. Nick Babadzhanian Discussion: https://postgr.es/m/cabw73uq2oj3e+kyvvduy04ekhhkc

pgsql: Fix parsing of ISO-8601 interval fields with exponential notatio

2023-02-20 Thread Tom Lane
Fix parsing of ISO-8601 interval fields with exponential notation. Historically we've accepted interval input like 'P.1e10D'. This is probably an accident of having used strtod() to do the parsing, rather than something anyone intended, but it's been that way for a long time. Commit e39f99046 br

pgsql: Fix parsing of ISO-8601 interval fields with exponential notatio

2023-02-20 Thread Tom Lane
Fix parsing of ISO-8601 interval fields with exponential notation. Historically we've accepted interval input like 'P.1e10D'. This is probably an accident of having used strtod() to do the parsing, rather than something anyone intended, but it's been that way for a long time. Commit e39f99046 br

pgsql: Prevent join removal from removing the query's result relation.

2023-02-20 Thread Tom Lane
Prevent join removal from removing the query's result relation. This was not something that required consideration before MERGE was invented; but MERGE builds a join tree that left-joins to the result relation, meaning that remove_useless_joins will consider removing it. That should generally be

pgsql: Prevent join removal from removing the query's result relation.

2023-02-20 Thread Tom Lane
Prevent join removal from removing the query's result relation. This was not something that required consideration before MERGE was invented; but MERGE builds a join tree that left-joins to the result relation, meaning that remove_useless_joins will consider removing it. That should generally be

pgsql: Limit memory usage of pg_walinspect functions.

2023-02-20 Thread Jeff Davis
Limit memory usage of pg_walinspect functions. GetWALRecordsInfo() and pg_get_wal_fpi_info() can leak memory across WAL record iterations. Fix this by using a temporary memory context that's reset for each WAL record iteraion. Also use a temporary context for loops in GetXLogSummaryStats(). The n

pgsql: Limit memory usage of pg_walinspect functions.

2023-02-20 Thread Jeff Davis
Limit memory usage of pg_walinspect functions. GetWALRecordsInfo() and pg_get_wal_fpi_info() can leak memory across WAL record iterations. Fix this by using a temporary memory context that's reset for each WAL record iteraion. Also a use temporary context for loops in GetXLogSummaryStats(). The n

pgsql: Remove gratuitous assumptions about what make_modifytable can se

2023-02-20 Thread Tom Lane
Remove gratuitous assumptions about what make_modifytable can see. For no clearly good reason, make_modifytable assumed that it could not reach its get-the-FDW-info-the-hard-way path in MERGE. It's currently possible to demonstrate that assertion failing, which seems to be due to an upstream plann

Re: pgsql: Add assert checking to pg_leftmost_one_pos32() and friends

2023-02-20 Thread Tom Lane
John Naylor writes: > Add assert checking to pg_leftmost_one_pos32() and friends I can see that this was worth writing for testing purposes, but is it really worth carrying permanently? Even in a debug build, the ratio of cycles expended to chances of finding a problem seems mighty poor, and you

pgsql: Correctly set userid of subquery relations' child rels

2023-02-20 Thread Alvaro Herrera
Correctly set userid of subquery relations' child rels The RelOptInfo->userid field (the user ID to check permissions as) of an "otherrel" relation was being copied from its parent relation, which is correct in most cases but wrong when the parent is a subquery. In that case, using the value from

pgsql: Optimize generate_orderedappend_paths

2023-02-20 Thread David Rowley
Optimize generate_orderedappend_paths In generate_orderedappend_paths(), when match_partition_order_desc was true, we would lcons() items to various lists in a loop over each live partition. When the number of live partitions was large, the lcons() could show up in profiles due to it having to pe

pgsql: Add MSVC support for pg_leftmost_one_pos32() and friends

2023-02-20 Thread John Naylor
Add MSVC support for pg_leftmost_one_pos32() and friends To allow testing for general support for fast bitscan intrinsics, add symbols HAVE_BITSCAN_REVERSE and HAVE_BITSCAN_FORWARD. Also do related cleanup in AllocSetFreeIndex(): Previously, we tested for HAVE__BUILTIN_CLZ and copied the relevant