1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00
Commit Graph

5369 Commits

Author SHA1 Message Date
Michael Paquier
0e0bf0d928 Replace OID8_FORMAT with more portable PRIu64
The OID8_FORMAT marker could break translated messages, as proven by
ceae3099da, so let's remove it while we can instead of encouraging its
use.

An alternative solution that would allow OID8_FORMAT is to save the
result into an intermediate string, itself used in the translated
strings, but per discussion this is not an appealing long-term approach.

Note that this commit partially reworks 072d4c4240.

Per discussion with Peter Eisentraut, Álvaro Herrera and Tom Lane.

Discussion: https://postgr.es/m/aqeO1OU7uZjhioAq@alvherre.pgsql
2026-09-28 12:34:29 +09:00
Etsuro Fujita
f25c50fd8f postgres_fdw: Improve comment in fetch_remote_statistics().
Mention that the relpages value fetched from a remote server is stored
as-is, regardless of any difference between the remote and local block
sizes.

Follow-up to commit 6a8571568.

Reported-by: Fujii Masao <masao.fujii@gmail.com>
Reported-by: Osama Abdul Qader <osamaabdulqader.cs@gmail.com>
Author: Etsuro Fujita <etsuro.fujita@gmail.com>
Discussion: https://postgr.es/m/CAPmGK14OBMkMEkanHdA9%2BJdrZLGzfNRcEVmb6K4DtDe_CTTTqw%40mail.gmail.com
Backpatch-through: 19
2026-09-26 20:40:00 +09:00
Etsuro Fujita
7d47e41238 Fix privilege handling in postgres_fdw statistics import.
When ANALYZE imports statistics from a remote server, it fetched/stored
the statistics while still running as the user executing ANALYZE, not as
the foreign table's owner.  This is inconsistent with the sampling path,
and it causes a security issue: a role that owns a foreign table but has
no access to the underlying remote data (eg, no access privileges on the
remote server) could obtain that data by having a privileged user run
ANALYZE on the table; the imported statistics like most_common_vals then
expose sampled values from the remote data, as shown in the reproducer
on the discussion thread.

To fix, switch to the foreign table owner's userid in analyze_rel()
before calling the ImportForeignStatistics() routine, mirroring the
identity used by the sampling path.   This not only makes the privilege
handling consistent between the sampling/import paths, but also prevents
statistics import from disclosing data the table owner couldn't
otherwise obtain.

Oversight in commit 28972b6fc.

Reported-by: Fujii Masao <masao.fujii@gmail.com>
Reported-by: Osama Abdul Qader <osamaabdulqader.cs@gmail.com>
Reported-by: Noah Misch <noah@leadboat.com>
Author: Noah Misch <noah@leadboat.com>
Reviewed-by: Matheus Alcantara <matheusssilv97@gmail.com>
Reviewed-by: Etsuro Fujita <etsuro.fujita@gmail.com>
Discussion: https://postgr.es/m/CAPmGK16jVk+i2KMkkgR9ajoPdaUAinvcspkk5Bc6urbo2xYTMQ@mail.gmail.com
Backpatch-through: 19
2026-09-26 20:35:00 +09:00
Tom Lane
87762cbaa4 Modernize crypt-des.c a bit, avoiding dubious casts.
The header comment for this file says it assumes that "the CPU is not
picky about alignment", which we wouldn't really accept for Postgres.
The two functions that have alignment requirements have been hacked in
ways that are inconsistent and yet both ugly.  des_setkey just casts
its "const char *" argument to "const uint32 *", relying on the caller
to ensure that that pointer is actually word-aligned, which the caller
does by declaring the buffer as uint32[] and then casting to "char *".
Meanwhile des_cipher carefully memcpy's to and from an internal
uint32[] buffer, which is pretty silly given that what it's passed
must be word-aligned for the benefit of des_setkey.  And on top of
that we have a bunch of ugly casting and oddly-written pointer
arithmetic in the caller px_crypt_des.  The odd pointer arithmetic
causes warnings about possible buffer overrun when using recent gcc
at -O3 or higher.

Let's clean this up by converting the buffer variable into a union
of a uint8 array and a uint32 array, so that we can remove all these
casts, and also replace the strange loop logic with a simple subscript
variable to satisfy gcc.

Reported-by: Andres Freund <andres@anarazel.de>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Co-authored-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Discussion: https://postgr.es/m/2005885.1790359097@sss.pgh.pa.us
Discussion: https://postgr.es/m/3nuudxv365kjnmwjhnygdakhxuktpdjvf26rt26eb44esgqdrj@y2x3vomkrfoo
Backpatch-through: 14
2026-09-25 15:34:38 -04:00
Michael Paquier
e27f3b2cad Remove duplicate definition of the compressed varlena header
toast_internals.h described the header of a compressed-in-line varlena
a second time, as toast_compress_header, with its own TOAST_COMPRESS_*
macros to read and write the tcinfo word.  varatt.h already describes
the same bytes as varattrib_4b.va_compressed and provides equivalent
macros that act as setter and getter of this information, as of
VARDATA_COMPRESSED_GET_EXTSIZE() and GET_COMPRESS_METHOD().

Let's remove the duplicate definition, and switch the TOAST code to use
the macros from varatt.h.  There should be no behavior change.

Note that toast_compression.h is removed from toast_internals.h, added
to the C files where its declarations are required.

Author: Nikhil Kumar Veldanda <veldanda.nikhilkumar17@gmail.com>
Author: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CAFAfj_FeJQZrKyVn7ur0aJx8iz8SR14NheVJNyc8JNoqtMX+og@mail.gmail.com
2026-09-25 14:24:06 +09:00
Melanie Plageman
5d84c76021 Add VM corruption check to verify_heapam()
Detect heap pages whose PD_ALL_VISIBLE flag is clear while either
visibility map bit is set. This inconsistent state can cause incorrect
index-only scan results and is not currently reported by verify_heapam().

This also helps users who have access to amcheck but not pg_visibility
to diagnose corruption.

Author: Melanie Plageman <melanieplageman@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/66mqpfyti3qhfttcsv6r2lbvqqd32rrmpn6i47ovrsnvguts46@gou54xc5jld3
2026-09-23 18:21:44 -04:00
Melanie Plageman
4a2f5533f3 Correct on-access VM setting heuristic
The heuristic to avoid setting the VM during on-access pruning when
doing so would emit an extra FPI missed a few cases. First it missed
temp and unlogged tables. Those will never emit an FPI, so they can
always set the VM if the page is all-visible. It also missed that if
hint bits are not WAL-logged, setting only the VM passes REGBUF_NO_IMAGE
for an already WAL-logged heap page, forbidding a heap FPI in the WAL
record. A page that has never been WAL-logged still requires a heap FPI.

