Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 82a4798

Browse files
committed
Arrange for SET LOCAL's effects to persist until the end of the current top
transaction, unless rolled back or overridden by a SET clause for the same variable attached to a surrounding function call. Per discussion, these seem the best semantics. Note that this is an INCOMPATIBLE CHANGE: in 8.0 through 8.2, SET LOCAL's effects disappeared at subtransaction commit (leading to behavior that made little sense at the SQL level). I took advantage of the opportunity to rewrite and simplify the GUC variable save/restore logic a little bit. The old idea of a "tentative" value is gone; it was a hangover from before we had a stack. Also, we no longer need a stack entry for every nesting level, but only for those in which a variable's value actually changed.
1 parent b366562 commit 82a4798

File tree

16 files changed

+798
-494
lines changed

16 files changed

+798
-494
lines changed

doc/src/sgml/ref/create_function.sgml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/create_function.sgml,v 1.77 2007/09/03 18:46:29 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/create_function.sgml,v 1.78 2007/09/11 00:06:41 tgl Exp $
33
-->
44

55
<refentry id="SQL-CREATEFUNCTION">
@@ -475,11 +475,11 @@ CREATE FUNCTION foo(int, out text) ...
475475
</para>
476476

477477
<para>
478-
If any <literal>SET</> clauses are attached to a function, then
478+
If a <literal>SET</> clause is attached to a function, then
479479
the effects of a <command>SET LOCAL</> command executed inside the
480-
function are restricted to the function: the configuration parameter's
481-
value is restored at function exit. This is true even for parameters
482-
not mentioned in the <literal>SET</> clause(s). However, an ordinary
480+
function for the same variable are restricted to the function: the
481+
configuration parameter's prior value is still restored at function exit.
482+
However, an ordinary
483483
<command>SET</> command (without <literal>LOCAL</>) overrides the
484484
<literal>SET</> clause, much as it would do for a previous <command>SET
485485
LOCAL</> command: the effects of such a command will persist after

doc/src/sgml/ref/prepare_transaction.sgml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/prepare_transaction.sgml,v 1.5 2006/09/16 00:30:19 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/prepare_transaction.sgml,v 1.6 2007/09/11 00:06:41 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -94,7 +94,8 @@ PREPARE TRANSACTION <replaceable class="PARAMETER">transaction_id</replaceable>
9494
</para>
9595

9696
<para>
97-
If the transaction modified any run-time parameters with <command>SET</>,
97+
If the transaction modified any run-time parameters with <command>SET</>
98+
(without the <literal>LOCAL</> option),
9899
those effects persist after <command>PREPARE TRANSACTION</>, and will not
99100
be affected by any later <command>COMMIT PREPARED</command> or
100101
<command>ROLLBACK PREPARED</command>. Thus, in this one respect

doc/src/sgml/ref/reset.sgml

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/reset.sgml,v 1.35 2007/04/26 16:13:09 neilc Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/reset.sgml,v 1.36 2007/09/11 00:06:41 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -44,13 +44,16 @@ SET <replaceable class="parameter">configuration_parameter</replaceable> TO DEFA
4444
have had, if no <command>SET</> had ever been issued for it in the
4545
current session. The actual source of this value might be a
4646
compiled-in default, the configuration file, command-line options,
47-
or per-database or per-user default settings. See <xref
48-
linkend="runtime-config"> for details.
47+
or per-database or per-user default settings. This is subtly different
48+
from defining it as <quote>the value that the parameter had at session
49+
start</>, because if the value came from the configuration file, it
50+
will be reset to whatever is specified by the configuration file now.
51+
See <xref linkend="runtime-config"> for details.
4952
</para>
5053

5154
<para>
52-
See the <command>SET</> reference page for details on the
53-
transaction behavior of <command>RESET</>.
55+
The transactional behavior of <command>RESET</> is the same as
56+
<command>SET</>: its effects will be undone by transaction rollback.
5457
</para>
5558
</refsect1>
5659

@@ -62,8 +65,9 @@ SET <replaceable class="parameter">configuration_parameter</replaceable> TO DEFA
6265
<term><replaceable class="PARAMETER">configuration_parameter</replaceable></term>
6366
<listitem>
6467
<para>
65-
The name of a run-time parameter. See <xref linkend="sql-set"
66-
endterm="sql-set-title"> for a list.
68+
Name of a settable run-time parameter. Available parameters are
69+
documented in <xref linkend="runtime-config"> and on the
70+
<xref linkend="sql-set" endterm="sql-set-title"> reference page.
6771
</para>
6872
</listitem>
6973
</varlistentry>
@@ -83,9 +87,9 @@ SET <replaceable class="parameter">configuration_parameter</replaceable> TO DEFA
8387
<title>Examples</title>
8488

8589
<para>
86-
Set the <varname>geqo</> configuration variable to its default value:
90+
Set the <varname>timezone</> configuration variable to its default value:
8791
<screen>
88-
RESET geqo;
92+
RESET timezone;
8993
</screen>
9094
</para>
9195
</refsect1>
@@ -97,4 +101,13 @@ RESET geqo;
97101
<command>RESET</command> is a <productname>PostgreSQL</productname> extension.
98102
</para>
99103
</refsect1>
104+
105+
<refsect1>
106+
<title>See Also</title>
107+
108+
<simplelist type="inline">
109+
<member><xref linkend="SQL-SET" endterm="SQL-SET-title"></member>
110+
<member><xref linkend="SQL-SHOW" endterm="SQL-SHOW-title"></member>
111+
</simplelist>
112+
</refsect1>
100113
</refentry>

doc/src/sgml/ref/set.sgml

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/set.sgml,v 1.90 2006/09/22 16:20:00 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/set.sgml,v 1.91 2007/09/11 00:06:41 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -40,13 +40,10 @@ SET [ SESSION | LOCAL ] TIME ZONE { <replaceable class="PARAMETER">timezone</rep
4040
</para>
4141

4242
<para>
43-
If <command>SET</command> or <command>SET SESSION</command> is issued
44-
within a transaction that is later aborted, the effects of the
43+
If <command>SET</command> (or equivalently <command>SET SESSION</command>)
44+
is issued within a transaction that is later aborted, the effects of the
4545
<command>SET</command> command disappear when the transaction is rolled
46-
back. (This behavior represents a change from
47-
<productname>PostgreSQL</productname> versions prior to 7.3, where
48-
the effects of <command>SET</command> would not roll back after a later
49-
error.) Once the surrounding transaction is committed, the effects
46+
back. Once the surrounding transaction is committed, the effects
5047
will persist until the end of the session, unless overridden by another
5148
<command>SET</command>.
5249
</para>
@@ -59,6 +56,36 @@ SET [ SESSION | LOCAL ] TIME ZONE { <replaceable class="PARAMETER">timezone</rep
5956
seen until the end of the transaction, but afterwards (if the transaction
6057
is committed) the <command>SET</command> value will take effect.
6158
</para>
59+
60+
<para>
61+
The effects of <command>SET</command> or <command>SET LOCAL</command> are
62+
also canceled by rolling back to a savepoint that is earlier than the
63+
command.
64+
</para>
65+
66+
<para>
67+
If <command>SET LOCAL</command> is used within a function that has a
68+
<literal>SET</> option for the same variable (see
69+
<xref linkend="sql-createfunction" endterm="sql-createfunction-title">),
70+
the effects of the <command>SET LOCAL</command> command disappear at
71+
function exit; that is, the value in effect when the function was called is
72+
restored anyway. This allows <command>SET LOCAL</command> to be used for
73+
dynamic or repeated changes of a parameter within a function, while still
74+
having the convenience of using the <literal>SET</> option to save and
75+
restore the caller's value. However, a regular <command>SET</> command
76+
overrides any surrounding function's <literal>SET</> option; its effects
77+
will persist unless rolled back.
78+
</para>
79+
80+
<note>
81+
<para>
82+
In <productname>PostgreSQL</productname> versions 8.0 through 8.2,
83+
the effects of a <command>SET LOCAL</command> would be canceled by
84+
releasing an earlier savepoint, or by successful exit from a
85+
<application>PL/pgSQL</application> exception block. This behavior
86+
has been changed because it was deemed unintuitive.
87+
</para>
88+
</note>
6289
</refsect1>
6390

6491
<refsect1>
@@ -106,8 +133,11 @@ SET [ SESSION | LOCAL ] TIME ZONE { <replaceable class="PARAMETER">timezone</rep
106133
<para>
107134
New value of parameter. Values can be specified as string
108135
constants, identifiers, numbers, or comma-separated lists of
109-
these. <literal>DEFAULT</literal> can be used to specify
110-
resetting the parameter to its default value.
136+
these, as appropriate for the particular parameter.
137+
<literal>DEFAULT</literal> can be written to specify
138+
resetting the parameter to its default value (that is, whatever
139+
value it would have had if no <command>SET</> had been executed
140+
in the current session).
111141
</para>
112142
</listitem>
113143
</varlistentry>
@@ -200,7 +230,9 @@ SELECT setseed(<replaceable>value</replaceable>);
200230
<term><literal>DEFAULT</literal></term>
201231
<listitem>
202232
<para>
203-
Set the time zone to your local time zone (the one that
233+
Set the time zone to your local time zone (that is, the
234+
server's default value of <varname>timezone</>; if this
235+
has not been explicitly set anywhere, it will be the zone that
204236
the server's operating system defaults to).
205237
</para>
206238
</listitem>
@@ -221,7 +253,10 @@ SELECT setseed(<replaceable>value</replaceable>);
221253

222254
<para>
223255
The function <function>set_config</function> provides equivalent
224-
functionality. See <xref linkend="functions-admin">.
256+
functionality; see <xref linkend="functions-admin">.
257+
Also, it is possible to UPDATE the
258+
<link linkend="view-pg-settings"><structname>pg_settings</structname></link>
259+
system view to perform the equivalent of <command>SET</>.
225260
</para>
226261
</refsect1>
227262

doc/src/sgml/ref/show.sgml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/show.sgml,v 1.42 2006/09/16 00:30:20 momjian Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/show.sgml,v 1.43 2007/09/11 00:06:41 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -36,7 +36,7 @@ SHOW ALL
3636
the <envar>PGOPTIONS</envar> environmental variable (when using
3737
<application>libpq</> or a <application>libpq</>-based
3838
application), or through command-line flags when starting the
39-
<command>postgres</command>. See <xref
39+
<command>postgres</command> server. See <xref
4040
linkend="runtime-config"> for details.
4141
</para>
4242
</refsect1>
@@ -130,7 +130,11 @@ SHOW ALL
130130

131131
<para>
132132
The function <function>current_setting</function> produces
133-
equivalent output. See <xref linkend="functions-admin">.
133+
equivalent output; see <xref linkend="functions-admin">.
134+
Also, the
135+
<link linkend="view-pg-settings"><structname>pg_settings</structname></link>
136+
system view produces the same information.
137+
134138
</para>
135139
</refsect1>
136140

src/backend/utils/adt/ri_triggers.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
1717
*
18-
* $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.96 2007/08/15 19:15:46 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.97 2007/09/11 00:06:42 tgl Exp $
1919
*
2020
* ----------
2121
*/
@@ -2749,7 +2749,7 @@ RI_Initial_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel)
27492749
snprintf(workmembuf, sizeof(workmembuf), "%d", maintenance_work_mem);
27502750
(void) set_config_option("work_mem", workmembuf,
27512751
PGC_USERSET, PGC_S_SESSION,
2752-
true, true);
2752+
GUC_ACTION_LOCAL, true);
27532753

27542754
if (SPI_connect() != SPI_OK_CONNECT)
27552755
elog(ERROR, "SPI_connect failed");
@@ -2832,13 +2832,12 @@ RI_Initial_Check(Trigger *trigger, Relation fk_rel, Relation pk_rel)
28322832

28332833
/*
28342834
* Restore work_mem for the remainder of the current transaction. This is
2835-
* another SET LOCAL, so it won't affect the session value, nor any
2836-
* tentative value if there is one.
2835+
* another SET LOCAL, so it won't affect the session value.
28372836
*/
28382837
snprintf(workmembuf, sizeof(workmembuf), "%d", old_work_mem);
28392838
(void) set_config_option("work_mem", workmembuf,
28402839
PGC_USERSET, PGC_S_SESSION,
2841-
true, true);
2840+
GUC_ACTION_LOCAL, true);
28422841

28432842
return true;
28442843
}

src/backend/utils/fmgr/fmgr.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/fmgr/fmgr.c,v 1.109 2007/09/03 00:39:18 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/fmgr/fmgr.c,v 1.110 2007/09/11 00:06:42 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -925,20 +925,18 @@ fmgr_security_definer(PG_FUNCTION_ARGS)
925925

926926
if (fcache->proconfig)
927927
{
928-
/* The options are processed as if by SET LOCAL var = val */
929928
ProcessGUCArray(fcache->proconfig,
930929
(superuser() ? PGC_SUSET : PGC_USERSET),
931930
PGC_S_SESSION,
932-
true);
931+
GUC_ACTION_SAVE);
933932
}
934933

935934
result = FunctionCallInvoke(fcinfo);
936935
}
937936
PG_CATCH();
938937
{
939938
fcinfo->flinfo = save_flinfo;
940-
if (fcache->proconfig)
941-
AtEOXact_GUC(false, save_nestlevel);
939+
/* We don't need to restore GUC settings, outer xact abort will */
942940
if (OidIsValid(fcache->userid))
943941
SetUserId(save_userid);
944942
PG_RE_THROW();

src/backend/utils/init/miscinit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.163 2007/09/03 00:39:18 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.164 2007/09/11 00:06:42 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -453,7 +453,7 @@ InitializeSessionUserId(const char *rolename)
453453
* right to insert an option into pg_authid was checked when it was
454454
* inserted.
455455
*/
456-
ProcessGUCArray(a, PGC_SUSET, PGC_S_USER, false);
456+
ProcessGUCArray(a, PGC_SUSET, PGC_S_USER, GUC_ACTION_SET);
457457
}
458458

459459
ReleaseSysCache(roleTup);

src/backend/utils/init/postinit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.177 2007/09/03 00:39:18 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/init/postinit.c,v 1.178 2007/09/11 00:06:42 tgl Exp $
1212
*
1313
*
1414
*-------------------------------------------------------------------------
@@ -255,7 +255,7 @@ CheckMyDatabase(const char *name, bool am_superuser)
255255
* right to insert an option into pg_database was checked when it
256256
* was inserted.
257257
*/
258-
ProcessGUCArray(a, PGC_SUSET, PGC_S_DATABASE, false);
258+
ProcessGUCArray(a, PGC_SUSET, PGC_S_DATABASE, GUC_ACTION_SET);
259259
}
260260
}
261261

0 commit comments

Comments
 (0)