Skip to content

Commit d6a9346

Browse files
authored
Merge branch 'postgres:master' into main
2 parents 9c571cf + bea97cd commit d6a9346

File tree

18 files changed

+148
-41
lines changed

18 files changed

+148
-41
lines changed

doc/src/sgml/custom-rmgr.sgml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<!-- doc/src/sgml/custom-rmgr.sgml -->
22

3-
<chapter id="custom-rmgr">
3+
<sect1 id="custom-rmgr">
44
<title>Custom WAL Resource Managers</title>
55

66
<para>
7-
This chapter explains the interface between the core
7+
This section explains the interface between the core
88
<productname>PostgreSQL</productname> system and custom WAL resource
99
managers, which enable extensions to integrate directly with the <link
1010
linkend="wal"><acronym>WAL</acronym></link>.
@@ -13,10 +13,7 @@
1313
An extension, especially a <link linkend="tableam">Table Access
1414
Method</link> or <link linkend="indexam">Index Access Method</link>, may
1515
need to use WAL for recovery, replication, and/or <link
16-
linkend="logicaldecoding">Logical Decoding</link>. Custom resource managers
17-
are a more flexible alternative to <link linkend="generic-wal">Generic
18-
WAL</link> (which does not support logical decoding), but more complex for
19-
an extension to implement.
16+
linkend="logicaldecoding">Logical Decoding</link>.
2017
</para>
2118
<para>
2219
To create a new custom WAL resource manager, first define an
@@ -102,4 +99,4 @@ extern void RegisterCustomRmgr(RmgrId rmid, const RmgrData *rmgr);
10299
the custom WAL records, which may prevent the server from starting.
103100
</para>
104101
</note>
105-
</chapter>
102+
</sect1>

doc/src/sgml/filelist.sgml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
<!ENTITY storage SYSTEM "storage.sgml">
108108
<!ENTITY transaction SYSTEM "xact.sgml">
109109
<!ENTITY tablesample-method SYSTEM "tablesample-method.sgml">
110+
<!ENTITY wal-for-extensions SYSTEM "wal-for-extensions.sgml">
110111
<!ENTITY generic-wal SYSTEM "generic-wal.sgml">
111112
<!ENTITY custom-rmgr SYSTEM "custom-rmgr.sgml">
112113
<!ENTITY backup-manifest SYSTEM "backup-manifest.sgml">

doc/src/sgml/generic-wal.sgml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
11
<!-- doc/src/sgml/generic-wal.sgml -->
22

3-
<chapter id="generic-wal">
3+
<sect1 id="generic-wal">
44
<title>Generic WAL Records</title>
55

66
<para>
77
Although all built-in WAL-logged modules have their own types of WAL
88
records, there is also a generic WAL record type, which describes changes
9-
to pages in a generic way. This is useful for extensions that provide
10-
custom access methods.
11-
</para>
12-
13-
<para>
14-
In comparison with <link linkend="custom-rmgr">Custom WAL Resource
15-
Managers</link>, Generic WAL is simpler for an extension to implement and
16-
does not require the extension library to be loaded in order to apply the
17-
records.
9+
to pages in a generic way.
1810
</para>
1911

2012
<note>
@@ -171,4 +163,4 @@
171163
</listitem>
172164
</itemizedlist>
173165
</para>
174-
</chapter>
166+
</sect1>

doc/src/sgml/postgres.sgml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,7 @@ break is not needed in a wider output rendering.
256256
&geqo;
257257
&tableam;
258258
&indexam;
259-
&generic-wal;
260-
&custom-rmgr;
259+
&wal-for-extensions;
261260
&indextypes;
262261
&storage;
263262
&transaction;

doc/src/sgml/ref/set_role.sgml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ RESET ROLE
3737
written as either an identifier or a string literal.
3838
After <command>SET ROLE</command>, permissions checking for SQL commands
3939
is carried out as though the named role were the one that had logged
40-
in originally.
40+
in originally. Note that <command>SET ROLE</command> and
41+
<command>SET SESSION AUTHORIZATION</command> are exceptions; permissions
42+
checks for those continue to use the current session user and the initial
43+
session user (the <firstterm>authenticated user</firstterm>), respectively.
4144
</para>
4245

4346
<para>
@@ -88,11 +91,6 @@ RESET ROLE
8891
exercised either with or without <literal>SET ROLE</literal>.
8992
</para>
9093