The third is more subtle: If the page is all-visible, the new prune xid
will be InvalidTransactionId. On-access pruning only executes when the
current pd_prune_xid is valid and visible. So, when on-access pruning
finds the page all-visible, it will always clear pd_prune_xid, modifying
the page.

Knowing this means we can set the VM without emitting an extra heap FPI
in more cases. When hint bits are WAL-logged, if the heap buffer is
clean, modifying pd_prune_xid will emit an FPI if one is required. There
is no reason to try to avoid an FPI by not setting the VM. So, set the
VM in this case. However, when the heap buffer is already dirty,
modifying pd_prune_xid can avoid an FPI; so if the page hasn't been
logged since the last checkpoint, setting it all-visible will emit an
extra heap page FPI. We will still avoid setting the VM in this case.

This is being backpatched to 19 because since 378a216187 pd_prune_xid
is set on insert, and if we execute a prune cycle and skip setting the
VM because of an incorrect heuristic, we have added new wasted work in
PG 19.

This commit adds some tests covering these cases. It also updates one of
the existing temp table tests to avoid exceeding the pin limit. Setting
the VM and FSM on-access when querying temp tables takes more local pins
and can run into the limit with fewer heap buffers pinned.

Reported-by: Melanie Plageman <melanieplageman@gmail.com>
Author: Melanie Plageman <melanieplageman@gmail.com>
Reviewed-by: Andrey Borodin <x4mmm@yandex-team.ru>
Discussion: https://postgr.es/m/CAAKRu_amj7qLF4c=9ijd=708Fu2G8gg-2EqwBu=aCdAHU2sPHg@mail.gmail.com
Backpatch-through: 19
2026-09-23 16:37:23 -04:00
John Naylor
a1c37421a8 Clean up usage of hash_any() and hash_any_extended()
Back in the days before a91e2fa94, hash_any() was the primary hash
function and it returned a Datum. That commit changed hash_any() to a
wrapper over hash_bytes(). Some places actually wanted the underlying
uint32 from hash_bytes(), but that now presents as useless round-trip
casting, so update the call sites where we don't immediately need a
Datum.

hash_numeric() didn't have round-trip casting, but it was internally
inconsistent: Paths returning a constant used PG_RETURN_UINT32(), but
the path using the result of hash_any() used PG_RETURN_DATUM. Change
it to use uint32 throughout.

Author: Aleksander Alekseev <aleksander@tigerdata.com>
Suggested-by: John Naylor <johncnaylorls@gmail.com>
Reviewed-by: Zsolt Parragi <zsolt.parragi@percona.com>
Discussion: https://postgr.es/m/CAJ7c6TMPhDRQMmkUHPv8oOK97B1mR8NRS61DgjpdaZUPAwaeZQ%40mail.gmail.com
2026-09-23 17:33:11 +07:00
Etsuro Fujita
bea01b825c postgres_fdw: Fix oversights in fetch_attstats().
The query to get attribute statistics from a remote server applied the
"C" collation to a column of type name without checking the server's
version.  Since the name type was made collatable in Postgres 12, this
could break attribute statistics import if the server was older.  Fix by
casting the column value to text before collating it if the server is
older.

Also, fix a typo in the if-test in the same function.

Oversights in commit 28972b6fc; the former was reported by Fujii Masao.

Reported-by: Fujii Masao <masao.fujii@gmail.com>
Author: Etsuro Fujita <etsuro.fujita@gmail.com>
Reviewed-by: Corey Huinker <corey.huinker@gmail.com>
Discussion: https://postgr.es/m/CAHGQGwGvA_3q7Wg7GXQkuugGZj3%3DkxDRjDsKgVvK1uwAxHTopQ%40mail.gmail.com
Backpatch-through: 19
2026-09-18 17:45:00 +09:00
Robert Haas
e1d8f81d49 pg_plan_advice: Fix defects in JOIN_ORDER advice feedback.
This commit fixes several related problems. All of these problems
escaped testing for the same reason: they do not occur when only
generated advice is supplied, and therefore test_plan_advice was
incapable of detecting these shortcomings.

First, prior to this commit, the advice feedback code never regarded
an unordered sublist of a JOIN_ORDER specification as matching an
unrolled join. As a result, when JOIN_ORDER() advice contained
unordered sublists, the advice feedback tended to be "matched, failed"
even when the advice worked exactly as intended. Only the case where
an unordered sublist was implemented by a plan shape not subject to
unrolling, such as a partitionwise join, worked properly.

Second, prior to this commit, a join order sublist in the initial
position wasn't properly handled. Note that this overlaps with the
problem described in the previous paragraph; JOIN_ORDER({a b} c) was
broken both because of the unordered sublist and because of the
sublist being in the initial position. However, there's more to this
case: JOIN_ORDER((a b) c) means the same as JOIN_ORDER(a b c), but the
advice feedback code didn't know that, and would generate "matched,
failed" for the former case even when everything was working.

Finally, prior to this commit, advice feedback didn't correctly handle
single-element sublists. Those are pretty nonsensical, since by
definition a join involves at least 2 tables, so we could just ban
that case. Instead, at least for now, I've chosen to make advice
feedback handle such cases in the same way that advice enforcement
already does: the extra grouping levels are simply disregarded, so
that JOIN_ORDER({a} ((b))) is enforced in the same way as, and also
gets the same advice feedback as, JOIN_ORDER(a b).

Reported-by: Noah Misch <noah@leadboat.com>
Backpatch-through: 19
Discussion: https://postgr.es/m/CA+TgmoYmXy-jiP5qDhqNEiYFEBzQsArO6O2d9E8szNZqi1bePQ@mail.gmail.com
Reviewed-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
2026-09-17 11:15:52 -04:00
Michael Paquier
be00f041a3 Fix typos and grammar of some comments
These errors have been reported to the mailing lists in the last few
weeks.  Some of the spots fixed have been noticed by myself during
independent code reviews, but not all.
2026-09-17 16:50:44 +09:00
Robert Haas
63920eb099 pg_plan_advice: Disallow partition name without partition schema.
Up until now, pg_plan_advice has had a feature that allows an advice
target to mention a partition name but omit the partition schema;
that is, something like SEQ_SCAN(foo/bar) forces a sequential scan on
every child of table foo whose partition name is bar, regardless of
the schema in which bar appears. However, that feature turns out to
have a nasty design flaw: while advice enforcement handles this case
just fine, the advice feedback code doesn't know about it and will
mark such advice as "matched, failed" even when everything worked
perfectly. Unfortunately, there seems to be no simple code fix for
this problem.

