Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitebb5318

Browse files
committed
Add code to handle [ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP }]
for temp tables.Gavin Sherry
1 parentf2ef470 commitebb5318

File tree

13 files changed

+370
-24
lines changed

13 files changed

+370
-24
lines changed

‎doc/src/sgml/ref/create_table.sgml

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.56 2002/09/02 06:20:53 momjian Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/create_table.sgml,v 1.57 2002/11/09 23:56:38 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -21,7 +21,7 @@ CREATE [ [ LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PARAMETER">t
2121
| <replaceable>table_constraint</replaceable> } [, ... ]
2222
)
2323
[ INHERITS ( <replaceable>parent_table</replaceable> [, ... ] ) ]
24-
[ WITH OIDS | WITHOUT OIDS ]
24+
[ WITH OIDS | WITHOUT OIDS ] [ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
2525

2626
where <replaceable class="PARAMETER">column_constraint</replaceable> is:
2727

@@ -107,10 +107,11 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is:
107107
<para>
108108
If specified, the table is created as a temporary table.
109109
Temporary tables are automatically dropped at the end of a
110-
session. Existing permanent tables with the same name are not
111-
visible to the current session while the temporary table exists,
112-
unless they are referenced with schema-qualified names.
113-
Any indexes created on a temporary table are automatically
110+
session or optionally at the end of the current transaction
111+
(See ON COMMIT below). Existing permanent tables with the same
112+
name are not visible to the current session while the temporary
113+
table exists, unless they are referenced with schema-qualified
114+
names. Any indexes created on a temporary table are automatically
114115
temporary as well.
115116
</para>
116117

@@ -487,9 +488,54 @@ and <replaceable class="PARAMETER">table_constraint</replaceable> is:
487488
</para>
488489
</listitem>
489490
</varlistentry>
490-
</variablelist>
491491

492+
<varlistentry>
493+
<term><literal>ON COMMIT</literal></term>
494+
<listitem>
495+
<para>
496+
The behaviour of temporary tables at the end of a transaction
497+
block can be controlled using <literal>ON COMMIT</literal>.
498+
The table will exhibit the same behavior at the end of
499+
transaction blocks for the duration of the session unless
500+
ON COMMIT DROP is specified or the temporary table is dropped.
501+
</para>
502+
<para>
503+
The three parameters to ON COMMIT are:
504+
505+
<variablelist>
506+
<varlistentry>
507+
<term><literal>PRESERVE ROWS</literal></term>
508+
<listitem>
509+
<para>
510+
The rows in the temporary table will persist after the
511+
transaction block.
512+
</para>
513+
</listitem>
514+
</varlistentry>
515+
516+
<varlistentry>
517+
<term><literal>DELETE ROWS</literal></term>
518+
<listitem>
519+
<para>
520+
All rows in the temporary table will be deleted at the
521+
end of the transaction block.
522+
</para>
523+
</listitem>
524+
</varlistentry>
492525

526+
<varlistentry>
527+
<term><literal>DROP</literal></term>
528+
<listitem>
529+
<para>
530+
The temporary table will be dropped at the end of the transaction.
531+
</para>
532+
</listitem>
533+
</varlistentry>
534+
</variablelist>
535+
</para>
536+
</listitem>
537+
</varlistentry>
538+
</variablelist>
493539
</refsect1>
494540

495541

‎src/backend/access/transam/xact.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.135 2002/10/22 22:44:36 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.136 2002/11/09 23:56:38 momjian Exp $
1212
*
1313
* NOTES
1414
*Transaction aborts can now occur two ways:
@@ -166,6 +166,7 @@
166166
#include"catalog/index.h"
167167
#include"catalog/namespace.h"
168168
#include"commands/async.h"
169+
#include"commands/tablecmds.h"
169170
#include"commands/trigger.h"
170171
#include"commands/user.h"
171172
#include"executor/spi.h"
@@ -1026,6 +1027,7 @@ CommitTransaction(void)
10261027
AtEOXact_hash();
10271028
AtEOXact_nbtree();
10281029
AtEOXact_rtree();
1030+
AtEOXact_temp_relations(true,s->blockState);
10291031
AtEOXact_Namespace(true);
10301032
AtEOXact_CatCache(true);
10311033
AtEOXact_Files();
@@ -1136,6 +1138,7 @@ AbortTransaction(void)
11361138
AtEOXact_hash();
11371139
AtEOXact_nbtree();
11381140
AtEOXact_rtree();
1141+
AtEOXact_temp_relations(false,s->blockState);
11391142
AtEOXact_Namespace(false);
11401143
AtEOXact_CatCache(false);
11411144
AtEOXact_Files();

‎src/backend/bootstrap/bootparse.y

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.53 2002/11/01 22:52:33 tgl Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.54 2002/11/09 23:56:38 momjian Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -34,6 +34,7 @@
3434
#include"catalog/pg_class.h"
3535
#include"catalog/pg_namespace.h"
3636
#include"commands/defrem.h"
37+
#include"commands/tablecmds.h"
3738
#include"miscadmin.h"
3839
#include"nodes/makefuncs.h"
3940
#include"nodes/nodes.h"
@@ -197,6 +198,7 @@ Boot_CreateStmt:
197198
tupdesc,
198199
RELKIND_RELATION,
199200
$3,
201+
ATEOXACTNOOP,
200202
true);
201203
elog(DEBUG3,"relation created with oid %u", id);
202204
}

