Skip to content

[pull] master from postgres:master #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
421 changes: 281 additions & 140 deletions contrib/xml2/xpath.c

Large diffs are not rendered by default.

26 changes: 15 additions & 11 deletions contrib/xml2/xslt_proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ xslt_process(PG_FUNCTION_ARGS)
volatile xsltSecurityPrefsPtr xslt_sec_prefs = NULL;
volatile xsltTransformContextPtr xslt_ctxt = NULL;
volatile int resstat = -1;
xmlChar *resstr = NULL;
volatile xmlChar *resstr = NULL;
int reslen = 0;

if (fcinfo->nargs == 3)
Expand Down Expand Up @@ -86,7 +86,7 @@ xslt_process(PG_FUNCTION_ARGS)
VARSIZE_ANY_EXHDR(doct), NULL, NULL,
XML_PARSE_NOENT);

if (doctree == NULL)
if (doctree == NULL || pg_xml_error_occurred(xmlerrcxt))
xml_ereport(xmlerrcxt, ERROR, ERRCODE_INVALID_XML_DOCUMENT,
"error parsing XML document");

Expand All @@ -95,14 +95,14 @@ xslt_process(PG_FUNCTION_ARGS)
VARSIZE_ANY_EXHDR(ssheet), NULL, NULL,
XML_PARSE_NOENT);

if (ssdoc == NULL)
if (ssdoc == NULL || pg_xml_error_occurred(xmlerrcxt))
xml_ereport(xmlerrcxt, ERROR, ERRCODE_INVALID_XML_DOCUMENT,
"error parsing stylesheet as XML document");

/* After this call we need not free ssdoc separately */
stylesheet = xsltParseStylesheetDoc(ssdoc);

if (stylesheet == NULL)
if (stylesheet == NULL || pg_xml_error_occurred(xmlerrcxt))
xml_ereport(xmlerrcxt, ERROR, ERRCODE_INVALID_ARGUMENT_FOR_XQUERY,
"failed to parse stylesheet");

Expand Down Expand Up @@ -137,11 +137,15 @@ xslt_process(PG_FUNCTION_ARGS)
restree = xsltApplyStylesheetUser(stylesheet, doctree, params,
NULL, NULL, xslt_ctxt);

if (restree == NULL)
if (restree == NULL || pg_xml_error_occurred(xmlerrcxt))
xml_ereport(xmlerrcxt, ERROR, ERRCODE_INVALID_ARGUMENT_FOR_XQUERY,
"failed to apply stylesheet");

resstat = xsltSaveResultToString(&resstr, &reslen, restree, stylesheet);
resstat = xsltSaveResultToString((xmlChar **) &resstr, &reslen,
restree, stylesheet);

if (resstat >= 0)
result = cstring_to_text_with_len((char *) resstr, reslen);
}
PG_CATCH();
{
Expand All @@ -155,6 +159,8 @@ xslt_process(PG_FUNCTION_ARGS)
xsltFreeStylesheet(stylesheet);
if (doctree != NULL)
xmlFreeDoc(doctree);
if (resstr != NULL)
xmlFree((xmlChar *) resstr);
xsltCleanupGlobals();

pg_xml_done(xmlerrcxt, true);
Expand All @@ -170,17 +176,15 @@ xslt_process(PG_FUNCTION_ARGS)
xmlFreeDoc(doctree);
xsltCleanupGlobals();

if (resstr)
xmlFree((xmlChar *) resstr);

pg_xml_done(xmlerrcxt, false);

/* XXX this is pretty dubious, really ought to throw error instead */
if (resstat < 0)
PG_RETURN_NULL();

result = cstring_to_text_with_len((char *) resstr, reslen);

if (resstr)
xmlFree(resstr);

PG_RETURN_TEXT_P(result);
#else /* !USE_LIBXSLT */

Expand Down
4 changes: 2 additions & 2 deletions doc/src/sgml/amcheck.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ SET client_min_messages = DEBUG1;
TOAST table.
</para>
<para>
This option is known to be slow. Also, if the toast table or its
index is corrupt, checking it against toast values could conceivably
This option is known to be slow. Also, if the TOAST table or its
index is corrupt, checking it against TOAST values could conceivably
crash the server, although in many cases this would just produce an
error.
</para>
Expand Down
2 changes: 1 addition & 1 deletion doc/src/sgml/bki.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ $ perl rewrite_dat_with_prokind.pl pg_proc.dat
</listitem>
<listitem>
<para>
Define indexes and toast tables.
Define indexes and TOAST tables.
</para>
</listitem>
<listitem>
Expand Down
2 changes: 1 addition & 1 deletion doc/src/sgml/catalogs.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -1951,7 +1951,7 @@ SCRAM-SHA-256$<replaceable>&lt;iteration count&gt;</replaceable>:<replaceable>&l
</para>
<para>
The OID of the data type that corresponds to this table's row type,
if any; zero for indexes, sequences, and toast tables, which have
if any; zero for indexes, sequences, and TOAST tables, which have
no <structname>pg_type</structname> entry
</para></entry>
</row>
Expand Down
8 changes: 2 additions & 6 deletions doc/src/sgml/installation.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -3847,17 +3847,13 @@ make: *** [postgres] Error 1
<para>
Both 32-bit and 64-bit builds are possible with the Microsoft Compiler suite.
32-bit PostgreSQL builds are possible with
<productname>Visual Studio 2015</productname> to
<productname>Visual Studio 2019</productname> to
<productname>Visual Studio 2022</productname>,
as well as standalone Windows SDK releases 10 and above.
64-bit PostgreSQL builds are supported with
<productname>Microsoft Windows SDK</productname> version 10 and above or
<productname>Visual Studio 2015</productname> and above.
<productname>Visual Studio 2019</productname> and above.
<!--
For 2015 requirements:
https://docs.microsoft.com/en-us/visualstudio/productinfo/vs2015-sysrequirements-vs
For 2017 requirements:
https://docs.microsoft.com/en-us/visualstudio/productinfo/vs2017-system-requirements-vs
For 2019 requirements:
https://docs.microsoft.com/en-us/visualstudio/releases/2019/system-requirements
For 2022 requirements:
Expand Down
2 changes: 1 addition & 1 deletion doc/src/sgml/logicaldecoding.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,7 @@ commit_prepared_cb(...); &lt;-- commit of the prepared transaction
currently used for decoded changes) is selected and streamed. However, in
some cases we still have to spill to disk even if streaming is enabled
because we exceed the memory threshold but still have not decoded the
complete tuple e.g., only decoded toast table insert but not the main table
complete tuple e.g., only decoded TOAST table insert but not the main table
insert.
</para>