91-
<para>
92-
Note that when a superuser chooses to <command>SET ROLE</command> to a
93-
non-superuser role, they lose their superuser privileges.
94-
</para>
95-
9694
<para>
9795
<command>SET ROLE</command> has effects comparable to
9896
<link linkend="sql-set-session-authorization"><command>SET SESSION AUTHORIZATION</command></link>, but the privilege
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!-- doc/src/sgml/wal-for-extensions.sgml -->
2+
3+
<chapter id="wal-for-extensions">
4+
<title>Write Ahead Logging for Extensions</title>
5+
6+
<para>
7+
Certain extensions, principally extensions that implement custom access
8+
methods, may need to perform write-ahead logging in order to ensure
9+
crash-safety. <productname>PostgreSQL</productname> provides two ways
10+
for extensions to achieve this goal.
11+
</para>
12+
13+
<para>
14+
First, extensions can choose to use <link linkend="generic-wal">generic
15+
WAL</link>, a special type of WAL record which describes changes to pages
16+
in a generic way. This method is simple to implement and does not require
17+
that an extension library be loaded in order to apply the records. However,
18+
generic WAL records will be ignored when performing logical decoding.
19+
</para>
20+
21+
<para>
22+
Second, extensions can choose to use a <link linkend="custom-rmgr">custom
23+
resource manager</link>. This method is more flexible, supports logical
24+
decoding, and can sometimes generate much smaller write-ahead log records
25+
than would be possible with generic WAL. However, it is more complex for an
26+
extension to implement.
27+
</para>
28+
29+
&generic-wal;
30+
&custom-rmgr;
31+
32+
</chapter>

src/backend/catalog/dependency.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2337,7 +2337,11 @@ process_function_rte_ref(RangeTblEntry *rte, AttrNumber attnum,
23372337
{
23382338
TupleDesc tupdesc;
23392339

2340-
tupdesc = get_expr_result_tupdesc(rtfunc->funcexpr, true);
2340+
/* If it has a coldeflist, it certainly returns RECORD */
2341+
if (rtfunc->funccolnames != NIL)
2342+
tupdesc = NULL; /* no need to work hard */
2343+
else
2344+
tupdesc = get_expr_result_tupdesc(rtfunc->funcexpr, true);
23412345
if (tupdesc && tupdesc->tdtypeid != RECORDOID)
23422346
{
23432347
/*

src/backend/optimizer/prep/prepjointree.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,6 +1854,10 @@ pull_up_constant_function(PlannerInfo *root, Node *jtnode,
18541854
if (rtf->funccolcount != 1)
18551855
return jtnode; /* definitely composite */
18561856

1857+
/* If it has a coldeflist, it certainly returns RECORD */
1858+
if (rtf->funccolnames != NIL)
1859+
return jtnode; /* must be a one-column RECORD type */
1860+
18571861
functypclass = get_expr_result_type(rtf->funcexpr,
18581862
&funcrettype,
18591863
&tupdesc);

src/backend/optimizer/util/clauses.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4431,12 +4431,11 @@ evaluate_function(Oid funcid, Oid result_type, int32 result_typmod,
44314431
* Can't simplify if it returns RECORD. The immediate problem is that it
44324432
* will be needing an expected tupdesc which we can't supply here.
44334433
*
4434-
* In the case where it has OUT parameters, it could get by without an
4435-
* expected tupdesc, but we still have issues: get_expr_result_type()
4436-
* doesn't know how to extract type info from a RECORD constant, and in
4437-
* the case of a NULL function result there doesn't seem to be any clean
4438-
* way to fix that. In view of the likelihood of there being still other
4439-
* gotchas, seems best to leave the function call unreduced.
4434+
* In the case where it has OUT parameters, we could build an expected
4435+
* tupdesc from those, but there may be other gotchas lurking. In
4436+
* particular, if the function were to return NULL, we would produce a
4437+
* null constant with no remaining indication of which concrete record
4438+
* type it is. For now, seems best to leave the function call unreduced.
44404439
*/
44414440
if (funcform->prorettype == RECORDOID)
44424441
return NULL;

src/backend/parser/parse_relation.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,12 +2738,17 @@ expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up,
27382738
{
27392739
RangeTblFunction *rtfunc = (RangeTblFunction *) lfirst(lc);
27402740
TypeFuncClass functypclass;
2741-
Oid funcrettype;
2742-
TupleDesc tupdesc;
2741+
Oid funcrettype = InvalidOid;
2742+
TupleDesc tupdesc = NULL;
2743+
2744+
/* If it has a coldeflist, it returns RECORD */
2745+
if (rtfunc->funccolnames != NIL)
2746+
functypclass = TYPEFUNC_RECORD;
2747+
else
2748+
functypclass = get_expr_result_type(rtfunc->funcexpr,
2749+
&funcrettype,
2750+
&tupdesc);
27432751

2744-
functypclass = get_expr_result_type(rtfunc->funcexpr,
2745-
&funcrettype,
2746-
&tupdesc);
27472752
if (functypclass == TYPEFUNC_COMPOSITE ||
27482753
functypclass == TYPEFUNC_COMPOSITE_DOMAIN)
27492754
{
@@ -3369,6 +3374,10 @@ get_rte_attribute_is_dropped(RangeTblEntry *rte, AttrNumber attnum)
33693374
{
33703375
TupleDesc tupdesc;
33713376

3377+
/* If it has a coldeflist, it returns RECORD */
3378+
if (rtfunc->funccolnames != NIL)
3379+
return false; /* can't have any dropped columns */
3380+
33723381
tupdesc = get_expr_result_tupdesc(rtfunc->funcexpr,
33733382
true);
33743383
if (tupdesc)

0 commit comments

Comments
 (0)