‎src/backend/catalog/heap.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.232 2002/10/21 22:06:18 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.233 2002/11/09 23:56:39 momjian Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -31,17 +31,20 @@
3131

3232
#include"access/heapam.h"
3333
#include"access/genam.h"
34+
#include"access/xact.h"
3435
#include"catalog/catalog.h"
3536
#include"catalog/catname.h"
3637
#include"catalog/dependency.h"
3738
#include"catalog/heap.h"
3839
#include"catalog/index.h"
3940
#include"catalog/indexing.h"
41+
#include"catalog/namespace.h"
4042
#include"catalog/pg_attrdef.h"
4143
#include"catalog/pg_constraint.h"
4244
#include"catalog/pg_inherits.h"
4345
#include"catalog/pg_statistic.h"
4446
#include"catalog/pg_type.h"
47+
#include"commands/tablecmds.h"
4548
#include"commands/trigger.h"
4649
#include"miscadmin.h"
4750
#include"nodes/makefuncs.h"
@@ -670,12 +673,14 @@ AddNewRelationType(const char *typeName,
670673
*creates a new cataloged relation. see comments above.
671674
* --------------------------------
672675
*/
676+
673677
Oid
674678
heap_create_with_catalog(constchar*relname,
675679
Oidrelnamespace,
676680
TupleDesctupdesc,
677681
charrelkind,
678682
boolshared_relation,
683+
charateoxact,/* Only used for temp relations */
679684
boolallow_system_table_mods)
680685
{
681686
Relationpg_class_desc;
@@ -717,6 +722,25 @@ heap_create_with_catalog(const char *relname,
717722
/* Assign an OID for the relation's tuple type */
718723
new_type_oid=newoid();
719724

725+
726+
/*
727+
* Add to temprels if we are a temp relation now that we have oid
728+
*/
729+
730+
if(isTempNamespace(relnamespace)) {
731+
TempTable*t;
732+
MemoryContextoldcxt;
733+
734+
oldcxt=MemoryContextSwitchTo(CacheMemoryContext);
735+
t= (TempTable*)palloc(sizeof(TempTable));
736+
t->relid=new_rel_oid;
737+
t->ateoxact=ateoxact;
738+
t->tid=GetCurrentTransactionId();
739+
t->dead= false;
740+
reg_temp_rel(t);
741+
MemoryContextSwitchTo(oldcxt);
742+
}
743+
720744
/*
721745
* now create an entry in pg_class for the relation.
722746
*
@@ -1147,6 +1171,14 @@ heap_drop_with_catalog(Oid rid)
11471171
rel->rd_rel->relkind!=RELKIND_COMPOSITE_TYPE)
11481172
smgrunlink(DEFAULT_SMGR,rel);
11491173

1174+
/*
1175+
* Keep temprels up to date so that we don't have ON COMMIT execution
1176+
* problems at the end of the next transaction block
1177+
*/
1178+
1179+
if(isTempNamespace(RelationGetNamespace(rel)))
1180+
rm_temp_rel(rid);
1181+
11501182
/*
11511183
* Close relcache entry, but *keep* AccessExclusiveLock on the
11521184
* relation until transaction commit. This ensures no one else will

‎src/backend/catalog/namespace.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
1515
* IDENTIFICATION
16-
* $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.38 2002/11/02 18:41:21 tgl Exp $
16+
* $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.39 2002/11/09 23:56:39 momjian Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -34,6 +34,7 @@
3434
#include"catalog/pg_proc.h"
3535
#include"catalog/pg_shadow.h"
3636
#include"catalog/pg_type.h"
37+
#include"commands/tablecmds.h"
3738
#include"lib/stringinfo.h"
3839
#include"miscadmin.h"
3940
#include"nodes/makefuncs.h"
@@ -1670,6 +1671,7 @@ RemoveTempRelationsCallback(void)
16701671

16711672
CommitTransactionCommand(true);
16721673
}
1674+
free_temp_rels();
16731675
}
16741676

16751677

‎src/backend/commands/cluster.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.91 2002/11/02 21:20:40 tgl Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.92 2002/11/09 23:56:39 momjian Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -25,6 +25,7 @@
2525
#include"catalog/index.h"
2626
#include"catalog/indexing.h"
2727
#include"catalog/catname.h"
28+
#include"catalog/namespace.h"
2829
#include"commands/cluster.h"
2930
#include"commands/tablecmds.h"
3031
#include"miscadmin.h"
@@ -203,6 +204,7 @@ make_new_heap(Oid OIDOldHeap, const char *NewName)
203204
tupdesc,
204205
OldHeap->rd_rel->relkind,
205206
OldHeap->rd_rel->relisshared,
207+
ATEOXACTNOOP,
206208
allowSystemTableMods);
207209

208210
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp