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

Commit 16efdb5

Browse files
author
Neil Conway
committed
Rename the newly-added commands for discarding session state.
RESET SESSION, RESET PLANS, and RESET TEMP are now DISCARD ALL, DISCARD PLANS, and DISCARD TEMP, respectively. This is to avoid confusion with the pre-existing RESET variants: the DISCARD commands are not actually similar to RESET. Patch from Marko Kreen, with some minor editorialization.
1 parent 5ea27a4 commit 16efdb5

File tree

19 files changed

+345
-133
lines changed

19 files changed

+345
-133
lines changed

doc/src/sgml/ref/allfiles.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.69 2007/01/23 05:07:16 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.70 2007/04/26 16:13:08 neilc Exp $
33
PostgreSQL documentation
44
Complete list of usable sgml source files in this directory.
55
-->
@@ -61,6 +61,7 @@ Complete list of usable sgml source files in this directory.
6161
<!entity deallocate system "deallocate.sgml">
6262
<!entity declare system "declare.sgml">
6363
<!entity delete system "delete.sgml">
64+
<!entity discard system "discard.sgml">
6465
<!entity dropAggregate system "drop_aggregate.sgml">
6566
<!entity dropCast system "drop_cast.sgml">
6667
<!entity dropConversion system "drop_conversion.sgml">

doc/src/sgml/ref/discard.sgml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<!--
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/discard.sgml,v 1.1 2007/04/26 16:13:09 neilc Exp $
3+
PostgreSQL documentation
4+
-->
5+
6+
<refentry id="SQL-DISCARD">
7+
<refmeta>
8+
<refentrytitle id="SQL-DISCARD-TITLE">DISCARD</refentrytitle>
9+
<refmiscinfo>SQL - Language Statements</refmiscinfo>
10+
</refmeta>
11+
12+
<refnamediv>
13+
<refname>DISCARD</refname>
14+
<refpurpose>Discard internal server state</refpurpose>
15+
</refnamediv>
16+
17+
<indexterm zone="sql-discard">
18+
<primary>DISCARD</primary>
19+
</indexterm>
20+
21+
<refsynopsisdiv>
22+
<synopsis>
23+
DISCARD { ALL | PLANS | TEMPORARY | TEMP }
24+
</synopsis>
25+
</refsynopsisdiv>
26+
27+
<refsect1>
28+
<title>Description</title>
29+
30+
<para>
31+
<command>DISCARD</> releases internal resources associated with a
32+
database session. These resources are normally released at the end
33+
of the session.
34+
</para>
35+
36+
<para>
37+
<command>DISCARD TEMP</> drops all temporary tables created in the
38+
current session. <command>DISCARD PLANS</> releases all internally
39+
cached query plans. <command>DISCARD ALL</> resets a session to
40+
its original state, discarding temporary resources and resetting
41+
session-local configuration changes.
42+
</para>
43+
</refsect1>
44+
45+
<refsect1>
46+
<title>Parameters</title>
47+
48+
<variablelist>
49+
50+
<varlistentry>
51+
<term><literal>TEMPORARY</literal> or <literal>TEMP</literal></term>
52+
<listitem>
53+
<para>
54+
Drops all temporary tables created in the current session.
55+
</para>
56+
</listitem>
57+
</varlistentry>
58+
59+
<varlistentry>
60+
<term><literal>PLANS</literal></term>
61+
<listitem>
62+
<para>
63+
Releases all cached query plans.
64+
</para>
65+
</listitem>
66+
</varlistentry>
67+
68+
<varlistentry>
69+
<term><literal>ALL</literal></term>
70+
<listitem>
71+
<para>
72+
Releases all temporary resources associated with the current
73+
session and resets the session to its initial state. This has
74+
the same effect as executing the following sequence of
75+
statements:
76+
<programlisting>
77+
SET SESSION AUTHORIZATION DEFAULT;
78+
RESET ALL;
79+
DEALLOCATE ALL;
80+
CLOSE ALL;
81+
UNLISTEN *;
82+
DISCARD PLANS;
83+
DISCARD TEMP;
84+
</programlisting>
85+
</para>
86+
</listitem>
87+
</varlistentry>
88+
89+
</variablelist>
90+
</refsect1>
91+
92+
<refsect1>
93+
<title>Notes</title>
94+
95+
<para>
96+
<command>DISCARD ALL</> cannot be executed inside a transaction block.
97+
</para>
98+
</refsect1>
99+
100+
<refsect1>
101+
<title>Compatibility</title>
102+
103+
<para>
104+
<command>DISCARD</command> is a <productname>PostgreSQL</productname> extension.
105+
</para>
106+
</refsect1>
107+
</refentry>