Since the release of PostgreSQL 19 is imminent, take the conservative
course and revert this feature of pg_plan_advice. In other words,
require the partition schema whenever the partition name is present.
You must now write e.g. SEQ_SCAN(foo/public.bar) rather than just
SEQ_SCAN(foo/bar). This doesn't affect any cases where automatically
generated advice is supplied, since generated advice has always
included the partition schema anyway. Manually written advice will
have to conform to the new, stricter rule. For a later release, we
can consider whether to again relax this restriction in some way,
but now is not the time to design new things.

Reported-by: Noah Misch <noah@leadboat.com>
Backpatch-through: 19
Discussion: https://postgr.es/m/CA+TgmoYmXy-jiP5qDhqNEiYFEBzQsArO6O2d9E8szNZqi1bePQ@mail.gmail.com
2026-09-16 21:03:58 -04:00
Robert Haas
5e595d659f pg_plan_advice: Disallow empty sublists within JOIN_ORDER()
Commit 8c9c2e5c09 fixed a similar
issue for FOREIGN_JOIN(). Handle this case similar to the way that
commit handled that case.

Backpatch-through: 19
Discussion: https://postgr.es/m/CA+TgmoYmXy-jiP5qDhqNEiYFEBzQsArO6O2d9E8szNZqi1bePQ@mail.gmail.com
Reviewed-by: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
2026-09-16 14:44:42 -04:00
Michael Paquier
87c6ef14f1 Tweak tests related to oid8 in amcheck and test_decoding
Some of the tests introduced by c68cba09dd in these two modules want
to rely on out-of-line values (compressed and not compressed), but the
values inserted that should be compressed were not (STORAGE EXTENDED).

The tests are updated to do what they should, reusing a cheap trick to
ensure out-of-line values coming from a different test in test_decoding.
Some checks are added to ensure that the expected set of values is
inserted.

Reported-by: Rui Zhao <zhaorui126@gmail.com>
Discussion: https://postgr.es/m/CAHWVJhGxVc4CpDd+mb=6YbeL2KHDUtsUC=R68y7NeMg1cO8QMg@mail.gmail.com
2026-09-16 10:00:24 +09:00
Peter Geoghegan
ddce1da5b1 Add slot-based table AM index scan interface.
Add table_index_getnext_slot, a new table AM interface that serves as
the single entry point for both plain and index-only index scans that
use amgettuple.  The table AM's index_scan_begin callback resolves which
implementation the scan will use and stores it in an IndexScanDesc
function pointer (xs_getnext_slot), which table_index_getnext_slot
dispatches through.

The interface intentionally avoids using fixed TableAmRoutine members,
allowing the table AM to dynamically register an implementation based on
conditions known at the start of each scan.  That way a table AM can
provide specialized variants that help the compiler produce more
efficient code.  heapam provides two implementations: one for plain
index scans, and one for index-only scans.  An upcoming commit that adds
the amgetbatch interface will add two more.  (Table AMs can opt to
provide a single generic implementation, or to provide many specialized
implementations, as requirements dictate.)

heapam's xs_getnext_slot implementations make aggressive use of forced
inlining to ensure that plain and index-only code paths are fully
specialized at compile time, without duplicating the code they have in
common.  This specialization is necessary to keep icache and iTLB
pressure to a minimum.

The new interface moves visibility map checks required by index-only
scans out of the executor (and selfuncs.c) and into heapam, enabling
batching of visibility map lookups (though for now we continue to just
perform retail lookups).  Using the new higher level slot-based
interface greatly simplifies nodeIndexonlyscan.c, which no longer has to
deal with the visibility map directly.  More importantly, this is a
significant architectural improvement: table AMs can now implement
index-only scans that are not tied to heapam's visibility map.

Two users of the now removed table_index_fetch_tuple interface,
_bt_check_unique and unique_key_recheck, fundamentally need to pass a
TID to the table AM to perform constraint enforcement.  Neither actually
performs an index scan (even though their TIDs are taken from an index),
so neither has any use for most of the index scan machinery.  Switch
these callers over to fetch_tid, a new special-purpose table AM
interface for constraint enforcement code.  All true index scan callers
now use the new slot-based interface.  (Note that fetch_tid doesn't
perform on-access pruning, which matches how things worked prior to
Postgres 12 commits c2fe139c2 and 71bdc99d0.)

The VISITED_PAGES_LIMIT mechanism used by get_actual_variable_range to
cap scan overhead during planning is reworked to go through a new scan
descriptor field (xs_visited_pages_limit), rather than having selfuncs.c
count heap page fetches and terminate the scan itself.  This is
necessary because callers that use the new slot-based interface no
longer have direct access to which heap blocks were fetched.  Similarly,
nodeIndexonlyscan.c can no longer use InstrCountTuples2 to count heap
fetches during an EXPLAIN ANALYZE.  EXPLAIN ANALYZE now obtains this
information from a new IndexScanInstrumentation field, which table AMs
are required to maintain during index-only scans.

Though independently useful, this commit is preparatory work for an
upcoming commit that will add an amgetbatch index AM interface, where
the table AM takes full responsibility for managing the progress of
index scans.  The table AM determines when to request the next batch
from the index AM, at a time of its choosing.  A follow-on commit will
rely on this to prefetch table blocks during index scans.  Having a
single entry point for all index scan callers unambiguously puts the
table AM in control of the scan.

Author: Peter Geoghegan <pg@bowt.ie>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Tomas Vondra <tomas@vondra.me>
Reviewed-by: Rui Zhao <zhaorui126@gmail.com>
Discussion: https://postgr.es/m/CAH2-WzmYqhacBH161peAWb5eF=Ja7CFAQ+0jSEMq=qnfLVTOOg@mail.gmail.com
2026-09-15 11:19:13 -04:00
Peter Eisentraut
a4b26b8f7c Revert UPDATE/DELETE FOR PORTION OF
List of commits reverted:

  8e72d914c5  Add UPDATE/DELETE FOR PORTION OF
  b6ccd30d8f  Add isolation tests for UPDATE/DELETE FOR PORTION OF
  33db6c4baf  Fix DELETE/UPDATE FOR PORTION OF with rules
  7b22f15a01  Add psql tab completion for FOR PORTION OF clause
  7ca8c94296  Fix FOR PORTION OF with non-updatable view columns
  993a7aa0e4  Fix cross-leftover pollution in FOR PORTION OF insert triggers
  7ac030d5b1  Require UPDATE permission on FOR PORTION OF column
  f0aedc7cb0  Small terminology fixes in comments
  7d13b03a2e  Fix FOR PORTION OF for inheritance children
  a272a58b94  Move FOR PORTION OF volatile check into planner
  a40fdf6588  Reject child partition FDWs in FOR PORTION OF
  bc3ae886a7  Forbid FOR PORTION OF with WHERE CURRENT OF
  e994f956e4  Forbid generated columns in FOR PORTION OF
  dfce19c230  Forbid FOR PORTION OF on views with INSTEAD OF triggers
  20fe90bbb9  Fix RLS checks for FOR PORTION OF leftover rows
  9170c8b716  Test what BEFORE UPDATE triggers do to FOR PORTION OF
  7090c696cc  Deparse FOR PORTION OF using the range column's current name.
  62d1a5f8be  Avoid RETURNING side effects for FOR PORTION OF leftovers.
  9924e2d900  Enforce WITH CHECK OPTION on DELETE FOR PORTION OF leftovers
  c16a1b4f2c  Fix error code for null FOR PORTION OF target
  610976420a  Fix assertion failures in DELETE FOR PORTION OF tuple routing
  438f027238  Resolve untyped parameters in FOR PORTION OF FROM/TO bounds
  140fdfcdf1  Don't evaluate the FOR PORTION OF target under EXPLAIN

