users/rhaas/postgres.git
2 days agostart of flag-based reporting advice_unstable
Robert Haas [Mon, 29 Sep 2025 19:20:10 +0000 (15:20 -0400)]
start of flag-based reporting

currently this only works for the join path hook, not the join rel
or scan hook

the results are emitted as warnings instead of being properly
structured

i have a feeling that there needs to be more interaction between
the join path stuff and the join rel stuff - e.g. PARTITIONWISE((a b))
conflicts with HASH_JOIN(b) but I don't think the current code can
detect that

we also need to split off the stuff that gets handled in the join
rel hook from a trove POV, to avoid making duplicate entries that
will confuse this reporting

an incidental note is that i think we should teach the advice
parser to ignore comments, so that we can emit something that looks
like a comment as a report, e.g.
   JOIN_ORDER(a b) /* matched, conflicted */
   JOIN_ORDER(a b) /* partial match only */
   JOIN_ORDER(a b) /* not matched */
   INDEX_SCAN(this that_idx) /* matched, inapplicable */

2 days agofix comment
Robert Haas [Mon, 29 Sep 2025 15:59:50 +0000 (11:59 -0400)]
fix comment

2 days agofix arguments to planner_setup_hook
Robert Haas [Mon, 29 Sep 2025 15:55:20 +0000 (11:55 -0400)]
fix arguments to planner_setup_hook

2 days agoupdate comment
Robert Haas [Mon, 29 Sep 2025 15:27:03 +0000 (11:27 -0400)]
update comment

5 days agofix indentation
Robert Haas [Fri, 26 Sep 2025 19:14:17 +0000 (15:14 -0400)]
fix indentation

5 days agocompensate for Richard
Robert Haas [Fri, 26 Sep 2025 19:13:46 +0000 (15:13 -0400)]
compensate for Richard

5 days agofix array overrun
Robert Haas [Fri, 26 Sep 2025 18:30:13 +0000 (14:30 -0400)]
fix array overrun

5 days agostab in the dark to cope with LWLockNewTrancheId signature change
Robert Haas [Fri, 26 Sep 2025 16:15:34 +0000 (12:15 -0400)]
stab in the dark to cope with LWLockNewTrancheId signature change

5 days agoadd a TODO
Robert Haas [Fri, 5 Sep 2025 12:24:50 +0000 (08:24 -0400)]
add a TODO

5 days agofix a bug in the NO_GATHER advice
Robert Haas [Thu, 4 Sep 2025 19:21:24 +0000 (15:21 -0400)]
fix a bug in the NO_GATHER advice

5 days agoNO_GATHER advice
Robert Haas [Thu, 4 Sep 2025 18:55:19 +0000 (14:55 -0400)]
NO_GATHER advice

5 days agomove comment
Robert Haas [Thu, 4 Sep 2025 16:53:31 +0000 (12:53 -0400)]
move comment

5 days agoAdd NO_GATHER and tidy up a few things.
Robert Haas [Thu, 4 Sep 2025 16:34:26 +0000 (12:34 -0400)]
Add NO_GATHER and tidy up a few things.

5 days agoupdate README for PARTITIONWISE, GATHER, GATHER_MERGE, and the
Robert Haas [Fri, 29 Aug 2025 20:29:42 +0000 (16:29 -0400)]
update README for PARTITIONWISE, GATHER, GATHER_MERGE, and the
presently-phantom NO_GATHER

5 days agocrude changes for Gather(Merge)
Robert Haas [Fri, 29 Aug 2025 19:06:27 +0000 (15:06 -0400)]
crude changes for Gather(Merge)

5 days agoinvented PGS_CONSIDER_NONPARTIAL
Robert Haas [Fri, 29 Aug 2025 17:34:28 +0000 (13:34 -0400)]
invented PGS_CONSIDER_NONPARTIAL

5 days agoget partitionwise hints working
Robert Haas [Fri, 29 Aug 2025 12:38:43 +0000 (08:38 -0400)]
get partitionwise hints working

5 days agoreindent, inject pgpa_joinrel_setup
Robert Haas [Thu, 28 Aug 2025 17:41:59 +0000 (13:41 -0400)]
reindent, inject pgpa_joinrel_setup

5 days agoinvent pgpa_join_state
Robert Haas [Thu, 28 Aug 2025 17:31:21 +0000 (13:31 -0400)]
invent pgpa_join_state

5 days agomechanical adjustments for jsa/ssa->pgs
Robert Haas [Thu, 28 Aug 2025 15:33:32 +0000 (11:33 -0400)]
mechanical adjustments for jsa/ssa->pgs

5 days agoAdapt for new hooks.
Robert Haas [Mon, 25 Aug 2025 17:06:29 +0000 (13:06 -0400)]
Adapt for new hooks.

5 days agoWIP: Add pg_plan_advice contrib module.
Robert Haas [Wed, 20 Aug 2025 19:20:31 +0000 (15:20 -0400)]
WIP: Add pg_plan_advice contrib module.

Provide a facility that (1) can be used to stabilize certain plan choices
so that the planner cannot reverse course without authorization and
(2) can be used by knowledgeable users to insist on plan choices contrary
to what the planner believes best. In both cases, terrible outcomes are
possible: users should think twice and perhaps three times before
constraining the planner's ability to do as it thinks best; nevertheless,
there are problems that are much more easily solved with these facilities
than without them.

We take the approach of analyzing a finished plan to produce textual
output, which we call "plan advice", that describes key decisions made
during plan; if that plan advice is provided during future planning
cycles, it will force those key decisions to be made in the same way.
Not all planner decisions can be controlled using advice; for example,
decisions about how to perform aggregation are currently out of scope,
as is choice of sort order. Plan advice can also be edited by the user,
or even written from scratch in simple cases, making it possible to
generate outcomes that the planner would not have produced. Partial
advice can be provided to control some planner outcomes but not others.

Currently, plan advice is focused only on specific outcomes, such as
the choice to use a sequential scan for a particular relation, and not
on estimates that might contribute to those outcomes, such as a
possibly-incorrect selectivity estimate. While it might be useful to
users to be able to provide plan advice that affects selectivity
estimates or other aspects of costing, that is out of scope for this
commit.

For more details, see contrib/pg_plan_advice/README.

NOTE: This code is currently incomplete, and some of what exists is
incorrect. Both advice generation and advice application have
singnificant gaps, many of which are called out by XXX in the comments.
There is currently no docmentation other than the README, and no test
cases. It should be considered early PoC quality.

5 days agoAllow for plugin control over path generation strategies.
Robert Haas [Thu, 28 Aug 2025 14:58:45 +0000 (10:58 -0400)]
Allow for plugin control over path generation strategies.

Each RelOptInfo now has a pgs_mask member which is a mask of acceptable
strategies. For child rels, this is populated from the parent rel; else,
it's populated from PlannerGlobal's default_pgs_mask, which is computed
from the values of the enable_* GUCs at the start of planning.

For baserels, get_relation_info_hook can be used to adjust pgs_mask for
each new RelOptInfo, at least for rels of type RTE_RELATION. Adjusting
pgs_mask is less useful for other types of rels, but if it proves to
be necessary, we can revisit the way this hook works or add a new one.

For joinrels, two new hooks are added. joinrel_setup_hook is called each
time a joinrel is created, and one thing that can be done from that hook
is to manipulate pgs_mask for the new joinrel. join_path_setup_hook is
called each time we're about to add paths to a joinrel by considering
some particular combination of an outer rel, an inner rel, and a join
type. It can modify the pgs_mask propagated into JoinPathExtraData to
restrict strategy choice for that paricular combination of rels.

To make joinrel_setup_hook work as intended, the existing calls to
build_joinrel_partition_info are moved later in the calling functions;
this is because that function checks whether the rel's pgs_mask includes
PGS_CONSIDER_PARTITIONWISE, so we want it to only be called after
plugins have had a chance to alter pgs_mask.

5 days agoStore information about Append node consolidation in the final plan.
Robert Haas [Mon, 21 Jul 2025 19:49:06 +0000 (15:49 -0400)]
Store information about Append node consolidation in the final plan.

When we build an AppendPath or MergeAppendPath, we sometimes pull all
child paths from a subordinate AppendPath or MergeAppendPath instead
of having one such path atop another. This results in the RTIs that
would have been associated with the subordinate path disappearing
from the final plan, making things difficult for code that wants
to scrutinize the final plan and extract information from it about
what happened during the planning process.

To avoid this, propagate the RTI sets that would have been present
in the 'apprelids' field of the subordinate Append or MergeAppend
nodes that would have been created into the surviving Append or
MergeAppend node, using a new 'child_append_relid_sets' field for
that purpose.

This commit also updates pg_overexplain to display these details.

5 days agoStore information about elided nodes in the final plan.
Robert Haas [Tue, 22 Apr 2025 18:10:19 +0000 (14:10 -0400)]
Store information about elided nodes in the final plan.