doc/src/sgml/ref/reset.sgml

Lines changed: 1 addition & 58 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.34 2007/04/12 22:34:45 neilc Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/reset.sgml,v 1.35 2007/04/26 16:13:09 neilc Exp $
33
PostgreSQL documentation
44
-->
55

@@ -22,7 +22,6 @@ PostgreSQL documentation
2222
<synopsis>
2323
RESET <replaceable class="PARAMETER">configuration_parameter</replaceable>
2424
RESET ALL
25-
RESET { PLANS | SESSION | TEMP | TEMPORARY }
2625
</synopsis>
2726
</refsynopsisdiv>
2827

@@ -53,15 +52,6 @@ SET <replaceable class="parameter">configuration_parameter</replaceable> TO DEFA
5352
See the <command>SET</> reference page for details on the
5453
transaction behavior of <command>RESET</>.
5554
</para>
56-
57-
<para>
58-
<command>RESET</> can also be used to release internal resources
59-
that are usually released at the end of session. <command>RESET
60-
TEMP</> drops all temporary tables created in the current session.
61-
<command>RESET PLANS</> releases all internally cached plans.
62-
<command>RESET SESSION</> releases all externally visible temporary
63-
resources associated with the current session.
64-
</para>
6555
</refsect1>
6656

6757
<refsect1>
@@ -86,56 +76,9 @@ SET <replaceable class="parameter">configuration_parameter</replaceable> TO DEFA
8676
</para>
8777
</listitem>
8878
</varlistentry>
89-
90-
<varlistentry>
91-
<term><literal>TEMP, TEMPORARY</literal></term>
92-
<listitem>
93-
<para>
94-
Drops all temporary tables created in the current session.
95-
</para>
96-
</listitem>
97-
</varlistentry>
98-
99-
<varlistentry>
100-
<term><literal>PLANS</literal></term>
101-
<listitem>
102-
<para>
103-
Releases all cached query plans.
104-
</para>
105-
</listitem>
106-
</varlistentry>
107-
108-
<varlistentry>
109-
<term><literal>SESSION</literal></term>
110-
<listitem>
111-
<para>
112-
Releases all temporary resources associated with the current
113-
session. This has the same effect as executing the following
114-
command sequence:
115-
<programlisting>
116-
SET SESSION AUTHORIZATION DEFAULT;
117-
RESET ALL;
118-
DEALLOCATE ALL;
119-
CLOSE ALL;
120-
UNLISTEN *;
121-
RESET PLANS;
122-
RESET TEMP;
123-
</programlisting>
124-
</para>
125-
</listitem>
126-
</varlistentry>
127-
12879
</variablelist>
12980
</refsect1>
13081

131-
<refsect1>
132-
<title>Notes</title>
133-
134-
<para>
135-
<command>RESET SESSION</> cannot be executed inside a transaction block.
136-
</para>
137-
</refsect1>
138-
13982
<refsect1>
14083
<title>Examples</title>
14184

doc/src/sgml/reference.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/reference.sgml,v 1.62 2007/01/31 20:56:18 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/reference.sgml,v 1.63 2007/04/26 16:13:08 neilc Exp $ -->
22

33
<part id="reference">
44
<title>Reference</title>
@@ -89,6 +89,7 @@
8989
&deallocate;
9090
&declare;
9191
&delete;
92+
&discard;
9293
&dropAggregate;
9394
&dropCast;
9495
&dropConversion;

src/backend/commands/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Makefile for backend/commands
55
#
66
# IDENTIFICATION
7-
# $PostgreSQL: pgsql/src/backend/commands/Makefile,v 1.35 2007/01/20 17:16:11 petere Exp $
7+
# $PostgreSQL: pgsql/src/backend/commands/Makefile,v 1.36 2007/04/26 16:13:09 neilc Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -14,7 +14,7 @@ include $(top_builddir)/src/Makefile.global
1414

1515
OBJS = aggregatecmds.o alter.o analyze.o async.o cluster.o comment.o \
1616
conversioncmds.o copy.o \
17-
dbcommands.o define.o explain.o functioncmds.o \
17+
dbcommands.o define.o discard.o explain.o functioncmds.o \
1818
indexcmds.o lockcmds.o operatorcmds.o opclasscmds.o \
1919
portalcmds.o prepare.o proclang.o \
2020
schemacmds.o sequence.o tablecmds.o tablespace.o trigger.o \