Discussion: https://www.postgresql.org/message-id/62bf70cc-dc33-4188-8070-a8c177bb61de%40eisentraut.org
2026-09-15 12:12:37 +02:00
Peter Eisentraut
f292187f37 Fix indirect include
Commit 0ee83dd4a9 added a call of assign_record_type_typmod() in
postgres_fdw.c, but relied on utils/typcache.h being included via
nodes/execnodes.h.  That was put there as part of the FOR PORTION OF
feature, and if that were to change, there would be a possible
unrelated compilation failure.  To fix, add the required include
directly.
2026-09-15 11:06:49 +02:00
Michael Paquier
0d34736e4c amcheck: Fix thinko with check of TOASTed attribute
A chunk_id type that does not match with one of the expected values (oid
or oid8) was missing a "return" clause.  This caused the code to report
two corruptions instead of one.

Oversight in 6e58d6356f.

Discussion: https://postgr.es/m/aqju1K96ex28yz2X@paquier.xyz
2026-09-15 16:48:44 +09:00
Michael Paquier
6e58d6356f Add support for external on-disk TOAST pointers as oid8
A TOAST table whose chunk_id column is oid8 is now fed a 64-bit object
ID thanks to the introduction of a new vartag_external called
VARTAG_ONDISK_OID8, coupled with a new varatt_external_oid8.  The only
difference between the existing varatt_external_oid and the new
varatt_external_oid8 is an extra 4 bytes to store 8 bytes worth an
object ID, spread across two uint32 to force alignement as memcmp may be
used for TOAST pointer comparison (line varatt_external_oid).

There is a one-one mapping between the vartag_external and the type of a
chunk_id:
- An oid8 chunk_id implies the use of VARTAG_ONDISK_OID8.
- An oid chunk_id implies the use of VARTAG_ONDISK_OID.

There are a couple of changes worth noting:
- In toast_tuple_init(), for the comparison of old and new external
values with a memcmp over VARSIZE_EXTERNAL(old_value).  Now that
multiple types of external on-disk TOAST pointers are possible, we
need to add a check based on the vartag used by an old or new value.
One of the tests added by c68cba09dd cover this case.
- In toast_tuple_find_biggest_attribute(), the initial "biggest_size"
depends on the type of chunk_id.  This needs a change in RelationData to
track the chunk_id type; this cached data is filled on demand.
- In detoast.h, toast_external_info_get() and toast_external_data act as
a translation layer to retrieve all the data associated to an Oid or an
Oid8 TOAST pointer, without the need to worry about the vartag dealt
with.  The introduction of this function and structure has reduced a lot
of code churn that existed in the initial versions of this patch, as per
a suggestion from Bharath Rupireddy.
- amcheck is updated to check the vartag <-> chunk_id type mapping
requirements, handling both vartags depending on the underlying type of
chunk_id on the TOAST table.

Bump catalog version, due to at least the change of VARTAG_SIZE().
(This counts for the bump forgotten in a625fc570c22..)

Author: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Greg Burd <greg@burd.me>
Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Reviewed-by: Yugo Nagata <nagata@sraoss.co.jp>
Discussion: https://postgr.es/m/af19kUjwjhaoUTLn@paquier.xyz
2026-09-15 15:00:01 +09:00
Michael Paquier
c68cba09dd Add battery of tests related TOAST tables with oid8
The tests added by this commit cover a large ground in terms of the
introduction of oid8 in TOAST tables, with the following areas covered,
with all the gaps found during the development of the feature:
- Tables with oid8 TOAST tables in general, under strings.sql.
- ALTER TABLE with attribute manipulations in transactions and different
toast_table_value settings.
- Relation rewrites, not affecting the TOAST relation after initial
creation with VACUUM FULL, CLUSTER, REPACK.
- pg_column_compression().
- test_decoding, for external and extended TOAST data.
- amcheck, external and extended storage with heap checked.
- UPDATE with out-of-line datums that belongs to another TOAST table.
This offers coverage for toast_tuple_init(), where external vartags
could be mixed once multiple on-disk external TOAST pointers can
co-exist.  This pattern can be triggered with asan/ubsan, with an
out-of-bound memcpy when unpatched.

These tests are added before the new vartag_external, mostly as a matter
of avoiding dead code in the tree.

Author: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Greg Burd <greg@burd.me>
Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Reviewed-by: Yugo Nagata <nagata@sraoss.co.jp>
Discussion: https://postgr.es/m/af19kUjwjhaoUTLn@paquier.xy
2026-09-15 11:30:45 +09:00
Michael Paquier
a625fc570c Add support for toast_value_type=oid8
This commit adds the possibility to define TOAST tables with oid8 as
their chunk_id, based on the reloption toast_value_type.  All the
external TOAST pointers still rely on varatt_external_oid and a single
vartag.  The values inserted in the oid8 TOAST tables are fed from the
OID8 value generator, casted to OID for now, as we do not have a
vartag_external able to store Oid8 values yet.

An upcoming commit will add support for a new vartag_external and its
associated structures, with the code being able to use a different
on-disk external TOAST pointer depending on the attribute type of
chunk_id defined in TOAST relations.

All the changes done here are mechanical, mostly around the TOAST code
that needs to be able to do chunk_id lookups based on the two types now
supported.

Bump catalog version.

Author: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Greg Burd <greg@burd.me>
Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Reviewed-by: Yugo Nagata <nagata@sraoss.co.jp>
Discussion: https://postgr.es/m/af19kUjwjhaoUTLn@paquier.xy
2026-09-15 08:37:06 +09:00
Etsuro Fujita
3ca4abd60c postgres_fdw: Disable attribute statistics import from pre-9.1 servers.
To import attribute statistics, postgres_fdw sent a query wity COLLATE
"C" to remote servers without checking their version.  Since COLLATE is
only supported since v9.1, this could break the import against older
servers; fix by modifying postgres_fdw to check their version and if
older, fall back to sampling.  (This commit still allows importing only
relation statistics from such an older server.)