Expand Down
2 changes: 1 addition & 1 deletion doc/src/sgml/ref/alter_table.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM

<para>
<literal>SHARE UPDATE EXCLUSIVE</literal> lock will be taken for
fillfactor, toast and autovacuum storage parameters, as well as the
fillfactor, TOAST and autovacuum storage parameters, as well as the
planner parameter <varname>parallel_workers</varname>.
</para>
</listitem>
Expand Down
12 changes: 6 additions & 6 deletions doc/src/sgml/ref/pg_amcheck.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ PostgreSQL documentation
</para>

<para>
Only ordinary and toast table relations, materialized views, sequences, and
Only ordinary and TOAST table relations, materialized views, sequences, and
btree indexes are currently supported. Other relation types are silently
skipped.
</para>
Expand Down Expand Up @@ -276,7 +276,7 @@ PostgreSQL documentation
<term><option>--no-dependent-toast</option></term>
<listitem>
<para>
By default, if a table is checked, its toast table, if any, will also
By default, if a table is checked, its TOAST table, if any, will also
be checked, even if it is not explicitly selected by an option
such as <literal>--table</literal> or <literal>--relation</literal>.
This option suppresses that behavior.
Expand Down Expand Up @@ -306,9 +306,9 @@ PostgreSQL documentation
<term><option>--exclude-toast-pointers</option></term>
<listitem>
<para>
By default, whenever a toast pointer is encountered in a table,
By default, whenever a TOAST pointer is encountered in a table,
a lookup is performed to ensure that it references apparently-valid
entries in the toast table. These checks can be quite slow, and this
entries in the TOAST table. These checks can be quite slow, and this
option can be used to skip them.
</para>
</listitem>
Expand Down Expand Up @@ -368,9 +368,9 @@ PostgreSQL documentation
End checking at the specified block number. An error will occur if the
table relation being checked has fewer than this number of blocks.
This option does not apply to indexes, and is probably only useful when
checking a single table relation. If both a regular table and a toast
checking a single table relation. If both a regular table and a TOAST
table are checked, this option will apply to both, but higher-numbered
toast blocks may still be accessed while validating toast pointers,
TOAST blocks may still be accessed while validating TOAST pointers,
unless that is suppressed using
<option>--exclude-toast-pointers</option>.
</para>
Expand Down
2 changes: 1 addition & 1 deletion doc/src/sgml/sepgsql.sgml
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ UPDATE t1 SET x = 2, y = func1(y) WHERE z = 100;
<para>
The default database privilege system allows database superusers to
modify system catalogs using DML commands, and reference or modify
toast tables. These operations are prohibited when
TOAST tables. These operations are prohibited when
<filename>sepgsql</filename> is enabled.
</para>
</sect3>
Expand Down
4 changes: 4 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ elif host_system == 'windows'
# define before including <time.h> for getting localtime_r() etc. on MinGW
cppflags += '-D_POSIX_C_SOURCE'
endif
if cc.get_id() == 'msvc'
# required for VA_ARGS_NARGS() in c.h; requires VS 2019
cppflags += '/Zc:preprocessor'
endif