src/backend/commands/discard.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* discard.c
4+
* The implementation of the DISCARD command
5+
*
6+
* Copyright (c) 1996-2007, PostgreSQL Global Development Group
7+
*
8+
*
9+
* IDENTIFICATION
10+
* $PostgreSQL: pgsql/src/backend/commands/discard.c,v 1.1 2007/04/26 16:13:10 neilc Exp $
11+
*
12+
*-------------------------------------------------------------------------
13+
*/
14+
#include "postgres.h"
15+
16+
#include "access/xact.h"
17+
#include "catalog/namespace.h"
18+
#include "commands/async.h"
19+
#include "commands/discard.h"
20+
#include "commands/prepare.h"
21+
#include "commands/variable.h"
22+
#include "utils/plancache.h"
23+
#include "utils/portal.h"
24+
25+
static void DiscardAll(bool isTopLevel);
26+
27+
/*
28+
* DISCARD { ALL | TEMP | PLANS }
29+
*/
30+
void
31+
DiscardCommand(DiscardStmt *stmt, bool isTopLevel)
32+
{
33+
switch (stmt->target)
34+
{
35+
case DISCARD_ALL:
36+
DiscardAll(isTopLevel);
37+
break;
38+
39+
case DISCARD_PLANS:
40+
ResetPlanCache();
41+
break;
42+
43+
case DISCARD_TEMP:
44+
ResetTempTableNamespace();
45+
break;
46+
47+
default:
48+
elog(ERROR, "unrecognized DISCARD target: %d", stmt->target);
49+
}
50+
}
51+
52+
static void
53+
DiscardAll(bool isTopLevel)
54+
{
55+
/*
56+
* Disallow DISCARD ALL in a transaction block. This is arguably
57+
* inconsistent (we don't make a similar check in the command
58+
* sequence that DISCARD ALL is equivalent to), but the idea is
59+
* to catch mistakes: DISCARD ALL inside a transaction block
60+
* would leave the transaction still uncommitted.
61+
*/
62+
PreventTransactionChain(isTopLevel, "DISCARD ALL");
63+
64+
SetPGVariable("session_authorization", NIL, false);
65+
ResetAllOptions();
66+
DropAllPreparedStatements();
67+
PortalHashTableDeleteAll();
68+
Async_UnlistenAll();
69+
ResetPlanCache();
70+
ResetTempTableNamespace();
71+
}

src/backend/nodes/copyfuncs.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.373 2007/04/02 03:49:38 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.374 2007/04/26 16:13:10 neilc Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -2589,6 +2589,16 @@ _copyVariableResetStmt(VariableResetStmt *from)
25892589
return newnode;
25902590
}
25912591

2592+
static DiscardStmt *
2593+
_copyDiscardStmt(DiscardStmt *from)
2594+
{
2595+
DiscardStmt *newnode = makeNode(DiscardStmt);
2596+
2597+
COPY_SCALAR_FIELD(target);
2598+
2599+
return newnode;
2600+
}
2601+
25922602
static CreateTableSpaceStmt *
25932603
_copyCreateTableSpaceStmt(CreateTableSpaceStmt *from)
25942604
{
@@ -3380,6 +3390,9 @@ copyObject(void *from)
33803390
case T_VariableResetStmt:
33813391
retval = _copyVariableResetStmt(from);
33823392
break;
3393+
case T_DiscardStmt:
3394+
retval = _copyDiscardStmt(from);
3395+
break;
33833396
case T_CreateTableSpaceStmt:
33843397
retval = _copyCreateTableSpaceStmt(from);
33853398
break;

src/backend/nodes/equalfuncs.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* Portions Copyright (c) 1994, Regents of the University of California
1919
*
2020
* IDENTIFICATION
21-
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.304 2007/04/02 03:49:38 tgl Exp $
21+
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.305 2007/04/26 16:13:11 neilc Exp $
2222
*
2323
*-------------------------------------------------------------------------
2424
*/
@@ -1376,6 +1376,14 @@ _equalVariableResetStmt(VariableResetStmt *a, VariableResetStmt *b)
13761376
return true;
13771377
}
13781378

1379+
static bool
1380+
_equalDiscardStmt(DiscardStmt *a, DiscardStmt *b)
1381+
{
1382+
COMPARE_SCALAR_FIELD(target);
1383+
1384+
return true;
1385+
}
1386+
13791387
static bool
13801388
_equalCreateTableSpaceStmt(CreateTableSpaceStmt *a, CreateTableSpaceStmt *b)
13811389
{
@@ -2313,6 +2321,9 @@ equal(void *a, void *b)
23132321
case T_VariableResetStmt:
23142322
retval = _equalVariableResetStmt(a, b);
23152323
break;
2324+
case T_DiscardStmt:
2325+
retval = _equalDiscardStmt(a, b);
2326+
break;
23162327
case T_CreateTableSpaceStmt:
23172328
retval = _equalCreateTableSpaceStmt(a, b);
23182329
break;

0 commit comments

Comments
 (0)