Also, expand the documentation to mention that attribute statistics are
stored into the local server without applying the foreign table columns'
n_distinct option.

Oversight in commit 28972b6fc.

Reported-by: Fujii Masao <masao.fujii@gmail.com>
Reported-by: Osama Abdul Qader <osamaabdulqader.cs@gmail.com>
Author: Etsuro Fujita <etsuro.fujita@gmail.com>
Reviewed-by: Corey Huinker <corey.huinker@gmail.com>
Discussion: https://postgr.es/m/CAHGQGwH8%2BuDTwfohpck9v_9L3nwSWACbmC36JYRyqHd5xQN_OA%40mail.gmail.com
Backpatch-through: 19
2026-09-14 19:00:00 +09:00
Michael Paquier
072d4c4240 Refactor some TOAST value ID code to use Oid8 instead of Oid
This is a mechanical update to change most of the TOAST code paths that
assume TOAST value IDs to be Oid variables to become Oid8 variables,
easing an the introduction of an upcoming patch to allow larger TOAST
values, at 8 bytes.

The areas touched by the change are related to table AM, amcheck and
logical decoding's reorder buffer.  A good chunk of the changes involve
switching printf() markers from %u to OID8_FORMAT.

For the sake of the release notes in terms of compatibility (perhaps
worth mentioning, or not), note that this changes some callback
definitions in the table AM section, upgrading some TOAST callbacks to
use Oid8 instead of Oid when referring to a TOAST value.

Author: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Greg Burd <greg@burd.me>
Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Reviewed-by: Yugo Nagata <nagata@sraoss.co.jp>
Discussion: https://postgr.es/m/af19kUjwjhaoUTLn@paquier.xy
2026-09-14 10:00:31 +09:00
Álvaro Herrera
0c5d626961 Fail REPACK in presence of !indisready indexes
Like VACUUM FULL, non-concurrent REPACK would try to rebuild such
indexes, which can sometimes succeed.  Concurrent REPACK would however
fail.  The inconsistency is not good, so make them both throw an error
quickly to force the user to make a decision on those indexes (most
likely, drop them).

Author: Álvaro Herrera <alvherre@kurilemu.de>
Reported-by: Zsolt Parragi <zsolt.parragi@percona.com>
Suggested-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Discussion: https://postgr.es/m/CAN4CZFO5A3YE0Dd-bn7eKrB20pECO3=U0wKg1z2rO=DxgWJJHQ@mail.gmail.com
2026-09-13 14:06:00 +02:00
Álvaro Herrera
c1c5d28f4a Disallow REPACK (CONCURRENTLY) when replica identity index is dropped
The replica identity determination was "flawed": it fell back to the
primary key if the marked index was dropped, which is a defensible
choice, but logical decoding has a differing opinion and fails to
provide usable tuple identity data in this case.  "Fix" REPACK by
refusing to use the primary key in that case.

This is arguably broken behavior in RelationGetIndexList, but I'll
refrain from changing that at this stage.

Reported-by: Nathan Bossart <nathandbossart@gmail.com>
Author: Matthias van de Meent <boekewurm+postgres@gmail.com>
Author: Ewan Young <kdbase.hack@gmail.com>
Backpatch-through: 19
Discussion: https://postgr.es/m/apCBRKCH8jwKiaSY@nathan
2026-09-11 13:42:45 +02:00
Robert Haas
3117cf3882 pg_plan_advice: Document interaction with GEQO.
The general nature of this interaction has been understood (at least
by me) since before the original commit, but I failed to explicitly
document it. I also left behind an XXX in the README which I intended
to remove before commit. Fix those things.

Reported-by: Noah Misch <noah@leadboat.com>
Backpatch-through: 19
Discussion: https://postgr.es/m/CA+TgmoYmXy-jiP5qDhqNEiYFEBzQsArO6O2d9E8szNZqi1bePQ@mail.gmail.com
2026-09-10 13:54:30 -04:00
Robert Haas
f15036f20b pg_plan_advice: pgindent
Oversight in 1129570f65

Reported-by: Nazir Bilal Yavuz <byavuz81@gmail.com> (off-list)
Backpatch-through: 19
2026-09-10 13:46:26 -04:00
Etsuro Fujita
9f4bd91a19 postgres_fdw: Adjust warning message in statistics import.
The previous warning message when falling back to sampling in a certain
case failed to properly mention the reason for that.

Also, for clarity, rewrite a comment about the fallback and add a note
about it to postgres-fdw.sgml.

Follow-up to commit 6a8571568.

Reported-by: Fujii Masao <masao.fujii@gmail.com>
Author: Etsuro Fujita <etsuro.fujita@gmail.com>
Reviewed-by: Corey Huinker <corey.huinker@gmail.com>
Discussion: https://postgr.es/m/CAHGQGwHq1VuXwxeDU8N4dd9U4RFEW982qQ9C26mRQDs3nu_Naw%40mail.gmail.com
Backpatch-through: 19
2026-09-10 17:30:00 +09:00
Fujii Masao
3430fba3b0 postgres_fdw: Fix crash when estimating joins with functions
Commit 0ee83dd4a9 allowed postgres_fdw to push down inner joins between
foreign tables and functions in FROM clauses to the remote server.
However, planning such a join with use_remote_estimate enabled could
cause a segmentation fault. For example, the following query crashed
when ft had use_remote_estimate set to true:

    EXPLAIN SELECT * FROM generate_series(1, 3) g JOIN ft ON ft.i = g;

The crash occurred because init_func_stub_fpinfo() copied the connection
information and options from the foreign side to the function-side stub,
but omitted the user mapping, leaving it NULL. When the function was the
outer side of the join, the join inherited this NULL mapping and passed it
to GetConnection() when requesting a remote estimate, causing a
segmentation fault.

Fix this by having init_func_stub_fpinfo() also copy the user mapping
from the foreign side.

Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Alexander Pyhalov <a.pyhalov@postgrespro.ru>
Discussion: https://postgr.es/m/CAHGQGwGE9xPzCke0C0r4omTkh-hU08aBd2j9oSA0FYmJLCf9jA@mail.gmail.com
2026-09-10 09:46:44 +09:00
Robert Haas
1129570f65 pg_plan_advice: Add CHECK_FOR_INTERRUPTS() and check_stack_depth()
Without CHECK_FOR_INTERRUPTS(), backends might not respond to query
cancellations in a timely fashion, especially for JOIN_ORDER()
specifications, where matching against each join can take O(n^2) time
in the length of the join order list in degenerate cases.

