|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * 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 $ |
12 | 12 | *
|
13 | 13 | *
|
14 | 14 | * INTERFACE ROUTINES
|
|
31 | 31 |
|
32 | 32 | #include"access/heapam.h"
|
33 | 33 | #include"access/genam.h"
|
| 34 | +#include"access/xact.h" |
34 | 35 | #include"catalog/catalog.h"
|
35 | 36 | #include"catalog/catname.h"
|
36 | 37 | #include"catalog/dependency.h"
|
37 | 38 | #include"catalog/heap.h"
|
38 | 39 | #include"catalog/index.h"
|
39 | 40 | #include"catalog/indexing.h"
|
| 41 | +#include"catalog/namespace.h" |
40 | 42 | #include"catalog/pg_attrdef.h"
|
41 | 43 | #include"catalog/pg_constraint.h"
|
42 | 44 | #include"catalog/pg_inherits.h"
|
43 | 45 | #include"catalog/pg_statistic.h"
|
44 | 46 | #include"catalog/pg_type.h"
|
| 47 | +#include"commands/tablecmds.h" |
45 | 48 | #include"commands/trigger.h"
|
46 | 49 | #include"miscadmin.h"
|
47 | 50 | #include"nodes/makefuncs.h"
|
@@ -670,12 +673,14 @@ AddNewRelationType(const char *typeName,
|
670 | 673 | *creates a new cataloged relation. see comments above.
|
671 | 674 | * --------------------------------
|
672 | 675 | */
|
| 676 | + |
673 | 677 | Oid
|
674 | 678 | heap_create_with_catalog(constchar*relname,
|
675 | 679 | Oidrelnamespace,
|
676 | 680 | TupleDesctupdesc,
|
677 | 681 | charrelkind,
|
678 | 682 | boolshared_relation,
|
| 683 | +charateoxact,/* Only used for temp relations */ |
679 | 684 | boolallow_system_table_mods)
|
680 | 685 | {
|
681 | 686 | Relationpg_class_desc;
|
@@ -717,6 +722,25 @@ heap_create_with_catalog(const char *relname,
|
717 | 722 | /* Assign an OID for the relation's tuple type */
|
718 | 723 | new_type_oid=newoid();
|
719 | 724 |
|
| 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 | + |
720 | 744 | /*
|
721 | 745 | * now create an entry in pg_class for the relation.
|
722 | 746 | *
|
@@ -1147,6 +1171,14 @@ heap_drop_with_catalog(Oid rid)
|
1147 | 1171 | rel->rd_rel->relkind!=RELKIND_COMPOSITE_TYPE)
|
1148 | 1172 | smgrunlink(DEFAULT_SMGR,rel);
|
1149 | 1173 |
|
| 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 | + |
1150 | 1182 | /*
|
1151 | 1183 | * Close relcache entry, but *keep* AccessExclusiveLock on the
|
1152 | 1184 | * relation until transaction commit. This ensures no one else will
|
|