When setrefs.c removes a SubqueryScan, single-child Append, or
single-child MergeAppend from the final Plan tree, the RTI which
would have been scanned by the removed node no longer appears in
the final plan (the actual range table entry is still present,
but it's no longer referenced).

That's fine for the executor, but it can create difficulties for
code that wants to deduce from the final plan what choices were
made during the planing process. For example, a traversal of a
join tree in the final plan might never encounter the RTI of one
of the relationss in the join problem, and might instead encounter
a scan of a child RTI or even one from a different subquery level.

This patch adjusts things so that each time we elide a node during
setrefs processing, we record the plan_node_id of its single surviving
child, the type of the removed node, and the RTIs that the removed
node would have scanned. This information is recorded in a separate
list that can be ignored by the executor and examined only by code
that cares about these details.

This commit also updates pg_overexplain to display these details.

5 days agoStore information about range-table flattening in the final plan.
Robert Haas [Wed, 24 Sep 2025 14:06:59 +0000 (10:06 -0400)]
Store information about range-table flattening in the final plan.

During planning, there is one range table per subquery; at the end if
planning, those separate range tables are flattened into a single
range table. Prior to this change, it was impractical for code
examining the final plan to understand which parts of the flattened
range table came from which subquery's range table.

If the only consumer of the final plan is the executor, that is
completely fine. However, if some code wants to examine the final
plan, or what happens when we execute it, and extract information from
it that be used in future planning cycles, it's inconvenient.  So,
this commit remembers in the final plan which part of the final range
table came from which subquery's range table.

Additionally, this commit teaches pg_overexplain'e RANGE_TABLE option
to display the subquery name for each range table entry.

5 days agoAssign each subquery a unique name prior to planning it.
Robert Haas [Fri, 26 Sep 2025 14:45:18 +0000 (10:45 -0400)]
Assign each subquery a unique name prior to planning it.

Previously, subqueries were given names only after they were planned,
which makes it difficult to use information from a previous execution of
the query to guide future planning. If, for example, you knew something
about how you want "InitPlan 2" to be planned, you won't know whether
the subquery you're currently planning will end up being "InitPlan 2"
until after you've finished planning it, by which point it's too late to
use the information that you had.

To fix this, assign each subplan a unique name before we begin planning
it. To improve consistency, use textual names for all subplans, rather
than, as we did previously, a mix of numbers (such as "InitPlan 1") and
names (such as "CTE foo"), and make sure that the same name is never
assigned more than once.

We adopt the somewhat arbitrary convention of using the type of sublink
to set the plan name; for example, a query that previously had two
expression sublinks shown as InitPlan 2 and InitPlan 1 will now end up
named expr_1 and expr_2. Because names are assigned before rather than
after planning, some of the regression test outputs show the numerical
part of the name switching positions: what was previously SubPlan 2 was
actually the first one encountered, but we finished planning it later.

We assign names even to subqueries that aren't shown as such within the
EXPLAIN output. These include subqueries that are a FROM clause item or
a branch of a set operation, rather than something that will be turned
into an InitPlan or SubPlan. The purpose of this is to make sure that,
below the topmost query level, there's always a name for each subquery
that is stable from one planning cycle to the next (assuming no changes
to the query or the database schema).

Author: Robert Haas <[email protected]>
Co-authored-by: Tom Lane <[email protected]>
Reviewed-by: Alexandra Wang <[email protected]>
Reviewed-by: Richard Guo <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Reviewed-by: Junwang Zhao <[email protected]>
Discussion: http://postgr.es/m/3641043.1758751399@sss.pgh.pa.us

6 days agoAdd extension_state member to PlannedStmt.
Robert Haas [Mon, 25 Aug 2025 18:29:02 +0000 (14:29 -0400)]
Add extension_state member to PlannedStmt.

Extensions can stash data computed at plan time into this list using
planner_shutdown_hook (or perhaps other mechanisms) and then access
it from any code that has access to the PlannedStmt (such as explain
hooks), allowing for extensible debugging and instrumentation of
plans.

6 days agoAdd planner_setup_hook and planner_shutdown_hook.
Robert Haas [Wed, 24 Sep 2025 15:21:55 +0000 (11:21 -0400)]
Add planner_setup_hook and planner_shutdown_hook.

These hooks allow plugins to get control at the earliest point at
which the PlannerGlobal object is fully initialized, and then just
before it gets destroyed. This is useful in combination with the
extendable plan state facilities (see extendplan.h) and perhaps for
other purposes as well.

6 days agoAdd ExplainState argument to pg_plan_query() and planner().
Robert Haas [Wed, 24 Sep 2025 15:18:12 +0000 (11:18 -0400)]
Add ExplainState argument to pg_plan_query() and planner().

This allows extensions to have access to any data they've stored
in the ExplainState during planning. Unfortunately, it won't help
with EXPLAIN EXECUTE is used, but since that case is less common,
this still seems like an improvement.

6 days agoRemove PlannerInfo's join_search_private method.
Robert Haas [Wed, 20 Aug 2025 19:10:52 +0000 (15:10 -0400)]
Remove PlannerInfo's join_search_private method.

Instead, use the new mechanism that allows planner extensions to store
private state inside a PlannerInfo, treating GEQO as an in-core planner
extension.  This is a useful test of the new facility, and also buys
back a few bytes of storage.

To make this work, we must remove innerrel_is_unique_ext's hack of
testing whether join_search_private is set as a proxy for whether
the join search might be retried. Add a flag that extensions can
use to explicitly signal their intentions instead.

6 days agoAllow private state in certain planner data structures.
Robert Haas [Wed, 24 Sep 2025 15:00:07 +0000 (11:00 -0400)]
Allow private state in certain planner data structures.

Extension that make extensive use of planner hooks may want to
coordinate their efforts, for example to avoid duplicate computation,
but that's currently difficult because there's no really good way to
pass data between different hooks.

To make that easier, allow for storage of extension-managed private
state in PlannerGlobal, PlannerInfo, and RelOptInfo, along very
similar lines to what we have permitted for ExplainState since commit
c65bc2e1d14a2d4daed7c1921ac518f2c5ac3d17.

6 days agoFix array allocation bugs in SetExplainExtensionState.
Robert Haas [Thu, 25 Sep 2025 15:43:52 +0000 (11:43 -0400)]
Fix array allocation bugs in SetExplainExtensionState.

If we already have an extension_state array but see a new extension_id
much larger than the highest the extension_id we've previously seen,
the old code might have failed to expand the array to a large enough
size, leading to disaster. Also, if we don't have an extension array
at all and need to create one, we should make sure that it's big enough
that we don't have to resize it instantly.

Reported-by: Tom Lane <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Discussion: http://postgr.es/m/2949591.1758570711@sss.pgh.pa.us
Backpatch-through: 18

6 days agoDoc: clean up documentation for new UUID functions.
Tom Lane [Thu, 25 Sep 2025 15:23:27 +0000 (11:23 -0400)]
Doc: clean up documentation for new UUID functions.

Fix assorted failures to conform to our normal style for function
documentation, such as lack of parentheses and incorrect markup.

Author: Marcos Pegoraro <[email protected]>
Co-authored-by: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/CAB-JLwbocrFjKfGHoKY43pHTf49Ca2O0j3WVebC8z-eQBMPJyw@mail.gmail.com
Backpatch-through: 18

6 days agoTeach doc/src/sgml/Makefile about the new func/*.sgml files.
Tom Lane [Thu, 25 Sep 2025 15:09:26 +0000 (11:09 -0400)]
Teach doc/src/sgml/Makefile about the new func/*.sgml files.

These were omitted from build dependencies and also tab/nbsp
checks, with the result that "make" did nothing after modifying
a func/*.sgml file.

Oversight in 4e23c9ef6.  AFAICT we don't need any comparable
changes in meson.build, or at least I don't see it doing anything
special for the pre-existing ref/*.sgml files.

6 days agoRemove preprocessor guards from injection points
Daniel Gustafsson [Thu, 25 Sep 2025 13:27:33 +0000 (15:27 +0200)]
Remove preprocessor guards from injection points

When defining an injection point there is no need to wrap the definition
with USE_INJECTION_POINT guards, the INJECTION_POINT macro is available
in all builds.  Remove to make the code consistent.

Author: Hayato Kuroda <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Reviewed-by: Daniel Gustafsson <[email protected]>
Discussion: https://postgr.es/m/OSCPR01MB14966C8015DEB05ABEF2CE077F51FA@OSCPR01MB14966.jpnprd01.prod.outlook.com
Backpatch-through: 17

6 days agoFix comments in recovery tests
Daniel Gustafsson [Thu, 25 Sep 2025 13:24:41 +0000 (15:24 +0200)]
Fix comments in recovery tests

Commit 4464fddf removed the large insertions but missed to remove
all the comments referring to them.  Also remove a superfluous ')'
in another comment.

Author: Hayato Kuroda <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Reviewed-by: Daniel Gustafsson <[email protected]>
Discussion: https://postgr.es/m/OSCPR01MB149663A99DAF2826BE691C23DF51FA@OSCPR01MB14966.jpnprd01.prod.outlook.com

6 days agoDon't include execnodes.h in replication/conflict.h
Álvaro Herrera [Thu, 25 Sep 2025 12:45:08 +0000 (14:45 +0200)]
Don't include execnodes.h in replication/conflict.h

... which silently propagates a lot of headers into many places
via pgstat.h, as evidenced by the variety of headers that this patch
needs to add to seemingly random places.  Add a minimum of typedefs to
conflict.h to be able to remove execnodes.h, and fix the fallout.

Backpatch to 18, where conflict.h first appeared.

Discussion: https://postgr.es/m/202509191927[email protected]

6 days agoUpdate some more forward declarations to use typedef
Álvaro Herrera [Thu, 25 Sep 2025 12:33:19 +0000 (14:33 +0200)]
Update some more forward declarations to use typedef

As commit d4d1fc527bdb.

Reviewed-by: Peter Eisentraut <[email protected]>
Discussion: https://postgr.es/m/202509191025[email protected]

7 days agopgbench: Fix typo in documentation.
Fujii Masao [Thu, 25 Sep 2025 05:06:12 +0000 (14:06 +0900)]
pgbench: Fix typo in documentation.

This commit fixes a typo introduced in commit b6290ea48e1.

Reported off-list by Erik Rijkers <[email protected]>

7 days agopgbench: Clarify documentation for \gset and \aset.
Fujii Masao [Thu, 25 Sep 2025 03:09:32 +0000 (12:09 +0900)]
pgbench: Clarify documentation for \gset and \aset.

This commit updates the pgbench documentation to list \gset and \aset
as separate terms for easier reading. It also clarifies that \gset raises
an error if the query returns zero or multiple rows, and explains how to
detect cases where the query with \aset returned no rows.

Author: Yugo Nagata <[email protected]>
Reviewed-by: Fujii Masao <[email protected]>
Discussion: https://postgr.es/m/20250626180125.5b896902a3d0bcd93f86c240@sraoss.co.jp

7 days agovacuumdb: Do not run VACUUM (ONLY_DATABASE_STATS) when --analyze-only.
Fujii Masao [Wed, 24 Sep 2025 16:38:54 +0000 (01:38 +0900)]
vacuumdb: Do not run VACUUM (ONLY_DATABASE_STATS) when --analyze-only.

Previously, vacuumdb --analyze-only issued VACUUM (ONLY_DATABASE_STATS)
at the end. Since --analyze-only is meant to update optimizer statistics only,
this extra VACUUM command is unnecessary.

This commit prevents vacuumdb --analyze-only from running that redundant
VACUUM command.

Author: Fujii Masao <[email protected]>
Reviewed-by: Mircea Cadariu <[email protected]>
Discussion: https://postgr.es/m/CAHGQGwEqHGa-k=wbRMucUVihHVXk4NQkK94GNN=ym9cQ5HBSHg@mail.gmail.com

7 days agoCorrect prune WAL record opcode name in comment
Melanie Plageman [Wed, 24 Sep 2025 16:29:13 +0000 (12:29 -0400)]
Correct prune WAL record opcode name in comment

f83d709760d8 incorrectly refers to a XLOG_HEAP2_PRUNE_FREEZE WAL record
opcode. No such code exists. The relevant opcodes are
XLOG_HEAP2_PRUNE_ON_ACCESS, XLOG_HEAP2_PRUNE_VACUUM_SCAN, and
XLOG_HEAP2_PRUNE_VACUUM_CLEANUP. Correct it.

Author: Melanie Plageman <[email protected]>
Reviewed-by: Andres Freund <[email protected]>
Discussion: https://postgr.es/m/yn4zp35kkdsjx6wf47zcfmxgexxt4h2og47pvnw2x5ifyrs3qc%407uw6jyyxuyf7

7 days agoEnsure guc_tables.o's dependency on guc_tables.inc.c is known.
Tom Lane [Wed, 24 Sep 2025 16:28:20 +0000 (12:28 -0400)]
Ensure guc_tables.o's dependency on guc_tables.inc.c is known.

Without this, rebuilds can malfunction unless --enable-depend is used.
Historically we've expected that you can get away without
--enable-depend as long as you manually clean after changing *.h
files; the makefiles are supposed to handle other sorts of
dependencies.  So add this one.

Follow-on to 635998965, so no need for back-patch.

Discussion: https://postgr.es/m/3121329.1758650878@sss.pgh.pa.us

7 days agoInclude pg_test_timing's full output in the TAP test log.
Tom Lane [Wed, 24 Sep 2025 16:08:55 +0000 (12:08 -0400)]
Include pg_test_timing's full output in the TAP test log.

We were already doing a short (1-second) pg_test_timing run during
check-world and buildfarm runs.  But we weren't doing anything
with the result except for a basic regex-based sanity check.
Collecting that output from buildfarm runs is seeming very
attractive though, because it would help us determine what sort
of timing resolution is available on supported platforms.
It's not very long, so let's just note it verbatim in the TAP log.

Discussion: https://postgr.es/m/3321785.1758728271@sss.pgh.pa.us

7 days agoFix incorrect and inconsistent comments in tableam.h and heapam.c.
Fujii Masao [Wed, 24 Sep 2025 15:51:59 +0000 (00:51 +0900)]
Fix incorrect and inconsistent comments in tableam.h and heapam.c.

This commit corrects several issues in function comments:

* The parameter "rel" was incorrectly referred to as "relation" in the comments
   for table_tuple_delete(), table_tuple_update(), and table_tuple_lock().
* In table_tuple_delete(), "changingPart" was listed as an output parameter
   in the comments but is actually input.
* In table_tuple_update(), "slot" was listed as an input parameter
   in the comments but is actually output.
* The comment for "update_indexes" in table_tuple_update() was mis-indented.
* The comments for heap_lock_tuple() incorrectly referenced a non-existent
   "tid" parameter.

Author: Chao Li <[email protected]>
Reviewed-by: Fujii Masao <[email protected]>
Discussion: https://postgr.es/m/CAEoWx2nB6Ay8g=KEn7L3qbYX_4+sLk9XOMkV0XZqHR4cTY8ZvQ@mail.gmail.com

7 days agoRemove PointerIsValid()
Peter Eisentraut [Wed, 24 Sep 2025 13:14:06 +0000 (15:14 +0200)]
Remove PointerIsValid()

This doesn't provide any value over the standard style of checking the
pointer directly or comparing against NULL.

Also remove related:
- AllocPointerIsValid() [unused]
- IndexScanIsValid() [had one user]
- HeapScanIsValid() [unused]
- InvalidRelation [unused]

Leaving HeapTupleIsValid(), ItemIdIsValid(), PortalIsValid(),
RelationIsValid for now, to reduce code churn.

Reviewed-by: Jacob Champion <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/ad50ab6b-6f74-4603-b099-1cd6382fb13d%40eisentraut.org
Discussion: https://www.postgresql.org/message-id/CA+hUKG+NFKnr=K4oybwDvT35dW=VAjAAfiuLxp+5JeZSOV3nBg@mail.gmail.com
Discussion: https://www.postgresql.org/message-id/bccf2803-5252-47c2-9ff0-340502d5bd1c@iki.fi

7 days agoFix incorrect option name in usage screen
Daniel Gustafsson [Wed, 24 Sep 2025 12:58:18 +0000 (14:58 +0200)]
Fix incorrect option name in usage screen

The usage screen incorrectly refered to the --docs option as --sgml.
Backpatch down to v17 where this script was introduced.

Author: Daniel Gustafsson <[email protected]>
Discussion: https://postgr.es/m/20250729.135638.1148639539103758555[email protected]
Backpatch-through: 17

7 days agoConsistently handle tab delimiters for wait event names
Daniel Gustafsson [Wed, 24 Sep 2025 12:57:26 +0000 (14:57 +0200)]
Consistently handle tab delimiters for wait event names

Format validation and element extraction for intermediate line
strings were inconsistent in their handling of tab delimiters,
which resulted in an unclear error when multiple tab characters
were used as a delimiter.  This fixes it by using captures from
the validation regex instead of a separate split() to avoid the
inconsistency.  Also, it ensures that \t+ is used consistently
when inspecting the strings.

Author: Kyotaro Horiguchi <[email protected]>
Reviewed-by: Daniel Gustafsson <[email protected]>
Discussion: https://postgr.es/m/20250729.135638.1148639539103758555[email protected]

8 days agoUpdate GB18030 encoding from version 2000 to 2022
John Naylor [Wed, 24 Sep 2025 06:26:05 +0000 (13:26 +0700)]
Update GB18030 encoding from version 2000 to 2022

Mappings for 18 characters have changed, affecting 36 code points. This
is a break in compatibility, but these characters are rarely used.

U+E5E5 (Private Use Area) was previously mapped to \xA3A0. This code
point now maps to \x65356535. Attempting to convert \xA3A0 will now
raise an error.

Separate from the 2022 update, the following mappings were previously
swapped, and subsequently corrected in 2000 and later versions:
 * U+E7C7 (Private Use Area) now maps to \x8135F437
 * U+1E3F (Latin Small Letter M with Acute) now maps to \xA8BC

The 2022 standard mentions the following policy changes, but they
have no effect in our implementation:

66 new ideographs are now required, but these are mapped
algorithmically so were already handled by utf8_and_gb18030.c.

Nine CJK compatibility ideographs are no longer required, but
implementations may retain them, as does the source we use from
the Unicode Consortium.

Release notes: Compatibility section

For further details, see:
https://www.unicode.org/L2/L2022/22274-disruptive-changes.pdf
https://ken-lunde.medium.com/the-gb-18030-2022-standard-3d0ebaeb4132

Author: Chao Li <[email protected]>
Author: Zheng Tao <[email protected]>
Discussion: https://postgr.es/m/966d9fc.169.198741fe60b.Coremail.jiaoshuntian%40highgo.com

8 days agoFix LOCK_TIMEOUT handling during parallel apply.
Amit Kapila [Wed, 24 Sep 2025 04:11:53 +0000 (04:11 +0000)]
Fix LOCK_TIMEOUT handling during parallel apply.

Previously, the parallel apply worker used SIGINT to receive a graceful
shutdown signal from the leader apply worker. However, SIGINT is also used
by the LOCK_TIMEOUT handler to trigger a query-cancel interrupt. This
overlap caused the parallel apply worker to miss LOCK_TIMEOUT signals,
leading to incorrect behavior during lock wait/contention.

This patch resolves the conflict by switching the graceful shutdown signal
from SIGINT to SIGUSR2.

Reported-by: Zane Duffield <[email protected]>
Diagnosed-by: Zhijie Hou <[email protected]>
Author: Hayato Kuroda <[email protected]>
Reviewed-by: Amit Kapila <[email protected]>
Backpatch-through: 16, where it was introduced
Discussion: https://postgr.es/m/CACMiCkXyC4au74kvE2g6Y=mCEF8X6r-Ne_ty4r7qWkUjRE4+oQ@mail.gmail.com

8 days agoFix compiler warnings in test_bitmapset
Michael Paquier [Tue, 23 Sep 2025 23:20:23 +0000 (08:20 +0900)]
Fix compiler warnings in test_bitmapset

The macros doing conversions of/from "text" from/to Bitmapset were using
arbitrary casts with Datum, something that is not fine since
2a600a93c7be.

These macros do not actually need casts with Datum, as they are given
already "text" and Bitmapset data in input.  They are updated to use
cstring_to_text() and text_to_cstring(), fixing the compiler warnings
reported by the buildfarm.  Note that appending a -m32 to gcc to trigger
32-bit builds was enough to reproduce the warnings here.

While on it, outer parenthesis are added to TEXT_TO_BITMAPSET(), and
inner parenthesis are removed from BITMAPSET_TO_TEXT(), to make these
macros more consistent with the style used in the tree, based on
suggestions by Tom Lane.

Oversights in commit 00c3d87a5cab.

Reported-by: Tom Lane <[email protected]>
Author: Greg Burd <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Discussion: https://postgr.es/m/3027069.1758606227@sss.pgh.pa.us

8 days agoKeep track of what RTIs a Result node is scanning.
Robert Haas [Tue, 23 Sep 2025 13:07:55 +0000 (09:07 -0400)]
Keep track of what RTIs a Result node is scanning.

Result nodes now include an RTI set, which is only non-NULL when they
have no subplan, and is taken from the relid set of the RelOptInfo that
the Result is generating. ExplainPreScanNode now takes notice of these
RTIs, which means that a few things get schema-qualified in the
regression tests that previously did not. This makes the output more
consistent between cases where some part of the plan tree is replaced by
a Result node and those where this does not happen.

Likewise, pg_overexplain's EXPLAIN (RANGE_TABLE) now displays the RTIs
stored in a Result node just as it already does for other RTI-bearing
node types.

Result nodes also now include a result_reason, which tells us something
about why the Result node was inserted.  Using that information, EXPLAIN
now emits, where relevant, a "Replaces" line describing the origin of
a Result node.

The purpose of these changes is to allow code that inspects a Plan
tree to understand the origin of Result nodes that appear therein.

Discussion: http://postgr.es/m/CA+TgmoYeUZePZWLsSO+1FAN7UPePT_RMEZBKkqYBJVCF1s60=w@mail.gmail.com
Reviewed-by: Alexandra Wang <[email protected]>
Reviewed-by: Richard Guo <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Reviewed-by: Junwang Zhao <[email protected]>
10 days agodoc: Remove trailing whitespace in xref
Daniel Gustafsson [Mon, 22 Sep 2025 08:12:31 +0000 (10:12 +0200)]
doc: Remove trailing whitespace in xref

Remove stray whitespace in xref tag.

This was found due to a regression in xmllint 2.15.0 which flagged
this as an error, and at the time of this commit no fix for xmllint
has shipped.

Author: Erik Wienhold <[email protected]>
Discussion: https://postgr.es/m/f4c4661b-4e60-4c10-9336-768b7b55c084@ewie.name
Backpatch-through: 17

10 days agoAdd a test module for Bitmapset
Michael Paquier [Mon, 22 Sep 2025 07:53:00 +0000 (16:53 +0900)]
Add a test module for Bitmapset

Bitmapset has a complex set of APIs, defined in bitmapset.h, and it can
be hard to test edge cases with the backend core code only.

This test module is aimed at closing the gap, and implements a set of
SQL functions that act as wrappers of the low-level C functions of the
same names.  These functions rely on text as data type for the input and
the output as Bitmapset as a node has support for these.  An extra
function, named test_random_operations(), can be used to stress bitmaps
with random member values and a defined number of operations potentially
useful for other purposes than only tests.

The coverage increases from 85.2% to 93.4%.  It should be possible to
cover more code paths, but at least it's a beginning.

Author: Greg Burd <[email protected]>
Reviewed-by: Nathan Bossart <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Discussion: https://postgr.es/m/7BD1ABDB-B03A-464A-9BA9-A73B55AD8A1F@getmailspring.com

10 days agoFix various incorrect filename references
David Rowley [Mon, 22 Sep 2025 01:32:36 +0000 (13:32 +1200)]
Fix various incorrect filename references

Author: Chao Li <[email protected]>
Author: David Rowley <[email protected]>
Discussion: https://postgr.es/m/CAEoWx2=hOBCPm-Z=F15twr_23XjHeoXSbifP5GdEdtWona97wQ@mail.gmail.com

10 days agoFix misleading comment in RangeTblEntry
Richard Guo [Mon, 22 Sep 2025 01:04:39 +0000 (10:04 +0900)]
Fix misleading comment in RangeTblEntry

The comment describing join_using_alias incorrectly referred to the
alias field as being defined "below", when it actually appears earlier
in the RangeTblEntry struct.  This patch fixes that.

Author: Steve Lau <[email protected]>
Reviewed-by: Chao Li <[email protected]>
Discussion: https://postgr.es/m/TYWPR01MB10612B020C33FD08F729415CEB613A@TYWPR01MB10612.jpnprd01.prod.outlook.com

10 days agoFix meson build with -Duuid=ossp when using version older than 0.60
Michael Paquier [Sun, 21 Sep 2025 23:03:23 +0000 (08:03 +0900)]
Fix meson build with -Duuid=ossp when using version older than 0.60

The package for the UUID library may be named "uuid" or "ossp-uuid", and
meson.build has been using a single call of dependency() with multiple
names, something only supported since meson 0.60.0.

The minimum version of meson supported by Postgres is 0.57.2 on HEAD,
since f039c2244110, and 0.54 on stable branches down to 16.

Author: Oreo Yang <[email protected]>
Reviewed-by: Nazir Bilal Yavuz <[email protected]>
Discussion: https://postgr.es/m/OS3P301MB01656E6F91539770682B1E77E711A@OS3P301MB0165.JPNP301.PROD.OUTLOOK.COM
Backpatch-through: 16

11 days agoAdd support for base64url encoding and decoding
Daniel Gustafsson [Sat, 20 Sep 2025 21:19:32 +0000 (23:19 +0200)]
Add support for base64url encoding and decoding

This adds support for base64url encoding and decoding, a base64
variant which is safe to use in filenames and URLs.  base64url
replaces '+' in the base64 alphabet with '-' and '/' with '_',
thus making it safe for URL addresses and file systems.

Support for base64url was originally suggested by Przemysław Sztoch.

Author: Florents Tselai <[email protected]>
Reviewed-by: Aleksander Alekseev <[email protected]>
Reviewed-by: David E. Wheeler <[email protected]>
Reviewed-by: Masahiko Sawada <[email protected]>
Reviewed-by: Daniel Gustafsson <[email protected]>
Reviewed-by: Chao Li (Evan) <[email protected]>
Discussion: https://postgr.es/m/70f2b6a8-486a-4fdb-a951-84cef35e22ab@sztoch.pl

11 days agoTrack the maximum possible frequency of non-MCE array elements.
Tom Lane [Sat, 20 Sep 2025 18:48:16 +0000 (14:48 -0400)]
Track the maximum possible frequency of non-MCE array elements.

The lossy-counting algorithm that ANALYZE uses to identify most-common
array elements has a notion of cutoff frequency: elements with
frequency greater than that are guaranteed to be collected, elements
with smaller frequencies are not.  In cases where we find fewer MCEs
than the stats target would permit us to store, the cutoff frequency
provides valuable additional information, to wit that there are no
non-MCEs with frequency greater than that.  What the selectivity
estimation functions actually use the "minfreq" entry for is as a
ceiling on the possible frequency of non-MCEs, so using the cutoff
rather than the lowest stored MCE frequency provides a tighter bound
and more accurate estimates.

Therefore, instead of redundantly storing the minimum observed MCE
frequency, store the cutoff frequency when there are fewer tracked
values than we want.  (When there are more, then of course we cannot
assert that no non-stored elements are above the cutoff frequency,
since we're throwing away some that are; so we still use the
minimum stored frequency in that case.)

Notably, this works even when none of the values are common enough
to be called MCEs.  In such cases we previously stored nothing in
the STATISTIC_KIND_MCELEM pg_statistic slot, which resulted in the
selectivity functions falling back to default estimates.  So in that
case we want to construct a STATISTIC_KIND_MCELEM entry that contains
no "values" but does have "numbers", to wit the three extra numbers
that the MCELEM entry type defines.  A small obstacle is that
update_attstats() has traditionally stored a null, not an empty array,
when passed zero "values" for a slot.  That gives rise to an MCELEM
entry that get_attstatsslot() will spit up on.  The least risky
solution seems to be to adjust update_attstats() so that it will emit
a non-null (but possibly empty) array when the passed stavalues array
pointer isn't NULL, rather than conditioning that on numvalues > 0.
In other existing cases I don't believe that that changes anything.
For consistency, handle the stanumbers array the same way.

In passing, improve the comments in routines that use
STATISTIC_KIND_MCELEM data.  Particularly, explain why we use
minfreq / 2 not minfreq as the estimate for non-MCE values.

Thanks to Matt Long for the suggestion that we could apply this
idea even when there are more than zero MCEs.

Reported-by: Mark Frost <[email protected]>
Reported-by: Matt Long <[email protected]>
Author: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/PH3PPF1C905D6E6F24A5C1A1A1D8345B593E16FA@PH3PPF1C905D6E6.namprd15.prod.outlook.com

11 days agoRe-allow using statistics for bool-valued functions in WHERE.
Tom Lane [Sat, 20 Sep 2025 16:44:52 +0000 (12:44 -0400)]
Re-allow using statistics for bool-valued functions in WHERE.

Commit a391ff3c3, which added the ability for a function's support
function to provide a custom selectivity estimate for "WHERE f(...)",
unintentionally removed the possibility of applying expression
statistics after finding there's no applicable support function.
That happened because we no longer fell through to boolvarsel()
as before.  Refactor to do so again, putting the 0.3333333 default
back into boolvarsel() where it had been (cf. commit 39df0f150).

I surely wouldn't have made this error if 39df0f150 had included
a test case, so add one now.  At the time we did not have the
"extended statistics" infrastructure, but we do now, and it is
also unable to work in this scenario because of this error.
So make use of that for the test case.

This is very clearly a bug fix, but I'm afraid to put it into
released branches because of the likelihood of altering plan
choices, which we avoid doing in minor releases.  So, master only.

Reported-by: Frédéric Yhuel <[email protected]>
Author: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/a8b99dce-1bfb-4d97-af73-54a32b85c916@dalibo.com

12 days agoFix obsolete references to postgres.h in comments.
Nathan Bossart [Fri, 19 Sep 2025 14:19:03 +0000 (09:19 -0500)]
Fix obsolete references to postgres.h in comments.

Oversights in commits d08741eab5 and d952373a98.

Reviewed-by: Chao Li <[email protected]>
Discussion: https://postgr.es/m/aMxbfSJ2wLWd32x-%40nathan

12 days agoImprove wording in a few comments
David Rowley [Fri, 19 Sep 2025 11:35:23 +0000 (23:35 +1200)]
Improve wording in a few comments

Initially this was to fix the "catched" typo, but I (David) wasn't quite
clear on what the previous comment meant about being "effective".  I
expect this means efficiency, so I've reworded the comment to indicate
that.

While this is only a comment fixup, for the sake of possibly minimizing
possible future backpatching pain, I've opted to backpatch to 18 since
this code is new to that version and the release isn't out the door yet.

Author: Tender Wang <[email protected]>
Discussion: https://postgr.es/m/CAHewXNmSYWPud1sfBvpKbCJeRkWeZYuqatxtV9U9LvAFXBEiBw@mail.gmail.com
Backpatch-through: 18

13 days agoAdd optional pid parameter to pg_replication_origin_session_setup().
Amit Kapila [Fri, 19 Sep 2025 05:38:40 +0000 (05:38 +0000)]
Add optional pid parameter to pg_replication_origin_session_setup().

Commit 216a784829c introduced parallel apply workers, allowing multiple
processes to share a replication origin. To support this,
replorigin_session_setup() was extended to accept a pid argument
identifying the process using the origin.

This commit exposes that capability through the SQL interface function
pg_replication_origin_session_setup() by adding an optional pid parameter.
This enables multiple processes to coordinate replication using the same
origin when using SQL-level replication functions.

This change allows the non-builtin logical replication solutions to
implement parallel apply for large transactions.

Additionally, an existing internal error was made user-facing, as it can
now be triggered via the exposed SQL API.

Author: Doruk Yilmaz <[email protected]>
Author: Hayato Kuroda <[email protected]>
Reviewed-by: Amit Kapila <[email protected]>
Reviewed-by: Euler Taveira <[email protected]>
Discussion: https://postgr.es/m/CAMPB6wfe4zLjJL8jiZV5kjjpwBM2=rTRme0UCL7Ra4L8MTVdOg@mail.gmail.com
Discussion: https://postgr.es/m/CAE2gYzyTSNvHY1+iWUwykaLETSuAZsCWyryokjP6rG46ZvRgQA@mail.gmail.com

13 days agoImprove few errdetail messages introduced in commit 0d48d393d46.
Amit Kapila [Fri, 19 Sep 2025 04:52:59 +0000 (04:52 +0000)]
Improve few errdetail messages introduced in commit 0d48d393d46.

Based on suggestions by Tom Lane

Reported-by: Kyotaro Horiguchi <[email protected]>
Author: Zhijie Hou <[email protected]>
Reviewed-by: Amit Kapila <[email protected]>
Discussion: https://postgr.es/m/20250916.114644.275726106301941878[email protected]

13 days agoMake XLogFlush() and XLogNeedsFlush() decision-making more consistent
Michael Paquier [Fri, 19 Sep 2025 04:47:28 +0000 (13:47 +0900)]
Make XLogFlush() and XLogNeedsFlush() decision-making more consistent

When deciding which code path to use depending on the state of recovery,
XLogFlush() and XLogNeedsFlush() have been relying on different
criterias:
- XLogFlush() relied on XLogInsertAllowed().
- XLogNeedsFlush() relied on RecoveryInProgress().

Currently, the checkpointer is allowed to insert WAL records while
RecoveryInProgress() returns true for an end-of-recovery checkpoint,
where XLogInsertAllowed() matters.  Using RecoveryInProgress() in
XLogNeedsFlush() did not really matter for its existing callers, as the
checkpointer only called XLogFlush().  However, a feature under
discussion, by Melanie Plageman, needs XLogNeedsFlush() to be able to
work in more contexts, the end-of-recovery checkpoint being one.

This commit changes XLogNeedsFlush() to use XLogInsertAllowed() instead
of RecoveryInProgress(), making the checks in both routines more
consistent.  While on it, an assertion based on XLogNeedsFlush() is
added at the end of XLogFlush(), triggered when flushing a physical
position (not for the normal recovery patch that checks for updates of
the minimum recovery point).  This assertion would fail for example in
the recovery test 015_promotion_pages if XLogNeedsFlush() is changed to
use RecoveryInProgress().  This should be hopefully enough to ensure
that the checks done in both routines remain consistent.

Author: Melanie Plageman <[email protected]>
Co-authored-by: Dilip Kumar <[email protected]>
Reviewed-by: Jeff Davis <[email protected]>
Reviewed-by: Chao Li <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Discussion: https://postgr.es/m/CAAKRu_a1vZRZRWO3_jv_X13RYoqLRVipGO0237g5PKzPa2YX6g@mail.gmail.com

13 days agoFix EPQ crash from missing partition pruning state in EState
Amit Langote [Fri, 19 Sep 2025 02:38:29 +0000 (11:38 +0900)]
Fix EPQ crash from missing partition pruning state in EState

Commit bb3ec16e14 moved partition pruning metadata into PlannedStmt.
At executor startup this metadata is used to initialize the EState
fields es_part_prune_infos, es_part_prune_states, and
es_part_prune_results.  EvalPlanQualStart() failed to copy those
fields into the child EState, causing NULL dereference when Append
ran partition pruning during a recheck. This can occur with DELETE
or UPDATE on partitioned tables that use runtime pruning, e.g. with
generic plans.

Fix by copying all partition pruning state into the EPQ estate.

Add an isolation test that reproduces the crash with concurrent
UPDATE and DELETE on a partitioned table, where the DELETE session
hits the crash during its EPQ recheck after the UPDATE commits.

Bug: #19056
Reported-by: Fei Changhong <[email protected]>
Diagnozed-by: Fei Changhong <[email protected]>
Author: David Rowley <[email protected]>
Co-authored-by: Amit Langote <[email protected]>
Discussion: https://postgr.es/m/19056-a677cef9b54d76a0%40postgresql.org

13 days agoDocument and check that PgStat_HashKey has no padding
Michael Paquier [Fri, 19 Sep 2025 00:54:05 +0000 (09:54 +0900)]
Document and check that PgStat_HashKey has no padding

This change is a tighter rework of 7d85d87f4d5c, which tried to improve
the code so as it would work should PgStat_HashKey gain new fields that
create padding bytes.  However, the previous change is proving to not be
enough as some code paths of pgstats do not pass PgStat_HashKey by
reference (valgrind would warn when padding is added to the structure,
through a new field).

Per discussion, let's document and check that PgStat_HashKey has no
padding rather than try to complicate the code of pgstats so as it is
able to work around that.

This removes a couple of memset(0) calls that should not be required.
While on it, this commit adds a static assertion checking that no
padding is introduced in the structure, by checking that the size of
PgStat_HashKey matches with the sum of the size of all its fields.

The object ID part of the hash key is already 8 bytes, which should be
plenty enough already.  A comment is added to discourage the addition of
new fields.

Author: Michael Paquier <[email protected]>
Reviewed-by: Sami Imseih <[email protected]>
Discussion: https://postgr.es/m/CAA5RZ0t9omat+HVSakJXwTMWvhpYFcAZb41RPWKwrKFUgmAFBQ@mail.gmail.com

13 days agoAdd a test harness for the LWLock tranche code.
Nathan Bossart [Thu, 18 Sep 2025 20:23:11 +0000 (15:23 -0500)]
Add a test harness for the LWLock tranche code.

This code is heavily used and already has decent test coverage, but
it lacks a dedicated test suite.  This commit changes that.

Author: Sami Imseih <[email protected]>
Co-authored-by: Nathan Bossart <[email protected]>
Reviewed-by: Bertrand Drouvot <[email protected]>
Discussion: https://postgr.es/m/CAA5RZ0tQ%2BEYSTOd2hQ8RXdsNfGBLAtOe-YmnsTE6ZVg0E-4qew%40mail.gmail.com
Discussion: https://postgr.es/m/CAA5RZ0vpr0P2rbA%3D_K0_SCHM7bmfVX4wEO9FAyopN1eWCYORhA%40mail.gmail.com

13 days agoFix re-initialization of LWLock-related shared memory.
Nathan Bossart [Thu, 18 Sep 2025 14:55:39 +0000 (09:55 -0500)]
Fix re-initialization of LWLock-related shared memory.

When shared memory is re-initialized after a crash, the named
LWLock tranche request array that was copied to shared memory will
no longer be accessible.  To fix, save the pointer to the original
array in postmaster's local memory, and switch to it when
re-initializing the LWLock-related shared memory.

Oversight in commit ed1aad15e0.  Per buildfarm member batta.

Reported-by: Michael Paquier <[email protected]>
Reported-by: Alexander Lakhin <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Discussion: https://postgr.es/m/aMoejB3iTWy1SxfF%40paquier.xyz
Discussion: https://postgr.es/m/f8ca018f-3479-49f6-a92c-e31db9f849d7%40gmail.com

2 weeks agopgbench: Remove unused argument from create_sql_command().
Fujii Masao [Thu, 18 Sep 2025 02:22:21 +0000 (11:22 +0900)]
pgbench: Remove unused argument from create_sql_command().

Author: Yugo Nagata <[email protected]>
Reviewed-by: Steven Niu <[email protected]>
Discussion: https://postgr.es/m/20250917112814.096f660ea4c3c64630475e62@sraoss.co.jp

2 weeks agopg_restore: Fix security label handling with --no-publications/subscriptions.
Fujii Masao [Thu, 18 Sep 2025 02:09:15 +0000 (11:09 +0900)]
pg_restore: Fix security label handling with --no-publications/subscriptions.

Previously, pg_restore did not skip security labels on publications or
subscriptions even when --no-publications or --no-subscriptions was specified.
As a result, it could issue SECURITY LABEL commands for objects that were
never created, causing those commands to fail.

This commit fixes the issue by ensuring that security labels on publications
and subscriptions are also skipped when the corresponding options are used.

Backpatch to all supported versions.

Author: Jian He <[email protected]>
Reviewed-by: Fujii Masao <[email protected]>
Discussion: https://postgr.es/m/CACJufxHCt00pR9h51AVu6+yPD5J7JQn=7dQXxqacj0XyDhc-fA@mail.gmail.com
Backpatch-through: 13

2 weeks agoMark shared buffer lookup table HASH_FIXED_SIZE
Andres Freund [Thu, 18 Sep 2025 00:28:43 +0000 (20:28 -0400)]
Mark shared buffer lookup table HASH_FIXED_SIZE

StrategyInitialize() calls InitBufTable() with maximum number of entries that
the buffer lookup table can ever have. Thus there should not be any need to
allocate more element after initialization. Hence mark the hash table as fixed
sized.

Author: Ashutosh Bapat <[email protected]>
Discussion: https://postgr.es/m/CAExHW5v0jh3F_wj86yC=qBfWk0uiT94qy=Z41uzAHLHh0SerRA@mail.gmail.com

2 weeks agoCalculate agglevelsup correctly when Aggref contains a CTE.
Tom Lane [Wed, 17 Sep 2025 20:32:57 +0000 (16:32 -0400)]
Calculate agglevelsup correctly when Aggref contains a CTE.

If an aggregate function call contains a sub-select that has
an RTE referencing a CTE outside the aggregate, we must treat
that reference like a Var referencing the CTE's query level
for purposes of determining the aggregate's level.  Otherwise
we might reach the nonsensical conclusion that the aggregate
should be evaluated at some query level higher than the CTE,
ending in a planner error or a broken plan tree that causes
executor failures.

Bug: #19055
Reported-by: BugForge <[email protected]>
Author: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/19055-6970cfa8556a394d@postgresql.org
Backpatch-through: 13

2 weeks agojit: Fix type used for Datum values in LLVM IR.
Thomas Munro [Wed, 17 Sep 2025 00:00:16 +0000 (12:00 +1200)]
jit: Fix type used for Datum values in LLVM IR.

Commit 2a600a93 made Datum 8 bytes wide everywhere.  It was no longer
appropriate to use TypeSizeT on 32 bit systems, and JIT compilation
would fail with various type check errors.  Introduce a separate
LLVMTypeRef with the name TypeDatum.  TypeSizeT is still used in some
places for actual size_t values.

Reported-by: Dmitry Mityugov <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Tested-by: Dmitry Mityugov <[email protected]>
Discussion: https://postgr.es/m/0a9f0be59171c2e8f1b3bc10f4fcf267%40postgrespro.ru

2 weeks agoinjection_points: Fix incrementation of variable-numbered stats
Michael Paquier [Wed, 17 Sep 2025 01:15:13 +0000 (10:15 +0900)]
injection_points: Fix incrementation of variable-numbered stats

The pending entry was not used when incrementing its data, directly
manipulating the shared memory pointer, without even locking it.  This
could mean losing statistics under concurrent activity.  The flush
callback was a no-op.

This code serves as a base template for extensions for the custom
cumulative statistics, so let's be clean and use a pending entry for the
incrementations, whose data is then flushed to the corresponding entry
in the shared hashtable when all the stats are reported, in its own
flush callback.

Author: Sami Imseih <[email protected]>
Discussion: https://postgr.es/m/CAA5RZ0v0U0yhPbY+bqChomkPbyUrRQ3rQXnZf_SB-svDiQOpgQ@mail.gmail.com
Backpatch-through: 18

2 weeks agoFix shared memory calculation size of PgAioCtl
Michael Paquier [Wed, 17 Sep 2025 00:33:32 +0000 (09:33 +0900)]
Fix shared memory calculation size of PgAioCtl

The shared memory size was calculated based on an offset of io_handles,
which is itself a pointer included in the structure.  We tend to
overestimate the shared memory size overall, so this was unlikely an
issue in practice, but let's be correct and use the full size of the
structure in the calculation, so as the pointer for io_handles is
included.

Oversight in da7226993fd4.

Author: Madhukar Prasad <[email protected]>
Reviewed-by: Andres Freund <[email protected]>
Reviewed-by: Matthias van de Meent <[email protected]>
Discussion: https://postgr.es/m/CAKi+wrbC2dTzh_vKJoAZXV5wqTbhY0n4wRNpCjJ=e36aoo0kFw@mail.gmail.com
Backpatch-through: 18

2 weeks agoAdd missing EPQ recheck for TID Range Scan
David Rowley [Wed, 17 Sep 2025 00:19:15 +0000 (12:19 +1200)]
Add missing EPQ recheck for TID Range Scan

The EvalPlanQual recheck for TID Range Scan wasn't rechecking the TID qual
still passed after following update chains.  This could result in tuples
being updated or deleted by plans using TID Range Scans where the ctid of
the new (updated) tuple no longer matches the clause of the scan.  This
isn't desired behavior, and isn't consistent with what would happen if the
chosen plan had used an Index or Seq Scan, and that could lead to hard to
predict behavior for scans that contain TID quals and other quals as the
planner has freedom to choose TID Range or some other non-TID scan method
for such queries, and the chosen plan could change at any moment.

Here we fix this by properly implementing the recheck function for TID
Range Scans.

Backpatch to 14, where TID Range Scans were added

Reported-by: Sophie Alpert <[email protected]>
Author: Sophie Alpert <[email protected]>
Author: David Rowley <[email protected]>
Reviewed-by: David Rowley <[email protected]>
Reviewed-by: Chao Li <[email protected]>
Discussion: https://postgr.es/m/4a6268ff-3340-453a-9bf5-c98d51a6f729@app.fastmail.com
Backpatch-through: 14

2 weeks agoAdd missing EPQ recheck for TID Scan
David Rowley [Tue, 16 Sep 2025 23:48:55 +0000 (11:48 +1200)]
Add missing EPQ recheck for TID Scan

The EvalPlanQual recheck for TID Scan wasn't rechecking the TID qual
still passed after following update chains.  This could result in tuples
being updated or deleted by plans using TID Scans where the ctid of the
new (updated) tuple no longer matches the clause of the scan.  This isn't
desired behavior, and isn't consistent with what would happen if the
chosen plan had used an Index or Seq Scan, and that could lead to hard to
predict behavior for scans that contain TID quals and other quals as the
planner has freedom to choose TID or some other scan method for such
queries, and the chosen plan could change at any moment.

Here we fix this by properly implementing the recheck function for TID
Scans.

Backpatch to 13, oldest supported version

Reported-by: Sophie Alpert <[email protected]>
Author: Sophie Alpert <[email protected]>
Author: David Rowley <[email protected]>
Reviewed-by: David Rowley <[email protected]>
Reviewed-by: Chao Li <[email protected]>
Discussion: https://postgr.es/m/4a6268ff-3340-453a-9bf5-c98d51a6f729@app.fastmail.com
Backpatch-through: 13

2 weeks agoAdd regression expected-files for older OpenSSL in FIPS mode.
Tom Lane [Tue, 16 Sep 2025 18:36:51 +0000 (14:36 -0400)]
Add regression expected-files for older OpenSSL in FIPS mode.

Cover contrib/pgcrypto, per buildfarm.

Author: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/443709.1757876535@sss.pgh.pa.us
Backpatch-through: 17

2 weeks agoRevert "Avoid race condition between "GRANT role" and "DROP ROLE"".
Tom Lane [Tue, 16 Sep 2025 17:05:53 +0000 (13:05 -0400)]
Revert "Avoid race condition between "GRANT role" and "DROP ROLE"".

This reverts commit 98fc31d6499163a0a781aa6f13582a07f09cd7c6.
That change allowed DROP OWNED BY to drop grants of the target
role to other roles, arguing that nobody would need those
privileges anymore.  But that's not so: if you're not superuser,
you still need admin privilege on the target role so you can
drop it.

It's not clear whether or how the dependency-based approach
to solving the original problem can be adapted to keep these
grants.  Since v18 release is fast approaching, the sanest
thing to do seems to be to revert this patch for now.  The
race-condition problem is low severity and not worth taking
risks for.

I didn't force a catversion bump in 98fc31d64, so I won't do
so here either.

Reported-by: Dipesh Dhameliya <[email protected]>
Author: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/CABgZEgczOFicCJoqtrH9gbYMe_BV3Hq8zzCBRcMgmU6LRsihUA@mail.gmail.com
Backpatch-through: 18

2 weeks agoFix pg_dump COMMENT dependency for separate domain constraints.
Noah Misch [Tue, 16 Sep 2025 16:40:44 +0000 (09:40 -0700)]
Fix pg_dump COMMENT dependency for separate domain constraints.

The COMMENT should depend on the separately-dumped constraint, not the
domain.  Sufficient restore parallelism might fail the COMMENT command
by issuing it before the constraint exists.  Back-patch to v13, like
commit 0858f0f96ebb891c8960994f023ed5a17b758a38.

Reviewed-by: Álvaro Herrera <[email protected]>
Discussion: https://postgr.es/m/20250913020233[email protected]
Backpatch-through: 13

2 weeks agoProvide more-specific error details/hints for function lookup failures.
Tom Lane [Tue, 16 Sep 2025 16:17:02 +0000 (12:17 -0400)]
Provide more-specific error details/hints for function lookup failures.

Up to now we've contented ourselves with a one-size-fits-all error
hint when we fail to find any match to a function or procedure call.
That was mostly okay in the beginning, but it was never great, and
since the introduction of named arguments it's really not adequate.
We at least ought to distinguish "function name doesn't exist" from
"function name exists, but not with those argument names".  And the
rules for named-argument matching are arcane enough that some more
detail seems warranted if we match the argument names but the call
still doesn't work.

This patch creates a framework for dealing with these problems:
FuncnameGetCandidates and related code will now pass back a bitmask of
flags showing how far the match succeeded.  This allows a considerable
amount of granularity in the reports.  The set-bits-in-a-bitmask
approach means that when there are multiple candidate functions, the
report will reflect the match(es) that got the furthest, which seems
correct.  Also, we can avoid mentioning "maybe add casts" unless
failure to match argument types is actually the issue.

Extend the same return-a-bitmask approach to OpernameGetCandidates.
The issues around argument names don't apply to operator syntax,
but it still seems worth distinguishing between "there is no
operator of that name" and "we couldn't match the argument types".

While at it, adjust these messages and related ones to more strictly
separate "detail" from "hint", following our message style guidelines'
distinction between those.

Reported-by: Dominique Devienne <[email protected]>
Author: Tom Lane <[email protected]>
Reviewed-by: Robert Haas <[email protected]>
Discussion: https://postgr.es/m/1756041.1754616558@sss.pgh.pa.us

2 weeks agoAdd regression expected-files for older OpenSSL in FIPS mode.
Tom Lane [Tue, 16 Sep 2025 14:09:49 +0000 (10:09 -0400)]
Add regression expected-files for older OpenSSL in FIPS mode.

In our previous discussions around making our regression tests
pass in FIPS mode, we concluded that we didn't need to support
the different error message wording observed with pre-3.0 OpenSSL.
However there are still a few LTS distributions soldiering along
with such versions, and now we have some in the buildfarm.
So let's add the variant expected-files needed to make them happy.

This commit only covers the core regression tests.  Previous
discussion suggested that we might need some adjustments in
contrib as well, but it's not totally clear to me what those
would be.  Rather than work it out from first principles,
I'll wait to see what the buildfarm shows.

Back-patch to v17 which is the oldest branch that claims
to support this case.

Author: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/443709.1757876535@sss.pgh.pa.us
Backpatch-through: 17

2 weeks agoTreat JsonConstructorExpr as non-strict
Richard Guo [Tue, 16 Sep 2025 09:42:20 +0000 (18:42 +0900)]
Treat JsonConstructorExpr as non-strict

JsonConstructorExpr can produce non-NULL output with a NULL input, so
it should be treated as a non-strict construct.  Failing to do so can
lead to incorrect query behavior.

For example, in the reported case, when pulling up a subquery that is
under an outer join, if the subquery's target list contains a
JsonConstructorExpr that uses subquery variables and it is mistakenly
treated as strict, it will be pulled up without being wrapped in a
PlaceHolderVar.  As a result, the expression will be evaluated at the
wrong place and will not be forced to null when the outer join should
do so.

Back-patch to v16 where JsonConstructorExpr was introduced.

Bug: #19046
Reported-by: Runyuan He <[email protected]>
Author: Tender Wang <[email protected]>
Co-authored-by: Richard Guo <[email protected]>
Discussion: https://postgr.es/m/19046-765b6602b0a8cfdf@postgresql.org
Backpatch-through: 16

2 weeks agoGenerate GB18030 mappings from the Unicode Consortium's UCM file
John Naylor [Tue, 16 Sep 2025 09:29:08 +0000 (16:29 +0700)]
Generate GB18030 mappings from the Unicode Consortium's UCM file

Previously we built the .map files for GB18030 (version 2000) from an
XML file. The 2022 version for this encoding is only available as a
Unicode Character Mapping (UCM) file, so as preparatory refactoring
switch to this format as the source for building version 2000.

As we do with most input files for the conversion mappings, download
the file on demand. In order to generate the same mappings we have
now, we must download from a previous upstream commit, rather than
the head since the latter contains a correction not present in our
current .map files.

The XML file is still used by EUC_CN, so we cannot delete it from our
repository. GB18030 is a superset of EUC_CN, so it may be possible to
build EUC_CN from the same UCM file, but that is left for future work.

Author: Chao Li <[email protected]>
Discussion: https://postgr.es/m/966d9fc.169.198741fe60b.Coremail.jiaoshuntian%40highgo.com

2 weeks agoMove pg_int64 back to postgres_ext.h
Peter Eisentraut [Tue, 16 Sep 2025 06:59:12 +0000 (08:59 +0200)]
Move pg_int64 back to postgres_ext.h

Fix for commit 3c86223c998.  That commit moved the typedef of pg_int64
from postgres_ext.h to libpq-fe.h, because the only remaining place
where it might be used is libpq users, and since the type is obsolete,
the intent was to limit its scope.

The problem is that if someone builds an extension against an
older (pre-PG18) server version and a new (PG18) libpq, they might get
two typedefs, depending on include file order.  This is not allowed
under C99, so they might get warnings or errors, depending on the
compiler and options.  The underlying types might also be
different (e.g., long int vs. long long int), which would also lead to
errors.  This scenario is plausible when using the standard Debian
packaging, which provides only the newest libpq but per-major-version
server packages.

The fix is to undo that part of commit 3c86223c998.  That way, the
typedef is in the same header file across versions.  At least, this is
the safest fix doable before PostgreSQL 18 releases.

Reviewed-by: Thomas Munro <[email protected]>
Discussion: https://www.postgresql.org/message-id/25144219-5142-4589-89f8-4e76948b32db%40eisentraut.org

2 weeks agopg_dump: Fix dumping of security labels on subscriptions and event triggers.
Fujii Masao [Tue, 16 Sep 2025 07:44:58 +0000 (16:44 +0900)]
pg_dump: Fix dumping of security labels on subscriptions and event triggers.

Previously, pg_dump incorrectly queried pg_seclabel to retrieve security labels
for subscriptions, which are stored in pg_shseclabel as they are global objects.
This could result in security labels for subscriptions not being dumped.

This commit fixes the issue by updating pg_dump to query the pg_seclabels view,
which aggregates entries from both pg_seclabel and pg_shseclabel.
While querying pg_shseclabel directly for subscriptions was an alternative,
using pg_seclabels is simpler and sufficient.

In addition, pg_dump is updated to dump security labels on event triggers,
which were previously omitted.

Backpatch to all supported versions.

Author: Jian He <[email protected]>
Co-authored-by: Fujii Masao <[email protected]>
Discussion: https://postgr.es/m/CACJufxHCt00pR9h51AVu6+yPD5J7JQn=7dQXxqacj0XyDhc-fA@mail.gmail.com
Backpatch-through: 13

2 weeks agoFix intermittent BF failures in 035_conflicts.
Amit Kapila [Tue, 16 Sep 2025 06:16:23 +0000 (06:16 +0000)]
Fix intermittent BF failures in 035_conflicts.

This commit addresses two sources of instability in the 035_conflicts
test:

Unstable VACUUM usage:
The test previously relied on VACUUM to remove a deleted column, which can
be unreliable due to concurrent background writer or checkpoint activity
that may lock the page containing the deleted tuple. Since the test
already verifies that replication_slot.xmin has advanced sufficiently to
confirm the feature's correctness, so, the VACUUM step is removed to
improve test stability.

Timing-sensitive retention resumption check:
The test includes a check to confirm that retention of conflict-relevant
information resumes after setting max_retention_duration to 0. However, in
some cases, the apply worker resumes retention immediately after the
inactive slot is removed from synchronized_standby_slots, even before
max_retention_duration is updated. This can happen if remote changes are
applied in under 1ms, causing the test to timeout while waiting for a
later log position. To ensure consistent behavior, this commit delays the
removal of synchronized_standby_slots until after max_retention_duration
is set to 0.

Author: Zhijie Hou <[email protected]>
Reviewed-by: shveta malik <[email protected]>
Reviewed-by: Amit Kapila <[email protected]>
Discussion: https://postgr.es/m/TY4PR01MB16907805DE4816E53C54708159414A@TY4PR01MB16907.jpnprd01.prod.outlook.com

2 weeks agoFix incorrect const qualifier
Peter Eisentraut [Tue, 16 Sep 2025 05:23:50 +0000 (07:23 +0200)]
Fix incorrect const qualifier

Commit 7202d72787d added in passing some const qualifiers, but the one
on the postmaster_child_launch() startup_data argument was incorrect,
because the function itself modifies the pointed-to data.  This is
hidden from the compiler because of casts.  The qualifiers on the
functions called by postmaster_child_launch() are still correct.

2 weeks agopg_restore: Fix comment handling with --no-policies.
Fujii Masao [Tue, 16 Sep 2025 02:54:23 +0000 (11:54 +0900)]
pg_restore: Fix comment handling with --no-policies.

Previously, pg_restore did not skip comments on policies even when
--no-policies was specified. As a result, it could issue COMMENT commands
for policies that were never created, causing those commands to fail.

This commit fixes the issue by ensuring that comments on policies
are also skipped when --no-policies is used.

Backpatch to v18, where --no-policies was added in pg_restore.

Author: Jian He <[email protected]>
Co-authored-by: Fujii Masao <[email protected]>
Discussion: https://postgr.es/m/CACJufxHCt00pR9h51AVu6+yPD5J7JQn=7dQXxqacj0XyDhc-fA@mail.gmail.com
Backpatch-through: 18

2 weeks agopg_restore: Fix comment handling with --no-publications / --no-subscriptions.
Fujii Masao [Tue, 16 Sep 2025 01:35:12 +0000 (10:35 +0900)]
pg_restore: Fix comment handling with --no-publications / --no-subscriptions.

Previously, pg_restore did not skip comments on publications or subscriptions
even when --no-publications or --no-subscriptions was specified. As a result,
it could issue COMMENT commands for objects that were never created,
causing those commands to fail.

This commit fixes the issue by ensuring that comments on publications and
subscriptions are also skipped when the corresponding options are used.

Backpatch to all supported versions.

Author: Jian He <[email protected]>
Co-authored-by: Fujii Masao <[email protected]>
Discussion: https://postgr.es/m/CACJufxHCt00pR9h51AVu6+yPD5J7JQn=7dQXxqacj0XyDhc-fA@mail.gmail.com
Backpatch-through: 13

2 weeks agoTeach nbtree to avoid evaluating row compare keys.
Peter Geoghegan [Mon, 15 Sep 2025 20:56:49 +0000 (16:56 -0400)]
Teach nbtree to avoid evaluating row compare keys.

Add logic to _bt_set_startikey that determines whether row compare keys
are guaranteed to be satisfied by every tuple on a page that is about to
be read by _bt_readpage.  This works in essentially the same way as the
existing scalar inequality logic.  Testing has shown that the new logic
improves performance to about the same degree as the existing scalar
inequality logic (compared to the unoptimized case).  In other words,
the new logic makes many row compare scans significantly faster.

Note that the new row compare inequality logic is only effective when
the same individual row member is the deciding subkey for all tuples on
the page (obviously, all tuples have to satisfy the row compare, too).
This is what makes the new row compare logic very similar to the
existing logic for scalar inequalities.  Note, in particular, that this
makes it safe to ignore whether all row compare members are against
either ASC or DESC index attributes (i.e. it doesn't matter if
individual subkeys don't all use the same inequality strategy).

Also stop refusing to set pstate.startikey to an offset beyond any
nonrequired key (don't add logic that'll do that for an individual row
compare subkey, either).  We can fully rely on our firstchangingattnum
tests instead.  This will do the right thing when a page has a group of
tuples with NULLs in a lower-order attribute that makes the tuples fail
to satisfy a row compare key -- we won't incorrectly conclude that all
tuples must satisfy the row compare, just because firsttup and lasttup
happen to.  Our firstchangingattnum test prevents that from happening.
(Note that the original "avoid evaluating nbtree scan keys" mechanism
added by commit e0b1ee17 couldn't support row compares due to issues
with tuples that contain NULLs in a lower-order subkey's attribute.
That original mechanism relied on requiredness markings, which the
replacement _bt_set_startikey mechanism never really needed.)

Follow up to commit 8a510275, which added the _bt_set_startikey
optimization.  _bt_set_startikey is now feature complete; there's no
remaining kind of nbtree scan key that it still doesn't support.

Author: Peter Geoghegan <[email protected]>
Reviewed-By: Chao Li <[email protected]>
Discussion: https://postgr.es/m/CAH2-WznL6Z3H_GTQze9d8T_Ls=cYbnd-_9f-Jo7aYgTGRUD58g@mail.gmail.com

2 weeks agoExpand virtual generated columns in constraint expressions
Peter Eisentraut [Mon, 15 Sep 2025 14:27:50 +0000 (16:27 +0200)]
Expand virtual generated columns in constraint expressions

Virtual generated columns in constraint expressions need to be
expanded because the optimizer matches these expressions to qual
clauses.  Failing to do so can cause us to miss opportunities for
constraint exclusion.

Author: Richard Guo <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/204804c0-798f-4c72-bd1f-36116024fda3%40eisentraut.org

2 weeks agoCREATE STATISTICS: improve misleading error message
Peter Eisentraut [Mon, 15 Sep 2025 09:38:58 +0000 (11:38 +0200)]
CREATE STATISTICS: improve misleading error message

The previous change (commit f225473cbae) was still not on target,
because it talked about relation kinds, which are not what is being
checked here.  Provide a more accurate message.

Reviewed-by: Tom Lane <[email protected]>
Discussion: https://postgr.es/m/CACJufxEZ48toGH0Em_6vdsT57Y3L8pLF=DZCQ_gCii6=C3MeXw@mail.gmail.com

2 weeks agoChange fmgr.h typedefs to use original names
Peter Eisentraut [Mon, 15 Sep 2025 08:48:30 +0000 (10:48 +0200)]
Change fmgr.h typedefs to use original names

fmgr.h defined some types such as fmNodePtr which is just Node *, but
it made its own types to avoid having to include various header files.
With C11, we can now instead typedef the original names without fear
of conflicts.

Reviewed-by: Tom Lane <[email protected]>
Reviewed-by: Chao Li <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/10d32190-f31b-40a5-b177-11db55597355@eisentraut.org

2 weeks agoRemove hbaPort type
Peter Eisentraut [Mon, 15 Sep 2025 08:48:30 +0000 (10:48 +0200)]
Remove hbaPort type

This was just a workaround to avoid including the header file that
defines the Port type.  With C11, we can now just re-define the Port
type without the possibility of a conflict.

Reviewed-by: Tom Lane <[email protected]>
Reviewed-by: Chao Li <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/10d32190-f31b-40a5-b177-11db55597355@eisentraut.org

2 weeks agoUpdate various forward declarations to use typedef
Peter Eisentraut [Mon, 15 Sep 2025 08:48:30 +0000 (10:48 +0200)]
Update various forward declarations to use typedef

There are a number of forward declarations that use struct but not the
customary typedef, because that could have led to repeat typedefs,
which was not allowed.  This is now allowed in C11, so we can update
these to provide the typedefs as well, so that the later uses of the
types look more consistent.

Reviewed-by: Chao Li <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/10d32190-f31b-40a5-b177-11db55597355@eisentraut.org

2 weeks agoImprove ExplainState type handling in header files
Peter Eisentraut [Mon, 15 Sep 2025 08:48:30 +0000 (10:48 +0200)]
Improve ExplainState type handling in header files

Now that we can have repeat typedefs with C11, we don't need to use
"struct ExplainState" anymore but can instead make a typedef where
necessary.  This doesn't change anything but makes it look nicer.

(There are more opportunities for similar changes, but this is broken
out because there was a separate discussion about it, and it's
somewhat bulky on its own.)

Reviewed-by: Chao Li <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/f36c0a45-98cd-40b2-a7cc-f2bf02b12890%40eisentraut.org#a12fb1a2c1089d6d03010f6268871b00
Discussion: https://www.postgresql.org/message-id/flat/10d32190-f31b-40a5-b177-11db55597355@eisentraut.org

2 weeks agoRemove workarounds against repeat typedefs
Peter Eisentraut [Mon, 15 Sep 2025 08:53:14 +0000 (10:53 +0200)]
Remove workarounds against repeat typedefs

This is allowed in C11, so we don't need the workarounds anymore.

Reviewed-by: Chao Li <[email protected]>
Discussion: https://www.postgresql.org/message-id/flat/10d32190-f31b-40a5-b177-11db55597355@eisentraut.org