Recursive functions should check_stack_depth().

Reported-by: Noah Misch <noah@leadboat.com>
Discussion: https://postgr.es/m/CA+TgmoYmXy-jiP5qDhqNEiYFEBzQsArO6O2d9E8szNZqi1bePQ@mail.gmail.com
Backpatch-through: 19
2026-09-09 17:49:33 -04:00
Masahiko Sawada
4964c75b08 Unify REPACK (CONCURRENTLY) error messages.
Commit 86f7c82cf1 reported the user catalog table restriction as a
detail, but the other checks in check_concurrent_repack_requirements()
were still a mix: some were hints, and the details repeated
"REPACK (CONCURRENTLY)", which the primary message already names.

Report them as details with the same "This operation ..." wording. The
one actionable hint, ALTER TABLE ... REPLICA IDENTITY USING INDEX,
stays.

Backpatch to v19, where REPACK (CONCURRENTLY) was introduced.

Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Suggested-by: Alvaro Herrera <alvherre@kurilemu.de>
Discussion: https://postgr.es/m/apBIFWzHYOaG0auN%40nathan
Backpatch-through: 19
2026-09-09 13:45:43 -07:00
Álvaro Herrera
412ef97d92 Fix error message for concurrent repack on materialized views
Previously, running REPACK (CONCURRENTLY) on a materialized view failed
with a confusing "has no identity index" error.

REPACK (CONCURRENTLY) replays changes decoded from WAL, but a
materialized view produces none, since it cannot be modified by DML and
REFRESH rewrites it through a transient heap that is not logically
decoded.

Fix this by reporting a clear error for materialized views upfront,
alongside the existing checks for system catalogs and TOAST tables, and
document the limitation.

Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Reviewed-by: Kiran Kaki <itskkpg@gmail.com>
Backpatch-through: 19
Discussion: https://postgr.es/m/CALj2ACXPvy4_LkQ0nHKgbZjAGK9fkDqRYUvXA3hgwxPm_X7Eng@mail.gmail.com
2026-09-09 12:58:00 +02:00
Masahiko Sawada
86f7c82cf1 Restrict REPACK (CONCURRENTLY) on user catalog tables.
REPACK (CONCURRENTLY) is not an MVCC-safe operation; it doesn't
preserve the visibility information, which logical decoding needs
because it reads user catalog tables under a historic snapshot.

Disallow REPACK (CONCURRENTLY) on user catalog tables. Removing this
check requires making it MVCC-safe and logical rewrite mappings.

Backpatch to v19, where REPACK (CONCURRENTLY) was introduced.

Reported-by: Nathan Bossart <nathandbossart@gmail.com>
Author: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Reviewed-by: Antonin Houska <ah@cybertec.at>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Reviewed-by: Alvaro Herrera <alvherre@kurilemu.de>
Discussion: https://postgr.es/m/apBIFWzHYOaG0auN%40nathan
Backpatch-through: 19
2026-09-08 13:04:56 -07:00
Robert Haas
dc33cca185 pg_stash_advice: Fix failure to reload empty advice string.
There's not really any good reason to store an empty advice string
in an advice stash, but it's entirely possible that some people might
do it by accident. If they do that without this fix, restarting the
system will result in failure while reloading pg_stash_advice.tsv.

The root cause is that I (rhaas) did not think clearly enough when
defining pgsa_next_tsv_field(). After returning each field on the
line, it set *cursor to the start of the next field, and after
returning all of them, it set *cursor to the trailing NUL byte. But
when the last field on the line is empty, this is ambiguous: if we're
pointing at the trailing NUL byte, it could be either because it's the
start of the zero-length field or because we're out of fields. To
remove the ambiguity, this commit decides that *cursor will instead
be set to NULL when there are no more fields.

Reported-by: Noah Misch <noah@leadboat.com>
Discussion: https://postgr.es/m/20260827171830.68.noahmisch@microsoft.com
Backpatch-through: 19
2026-09-08 10:03:52 -04:00
Peter Eisentraut
f9fc9a78a3 Fix -Wshadow=local warnings
This fixes issues with the same variable name being used in the same
function for two different variables.  (In some cases, one of the uses
is a function argument.)  The fix is in most cases to rename one or
both of them.  The individual choice depends on conventions in the
surrounding code.  Often, making both variable names more specific is
the best choice.  In a few cases, the fix is to move one of the
variables to a lower scope, so that it no longer conflicts with the
other.

Since these are all local-variable conflicts, the changes in different
files in this patch are independent of each other.

These issues correspond to the gcc warning option -Wshadow=local,
which is not currently used but could be activated after this.

Reviewed-by: Peter Geoghegan <pg@bowt.ie>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/84b6f128-91f5-480e-8a9e-7d0e8f538cea%40eisentraut.org
2026-09-08 08:49:30 +02:00
Peter Eisentraut
b1f106c80c Revert SQL Property Graph Queries (SQL/PGQ)
List of commits reverted:

  2f094e7ac6  SQL Property Graph Queries (SQL/PGQ)
  cd8844e7db  Make some tests more stable by adding more explicit ordering
  182cdf5aea  pg_dump: Add appropriate version check
  c9babbc881  Dump labels in reproducible order
  040a56be4b  Cleanup users and roles in graph_table_rls test
  5282bf535e  Fix some typos and make small stylistic improvements
  720f0f89d6  Reject consecutive element patterns of same kind
  288ae96872  Add a graph pattern variable only once
  c5b3253b8a  Property references are preferred over regular column references
  a0dd0702e4  Fix cross variable references in graph pattern causing segfault
  2ff289d039  Check for stack overflow when rewriting graph queries
  9082680c34  Fix typos and grammar in graph table rewrite code
  ac3bcc041c  Fix collation of expressions in GRAPH_TABLE COLUMNS clause
  9d2979dd68  pg_get_viewdef() and lateral references in COLUMNS of GRAPH_TABLE
  891a57c739  Do not define type for a property graph
  dc9e7c9ed9  Handle nodes that may appear in GraphPattern expression trees
  f6edd8ed70  Add ORDER BY to test query to stabilize test
  1190f858ea  doc: Small synopsis wording change for consistency
  d0eac3cafb  Make spelling consistent
  6827de95ee  Simplify code in objectaddress.c for some property graph objects
  5778fb3eaf  Fix typo in error message
  72498a8698  Handle element label and label property objects in object address functions
  4cb2a9863d  Fix LATERAL references in GRAPH_TABLE with multi-label pattern
  9d8cdcbe0c  Record dependencies on graph labels and properties
  2a7e95b659  Readable identity strings for property graph objects
  7afa11feca  Prevent dropping the last label from a property graph element
  96418a6da9  Fix handling of dropping a property not associated with the given label
  efd7d8d7d4  Resolve unknown-type literals in GRAPH_TABLE COLUMNS
  e0ff7fd9aa  Make property graph object descriptions better translatable
  0e4f0827f6  Fix properties orphaned by dropping a label
  73dfe79fd6  Remove apparent support for SECURITY LABEL ON PROPERTY GRAPH
  592de8bd21  Fix pg_dump ACL minimization for PROPERTY GRAPH.
  16a4b3ef8e  Fix replace_property_refs() ignoring the root of expression tree
  57f93af36f  Resolve unknown-type literals in property expressions
  2e6578292a  Prohibit locking clauses on GRAPH_TABLE
  2521f9e75e  doc: Fix SQL quoting in example
  0316593146  Restore the ability to use | and -> as prefix operators.
  780fa49746  Fix missing space before WHERE in GRAPH_TABLE deparse
  fa62d4f6ea  Prohibit GRANT ... ON TABLE on a property graph
  63c3bbb39f  doc: Add PROPERTY GRAPH to the access privilege tables
  0a51a06cdb  More tab-completion for DROP PROPERTY GRAPH
  f585671055  Disallow aggregates, window functions, and SRFs in GRAPH_TABLE COLUMNS
  9b917a9311  Report duplicate property and label names with a proper error
  a82e33a83d  Make generate_queries_for_path_pattern_recurse() interruptible
  3c982c9bf1  Add test for view referencing labels shared by vertex and edge tables
  8646d1d590  Fix inferred property graph keys with INCLUDE columns
  0417bf5296  Fix pg_event_trigger_ddl_commands for GRANT ON PROPERTY GRAPH
  a20d3e35f2  doc: reformat GRAPH_TABLE examples
  792094a5ce  Coerce GRAPH_TABLE pattern WHERE clauses to boolean