export_file_format = 'win'
export_file_suffix = 'def'
Expand Down
4 changes: 2 additions & 2 deletions src/backend/executor/execIndexing.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ ExecCloseIndices(ResultRelInfo *resultRelInfo)
* executor is performing an UPDATE that could not use an
* optimization like heapam's HOT (in more general terms a
* call to table_tuple_update() took place and set
* 'update_indexes' to TUUI_All). Receiving this hint makes
* 'update_indexes' to TU_All). Receiving this hint makes
* us consider if we should pass down the 'indexUnchanged'
* hint in turn. That's something that we figure out for
* each index_insert() call iff 'update' is true.
Expand All @@ -290,7 +290,7 @@ ExecCloseIndices(ResultRelInfo *resultRelInfo)
* HOT has been applied and any updated columns are indexed
* only by summarizing indexes (or in more general terms a
* call to table_tuple_update() took place and set
* 'update_indexes' to TUUI_Summarizing). We can (and must)
* 'update_indexes' to TU_Summarizing). We can (and must)
* therefore only update the indexes that have
* 'amsummarizing' = true.
*
Expand Down
19 changes: 0 additions & 19 deletions src/include/c.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,25 +376,7 @@
* pretty trivial: VA_ARGS_NARGS_() returns its 64th argument, and we set up
* the call so that that is the appropriate one of the list of constants.
* This idea is due to Laurent Deniau.
*
* MSVC has an implementation of __VA_ARGS__ that doesn't conform to the
* standard unless you use the /Zc:preprocessor compiler flag, but that
* isn't available before Visual Studio 2019. For now, use a different
* definition that also works on older compilers.
*/
#ifdef _MSC_VER
#define EXPAND(args) args
#define VA_ARGS_NARGS(...) \
VA_ARGS_NARGS_ EXPAND((__VA_ARGS__, \
63,62,61,60, \
59,58,57,56,55,54,53,52,51,50, \
49,48,47,46,45,44,43,42,41,40, \
39,38,37,36,35,34,33,32,31,30, \
29,28,27,26,25,24,23,22,21,20, \
19,18,17,16,15,14,13,12,11,10, \
9, 8, 7, 6, 5, 4, 3, 2, 1, 0))
#else

#define VA_ARGS_NARGS(...) \
VA_ARGS_NARGS_(__VA_ARGS__, \
63,62,61,60, \
Expand All @@ -404,7 +386,6 @@
29,28,27,26,25,24,23,22,21,20, \
19,18,17,16,15,14,13,12,11,10, \
9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
#endif

#define VA_ARGS_NARGS_( \
_01,_02,_03,_04,_05,_06,_07,_08,_09,_10, \
Expand Down
2 changes: 1 addition & 1 deletion src/include/catalog/pg_publication.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ extern Publication *GetPublicationByName(const char *pubname, bool missing_ok);
extern List *GetRelationPublications(Oid relid);

/*---------
* Expected values for pub_partopt parameter of GetRelationPublications(),
* Expected values for pub_partopt parameter of GetPublicationRelations(),
* which allows callers to specify which partitions of partitioned tables
* mentioned in the publication they expect to see.
*
Expand Down
50 changes: 49 additions & 1 deletion src/port/pg_numa.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@
#include <numa.h>
#include <numaif.h>

/*
* numa_move_pages() chunk size, has to be <= 16 to work around a kernel bug
* in do_pages_stat() (chunked by DO_PAGES_STAT_CHUNK_NR). By using the same
* chunk size, we make it work even on unfixed kernels.
*
* 64-bit system are not affected by the bug, and so use much larger chunks.
*/
#if SIZEOF_SIZE_T == 4
#define NUMA_QUERY_CHUNK_SIZE 16
#else
#define NUMA_QUERY_CHUNK_SIZE 1024
#endif

/* libnuma requires initialization as per numa(3) on Linux */
int
pg_numa_init(void)
Expand All @@ -42,11 +55,46 @@ pg_numa_init(void)
* We use move_pages(2) syscall here - instead of get_mempolicy(2) - as the
* first one allows us to batch and query about many memory pages in one single
* giant system call that is way faster.
*
* We call numa_move_pages() for smaller chunks of the whole array. The first
* reason is to work around a kernel bug, but also to allow interrupting the
* query between the calls (for many pointers processing the whole array can
* take a lot of time).
*/
int
pg_numa_query_pages(int pid, unsigned long count, void **pages, int *status)
{
return numa_move_pages(pid, count, pages, NULL, status, 0);
unsigned long next = 0;
int ret = 0;

/*
* Chunk pointers passed to numa_move_pages to NUMA_QUERY_CHUNK_SIZE
* items, to work around a kernel bug in do_pages_stat().
*/
while (next < count)
{
unsigned long count_chunk = Min(count - next,
NUMA_QUERY_CHUNK_SIZE);

/*
* Bail out if any of the chunks errors out (ret<0). We ignore
* (ret>0) which is used to return number of nonmigrated pages,
* but we're not migrating any pages here.
*/
ret = numa_move_pages(pid, count_chunk, &pages[next], NULL, &status[next], 0);
if (ret < 0)
{
/* plain error, return as is */
return ret;
}

next += count_chunk;
}

/* should have consumed the input array exactly */
Assert(next == count);

return 0;
}

int
Expand Down