plus typedefs.list changes.

Discussion: https://www.postgresql.org/message-id/CAAKRu_bEtjWYWhYxSo0o_t3DaZYRQd5PkC0abA0g9Mp4%2BovH0w%40mail.gmail.com
2026-09-07 21:00:55 +02:00
Michael Paquier
c5806f2165 Rename varatt_external to varatt_external_oid
This impacts a few more definitions, related to this structure, as of:
- VARTAG_ONDISK -> VARTAG_ONDISK_OID
- TOAST_POINTER_SIZE -> TOAST_OID_POINTER_SIZE
- TOAST_MAX_CHUNK_SIZE -> TOAST_OID_MAX_CHUNK_SIZE
- Macros in varatt.h for varatt_external_oid.

This rename is part of a conversation to add support for more types of
external TOAST pointers, not only OID.  One of them is to extend the
pointers to use an OID8 variant.  The control file field for the max
chunk size is left out, for now.

Author: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Yugo Nagata <nagata@sraoss.co.jp>
Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Discussion: https://postgr.es/m/CALj2ACVnO6jjs5aRx3dSOBy9LV7=iakPBR1eOvoeB8rL8Q47zg@mail.gmail.com
Discussion: https://postgr.es/m/apoD1Ulet2PtDrRV@paquier.xyz
2026-09-07 08:45:23 +09:00
Etsuro Fujita
6a85715682 postgres_fdw: Fix issues with statistics import.
When analyzing a foreign table pointing to a partitioned or inherited
table on the remote server, this method just imported relpages and
reltuples for the parent table from the remote pg_class, causing a
discrepancy or an error in results compared to the sampling method.

* In the partitioning case, while the sampling method sets relpages=0,
  this method set relpages=-1.  (For reltuples, the results of both
  methods match.)
* In the inheritance case, while the sampling method sets
  reltuples=(# of rows in the parent and child tables), this method set
  reltuples=(# of rows in the parent table).  (For relpages, the results
  of both methods match.)

As relpages and reltuples are used for costing foreign paths, these
would lead to incorrect plans or plan changes depending on the method.
To fix, do the following:

* For the partitioning case, modify postgres_fdw to set relpages=0 to
  match the sampling method.
* For the inheritance case, we could also modify it to set the correct
  reltuples value by fetching reltuples for the child tables as well,
  but 1) the change isn't small, and 2) table inheritance hasn't been
  used that much these days, so fix by disabling this method.

While at it, adjust comments and docs slightly.

Oversight in commit 28972b6fc.

Author: Etsuro Fujita <etsuro.fujita@gmail.com>
Discussion: https://postgr.es/m/CAPmGK173b2Xvyoeq%3DY7L09H%2BajgMgxC2fYe%3D7CCunZz8tGTfFA%40mail.gmail.com
Backpatch-through: 19
2026-09-04 18:40:00 +09:00
Michael Paquier
2b3d11aaed Minimize footprint of TOAST_MAX_CHUNK_SIZE in heap and amcheck code
This refactoring eases a little bit a follow-up change to add support
for 8-byte TOAST value IDs, as the maximum chunk size allowed for a
single chunk of TOASTed data depends on the size of varatt_external, its
value ID being part of it.

It is worth noting that TOAST_MAX_CHUNK_SIZE resolves as a uintptr_t, so
the previous calculations were in 64-bit unsigned arithmetic.  These are
now done in int32, which still works the same way due to an external
TOAST value being bounded to 1GB.

Author: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Yugo Nagata <nagata@sraoss.co.jp>
Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Discussion: https://postgr.es/m/CALj2ACVnO6jjs5aRx3dSOBy9LV7=iakPBR1eOvoeB8rL8Q47zg@mail.gmail.com
2026-09-04 07:50:46 +09:00
Michael Paquier
6fe9b62914 Revert "Remove fake FunctionCallInfos from the stats .."
This reverts commit cc9a8eb112, after more discussion with Etsuro
Fujita.  We are still not sure about the interface that should be used
for the portion related to the statistics import, and what should be
exposed for FDW code that may want to rely on these two functions:
- import_attribute_statistics()
- import_relation_statistics()

Discussion: https://postgr.es/m/CAPmGK15HUuNvEZk4b+K_x57+sg31B9LDwB7DBgVNaCpLnafhPA@mail.gmail.com
2026-09-03 17:24:52 +09:00
Alexander Korotkov
0fb258d1f2 postgres_fdw: Fix "may be used uninitialized" warning in foreign_join_ok()
Commit 0ee83dd4a9 detected the mixed foreign x function-RTE cases in one
if/else chain that only set a pair of bool flags, then acted on those flags in
a second chain.  fpinfo_o and fpinfo_i are each assigned in one chain and read
in the other, so proving them initialized requires correlating the flags with
the assignments.  gcc 13 with -Og does not manage that and reports fpinfo_i as
possibly uninitialized; clang's -Wconditional-uninitialized likewise reports
both variables.

The flags served no purpose beyond deferring the work, so merge the two chains
and read both fdw_private pointers up front, unconditionally.  A function rel
never has an fdw_private of its own, so the pointer is simply NULL until the
stub replaces it, and each branch now assigns and uses the two variables in one
place.

Reported-by: Karina Litskevich <litskevichkarina@gmail.com>
Reported-by: Marina Polyakova <m.polyakova@postgrespro.ru>
Reviewed-by: Marina Polyakova <m.polyakova@postgrespro.ru>
Discussion: https://postgr.es/m/CACiT8iamoL-%3D792e6JK2uCVvwDhfCg7DXHhvqN0P33jhGg2-8A%40mail.gmail.com
2026-09-02 15:46:47 +03:00
Michael Paquier
282111b45c Apply some query jumbling to WAIT FOR LSN
The query is now stored as normalized in pg_stat_statements, with its
LSN position ignored in the jumbling, resulting in:
WAIT FOR LSN $1;

The option values in the WITH clause are left untouched.

Reported-by: Peter Eisentraut <peter@eisentraut.org>
Author: Sirisha Chamarthi <sirichamarthi22@gmail.com>
Reviewed-by: Sami Imseih <samimseih.pg@gmail.com>
Reviewed-by: Rithvika Devisetti <devisettirithvika@gmail.com>
Discussion: https://postgr.es/m/1f04f78c-2cfa-47a0-997f-f02572cd10eb@eisentraut.org
Backpatch-through: 19
2026-09-02 14:14:19 +09:00
Michael Paquier
cc9a8eb112 Remove fake FunctionCallInfos from the stats restore and import code
The statistics import and restore paths built fake FunctionCallInfos
with LOCAL_FCINFO() and InitFunctionCallInfoData(), never calling
anything through them.  The only data relevantly used was the values
carried around as NullableDatum arrays, read back with PG_GETARG_*()
macros.

import_relation_statistics() and import_attribute_statistics() were
passing a set of NullablePointer pointers, leading to more round-trip
manipulations with the fake FunctionCallInfos.  These are reworked so as
the values pushed to pg_class (for relation stats) and pg_statistic (for
attribute stats) are passed around in dedicated structures with all the
values assigned based on positional indexes (import code cares about
less values than the restore code), simplifying their signatures and
reducing the number of code lines required to pass the data around.

The stats_check_*() functions now take the values and the attribute
names rather than a StatsArgInfo with positional indexes, as this code
is shared between the stats restore and import.  This removes the
dependency between the StatsArgInfo bits and the import code.
StatsArgInfo is used only for the restore code, for argument mapping.

No behavioral change should be introduced in this commit; this is
(should be) pure refactoring.

Reported-by: Robert Haas <robertmhaas@gmail.com>
Author: Corey Huinker <corey.huinker@gmail.com>
Author: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CADkLM=eo7MtuCE=YjovW+=ASw1=q39qQ3qarrsw+EKfU901ztA@mail.gmail.com
2026-09-02 13:17:39 +09:00
Peter Eisentraut
a62fa61611 pgcrypto: remove unused BF_ASM macro
This has never been defined to anything but 0, and the _BF_body_r
function it would call has never existed.

Author: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Discussion: https://www.postgresql.org/message-id/flat/87ldew2yqu.fsf%40wibble.ilmari.org
2026-09-01 13:50:51 +02:00
Peter Eisentraut
8534b0b4c7 Replace px_memset() with explicit_bzero()
The former was trying to do the same as the latter, but the latter has
more robust and portable implementations, and it's the standard across
the tree, so replace and remove px_memset().

Co-authored-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/a035c67f-4aa8-42e0-bb24-7b5abe927af4%40eisentraut.org
Discussion: https://www.postgresql.org/message-id/flat/87ldew2yqu.fsf%40wibble.ilmari.org
2026-09-01 13:43:46 +02:00
Peter Eisentraut
2a2dab67dc Fix memset invocation
It was setting sha_buf_tmp but sizing it by sizeof sha_buf.  These
happen to be the same size, so it's not an actual problem, but for
correctness make the sizeof match.

Reported-by: Sehrope Sarkuni <sehrope@jackdb.com>
Discussion: https://www.postgresql.org/message-id/flat/a035c67f-4aa8-42e0-bb24-7b5abe927af4%40eisentraut.org
2026-09-01 12:05:01 +02:00
Robert Haas
8c9c2e5c09 Fix empty FOREIGN_JOIN sublist validation
FOREIGN_JOIN target sublists must contain at least two relation
identifiers.  However, the parser checked only for sublists with
exactly one identifier, so FOREIGN_JOIN(()) was accepted.

Reject sublists with fewer than two relation identifiers, and add
regression coverage.

Author: Chao Li <lic@highgo.com>
Discussion: http://postgr.es/m/BEDC04E0-6732-4310-95BA-6EC34BC1442C@gmail.com
2026-08-27 14:14:15 -04:00
Etsuro Fujita
5c52858ecd Further cleanup related to statistics import support in postgres_fdw.
* Reorder the conditions in an if-else block for efficiency.
* Reorder struct definitions for readability.
* Reorder arguments for some functions for consistency.
* Move variables to the required scope.
* Rename a variable to match an input argument.
* Add/Tweak some comments/docs for clarity.

Author: Etsuro Fujita <etsuro.fujita@gmail.com>
Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Discussion: https://postgr.es/m/CAPmGK14otpa7XZyBO5GxDABUK9OPWFLsAwoQP3ugNdXq%3DK4J1g%40mail.gmail.com
Backpatch-through: 19
2026-08-25 17:50:00 +09:00
Daniel Gustafsson
cbc1e24d1b pgcrypto: Consistent spelling of built-in
Consistently use "built-in" instead of "built in" and "builtin".

Author: Erik Rijkers <er@xs4all.nl>
Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de>
Discussion: https://postgr.es/m/b6d69f32-253c-43ee-290e-f5f4c051a358@xs4all.nl
2026-08-25 10:41:10 +02:00
Peter Eisentraut
5767fece95 Change InputFunctionCall* to take a const char *str
It's reasonable to specify that the input string passed to these
functions isn't modified.

In each case, the input string is passed down to CStringGetDatum(),
which already takes a const char *, so this change just pushes that
API specification one level up.

A couple of callers benefit from this by no longer having to cast away
a const qualifier.

A few more functions that call input functions internally are changed
so that they can now offer a const qualified input string to their
callers.

Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi>
Discussion: https://www.postgresql.org/message-id/flat/459217ca-3840-4452-8cd1-8f9b47e8d479%40eisentraut.org
2026-08-25 10:26:50 +02:00