Skip to content

Commit df13324

Browse files
committed
Add a "relistemp" boolean column to pg_class, which is true for temporary
relations (including a temp table's indexes and toast table/index), and false for normal relations. For ease of checking, this commit just adds the column and fills it correctly --- revising the relation access machinery to use it will come separately.
1 parent eeeb782 commit df13324

File tree

6 files changed

+69
-45
lines changed

6 files changed

+69
-45
lines changed

doc/src/sgml/catalogs.sgml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.199 2009/03/05 23:06:45 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.200 2009/03/31 17:59:55 tgl Exp $ -->
22
<!--
33
Documentation of the system catalogs, directed toward PostgreSQL developers
44
-->
@@ -1532,6 +1532,16 @@
15321532
</entry>
15331533
</row>
15341534

1535+
<row>
1536+
<entry><structfield>relistemp</structfield></entry>
1537+
<entry><type>bool</type></entry>
1538+
<entry></entry>
1539+
<entry>
1540+
True if this table is a temporary relation. If so, only the creating
1541+
session can safely access its contents
1542+
</entry>
1543+
</row>
1544+
15351545
<row>
15361546
<entry><structfield>relkind</structfield></entry>
15371547
<entry><type>char</type></entry>

src/backend/catalog/heap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.351 2009/02/24 01:38:09 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.352 2009/03/31 17:59:56 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -664,6 +664,7 @@ InsertPgClassTuple(Relation pg_class_desc,
664664
values[Anum_pg_class_reltoastidxid - 1] = ObjectIdGetDatum(rd_rel->reltoastidxid);
665665
values[Anum_pg_class_relhasindex - 1] = BoolGetDatum(rd_rel->relhasindex);
666666
values[Anum_pg_class_relisshared - 1] = BoolGetDatum(rd_rel->relisshared);
667+
values[Anum_pg_class_relistemp - 1] = BoolGetDatum(rd_rel->relistemp);
667668
values[Anum_pg_class_relkind - 1] = CharGetDatum(rd_rel->relkind);
668669
values[Anum_pg_class_relnatts - 1] = Int16GetDatum(rd_rel->relnatts);
669670
values[Anum_pg_class_relchecks - 1] = Int16GetDatum(rd_rel->relchecks);

src/backend/utils/cache/relcache.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.284 2009/01/27 12:40:15 petere Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.285 2009/03/31 17:59:56 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1396,6 +1396,12 @@ formrdesc(const char *relationName, Oid relationReltype,
13961396
*/
13971397
relation->rd_rel->relisshared = false;
13981398

1399+
/*
1400+
* Likewise, we must know if a relation is temp ... but formrdesc is
1401+
* not used for any temp relations.
1402+
*/
1403+
relation->rd_rel->relistemp = false;
1404+
13991405
relation->rd_rel->relpages = 1;
14001406
relation->rd_rel->reltuples = 1;
14011407
relation->rd_rel->relkind = RELKIND_RELATION;
@@ -2398,6 +2404,9 @@ RelationBuildLocalRelation(const char *relname,
23982404
*/
23992405
rel->rd_rel->relisshared = shared_relation;
24002406

2407+
/* it is temporary if and only if it is in my temp-table namespace */
2408+
rel->rd_rel->relistemp = isTempOrToastNamespace(relnamespace);
2409+
24012410
RelationGetRelid(rel) = relid;
24022411

24032412
for (i = 0; i < natts; i++)

src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.526 2009/03/25 22:19:02 tgl Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.527 2009/03/31 17:59:56 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 200903251
56+
#define CATALOG_VERSION_NO 200903311
5757

5858
#endif

src/include/catalog/pg_attribute.h

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/catalog/pg_attribute.h,v 1.146 2009/01/22 20:16:08 tgl Exp $
11+
* $PostgreSQL: pgsql/src/include/catalog/pg_attribute.h,v 1.147 2009/03/31 17:59:56 tgl Exp $
1212
*
1313
* NOTES
1414
* the genbki.sh script reads this file and generates .bki
@@ -409,17 +409,18 @@ DATA(insert ( 1249 tableoid 26 0 4 -7 0 -1 -1 t p i t f f t 0 _null_));
409409
{ 1259, {"reltoastidxid"}, 26, -1, 4, 11, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, { 0 } }, \
410410
{ 1259, {"relhasindex"}, 16, -1, 1, 12, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
411411
{ 1259, {"relisshared"}, 16, -1, 1, 13, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
412-
{ 1259, {"relkind"}, 18, -1, 1, 14, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
413-
{ 1259, {"relnatts"}, 21, -1, 2, 15, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, { 0 } }, \
414-
{ 1259, {"relchecks"}, 21, -1, 2, 16, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, { 0 } }, \
415-
{ 1259, {"relhasoids"}, 16, -1, 1, 17, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
416-
{ 1259, {"relhaspkey"}, 16, -1, 1, 18, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
417-
{ 1259, {"relhasrules"}, 16, -1, 1, 19, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
418-
{ 1259, {"relhastriggers"},16, -1, 1, 20, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
419-
{ 1259, {"relhassubclass"},16, -1, 1, 21, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
420-
{ 1259, {"relfrozenxid"}, 28, -1, 4, 22, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, { 0 } }, \
421-
{ 1259, {"relacl"}, 1034, -1, -1, 23, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, { 0 } }, \
422-
{ 1259, {"reloptions"}, 1009, -1, -1, 24, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, { 0 } }
412+
{ 1259, {"relistemp"}, 16, -1, 1, 14, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
413+
{ 1259, {"relkind"}, 18, -1, 1, 15, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
414+
{ 1259, {"relnatts"}, 21, -1, 2, 16, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, { 0 } }, \
415+
{ 1259, {"relchecks"}, 21, -1, 2, 17, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, { 0 } }, \
416+
{ 1259, {"relhasoids"}, 16, -1, 1, 18, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
417+
{ 1259, {"relhaspkey"}, 16, -1, 1, 19, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
418+
{ 1259, {"relhasrules"}, 16, -1, 1, 20, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
419+
{ 1259, {"relhastriggers"},16, -1, 1, 21, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
420+
{ 1259, {"relhassubclass"},16, -1, 1, 22, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
421+
{ 1259, {"relfrozenxid"}, 28, -1, 4, 23, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, { 0 } }, \
422+
{ 1259, {"relacl"}, 1034, -1, -1, 24, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, { 0 } }, \
423+
{ 1259, {"reloptions"}, 1009, -1, -1, 25, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, { 0 } }
423424

424425
DATA(insert ( 1259 relname 19 -1 NAMEDATALEN 1 0 -1 -1 f p c t f f t 0 _null_));
425426
DATA(insert ( 1259 relnamespace 26 -1 4 2 0 -1 -1 t p i t f f t 0 _null_));
@@ -434,17 +435,18 @@ DATA(insert ( 1259 reltoastrelid 26 -1 4 10 0 -1 -1 t p i t f f t 0 _null_));
434435
DATA(insert ( 1259 reltoastidxid 26 -1 4 11 0 -1 -1 t p i t f f t 0 _null_));
435436
DATA(insert ( 1259 relhasindex 16 -1 1 12 0 -1 -1 t p c t f f t 0 _null_));
436437
DATA(insert ( 1259 relisshared 16 -1 1 13 0 -1 -1 t p c t f f t 0 _null_));
437-
DATA(insert ( 1259 relkind 18 -1 1 14 0 -1 -1 t p c t f f t 0 _null_));
438-
DATA(insert ( 1259 relnatts 21 -1 2 15 0 -1 -1 t p s t f f t 0 _null_));
439-
DATA(insert ( 1259 relchecks 21 -1 2 16 0 -1 -1 t p s t f f t 0 _null_));
440-
DATA(insert ( 1259 relhasoids 16 -1 1 17 0 -1 -1 t p c t f f t 0 _null_));
441-
DATA(insert ( 1259 relhaspkey 16 -1 1 18 0 -1 -1 t p c t f f t 0 _null_));
442-
DATA(insert ( 1259 relhasrules 16 -1 1 19 0 -1 -1 t p c t f f t 0 _null_));
443-
DATA(insert ( 1259 relhastriggers 16 -1 1 20 0 -1 -1 t p c t f f t 0 _null_));
444-
DATA(insert ( 1259 relhassubclass 16 -1 1 21 0 -1 -1 t p c t f f t 0 _null_));
445-
DATA(insert ( 1259 relfrozenxid 28 -1 4 22 0 -1 -1 t p i t f f t 0 _null_));
446-
DATA(insert ( 1259 relacl 1034 -1 -1 23 1 -1 -1 f x i f f f t 0 _null_));
447-
DATA(insert ( 1259 reloptions 1009 -1 -1 24 1 -1 -1 f x i f f f t 0 _null_));
438+
DATA(insert ( 1259 relistemp 16 -1 1 14 0 -1 -1 t p c t f f t 0 _null_));
439+
DATA(insert ( 1259 relkind 18 -1 1 15 0 -1 -1 t p c t f f t 0 _null_));
440+
DATA(insert ( 1259 relnatts 21 -1 2 16 0 -1 -1 t p s t f f t 0 _null_));
441+
DATA(insert ( 1259 relchecks 21 -1 2 17 0 -1 -1 t p s t f f t 0 _null_));
442+
DATA(insert ( 1259 relhasoids 16 -1 1 18 0 -1 -1 t p c t f f t 0 _null_));
443+
DATA(insert ( 1259 relhaspkey 16 -1 1 19 0 -1 -1 t p c t f f t 0 _null_));
444+
DATA(insert ( 1259 relhasrules 16 -1 1 20 0 -1 -1 t p c t f f t 0 _null_));
445+
DATA(insert ( 1259 relhastriggers 16 -1 1 21 0 -1 -1 t p c t f f t 0 _null_));
446+
DATA(insert ( 1259 relhassubclass 16 -1 1 22 0 -1 -1 t p c t f f t 0 _null_));
447+
DATA(insert ( 1259 relfrozenxid 28 -1 4 23 0 -1 -1 t p i t f f t 0 _null_));
448+
DATA(insert ( 1259 relacl 1034 -1 -1 24 1 -1 -1 f x i f f f t 0 _null_));
449+
DATA(insert ( 1259 reloptions 1009 -1 -1 25 1 -1 -1 f x i f f f t 0 _null_));
448450
DATA(insert ( 1259 ctid 27 0 6 -1 0 -1 -1 f p s t f f t 0 _null_));
449451
DATA(insert ( 1259 oid 26 0 4 -2 0 -1 -1 t p i t f f t 0 _null_));
450452
DATA(insert ( 1259 xmin 28 0 4 -3 0 -1 -1 t p i t f f t 0 _null_));

src/include/catalog/pg_class.h

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/catalog/pg_class.h,v 1.112 2009/01/22 20:16:09 tgl Exp $
11+
* $PostgreSQL: pgsql/src/include/catalog/pg_class.h,v 1.113 2009/03/31 17:59:56 tgl Exp $
1212
*
1313
* NOTES
1414
* the genbki.sh script reads this file and generates .bki
@@ -43,6 +43,7 @@ CATALOG(pg_class,1259) BKI_BOOTSTRAP
4343
Oid reltoastidxid; /* if toast table, OID of chunk_id index */
4444
bool relhasindex; /* T if has (or has had) any indexes */
4545
bool relisshared; /* T if shared across databases */
46+
bool relistemp; /* T if temporary relation */
4647
char relkind; /* see RELKIND_xxx constants below */
4748
int2 relnatts; /* number of user attributes */
4849

@@ -85,7 +86,7 @@ typedef FormData_pg_class *Form_pg_class;
8586
* ----------------
8687
*/
8788

88-
#define Natts_pg_class 24
89+
#define Natts_pg_class 25
8990
#define Anum_pg_class_relname 1
9091
#define Anum_pg_class_relnamespace 2
9192
#define Anum_pg_class_reltype 3
@@ -99,17 +100,18 @@ typedef FormData_pg_class *Form_pg_class;
99100
#define Anum_pg_class_reltoastidxid 11
100101
#define Anum_pg_class_relhasindex 12
101102
#define Anum_pg_class_relisshared 13
102-
#define Anum_pg_class_relkind 14
103-
#define Anum_pg_class_relnatts 15
104-
#define Anum_pg_class_relchecks 16
105-
#define Anum_pg_class_relhasoids 17
106-
#define Anum_pg_class_relhaspkey 18
107-
#define Anum_pg_class_relhasrules 19
108-
#define Anum_pg_class_relhastriggers 20
109-
#define Anum_pg_class_relhassubclass 21
110-
#define Anum_pg_class_relfrozenxid 22
111-
#define Anum_pg_class_relacl 23
112-
#define Anum_pg_class_reloptions 24
103+
#define Anum_pg_class_relistemp 14
104+
#define Anum_pg_class_relkind 15
105+
#define Anum_pg_class_relnatts 16
106+
#define Anum_pg_class_relchecks 17
107+
#define Anum_pg_class_relhasoids 18
108+
#define Anum_pg_class_relhaspkey 19
109+
#define Anum_pg_class_relhasrules 20
110+
#define Anum_pg_class_relhastriggers 21
111+
#define Anum_pg_class_relhassubclass 22
112+
#define Anum_pg_class_relfrozenxid 23
113+
#define Anum_pg_class_relacl 24
114+
#define Anum_pg_class_reloptions 25
113115

114116
/* ----------------
115117
* initial contents of pg_class
@@ -121,13 +123,13 @@ typedef FormData_pg_class *Form_pg_class;
121123
*/
122124

123125
/* Note: "3" in the relfrozenxid column stands for FirstNormalTransactionId */
124-
DATA(insert OID = 1247 ( pg_type PGNSP 71 PGUID 0 1247 0 0 0 0 0 f f r 28 0 t f f f f 3 _null_ _null_ ));
126+
DATA(insert OID = 1247 ( pg_type PGNSP 71 PGUID 0 1247 0 0 0 0 0 f f f r 28 0 t f f f f 3 _null_ _null_ ));
125127
DESCR("");
126-
DATA(insert OID = 1249 ( pg_attribute PGNSP 75 PGUID 0 1249 0 0 0 0 0 f f r 18 0 f f f f f 3 _null_ _null_ ));
128+
DATA(insert OID = 1249 ( pg_attribute PGNSP 75 PGUID 0 1249 0 0 0 0 0 f f f r 18 0 f f f f f 3 _null_ _null_ ));
127129
DESCR("");
128-
DATA(insert OID = 1255 ( pg_proc PGNSP 81 PGUID 0 1255 0 0 0 0 0 f f r 25 0 t f f f f 3 _null_ _null_ ));
130+
DATA(insert OID = 1255 ( pg_proc PGNSP 81 PGUID 0 1255 0 0 0 0 0 f f f r 25 0 t f f f f 3 _null_ _null_ ));
129131
DESCR("");
130-
DATA(insert OID = 1259 ( pg_class PGNSP 83 PGUID 0 1259 0 0 0 0 0 f f r 24 0 t f f f f 3 _null_ _null_ ));
132+
DATA(insert OID = 1259 ( pg_class PGNSP 83 PGUID 0 1259 0 0 0 0 0 f f f r 25 0 t f f f f 3 _null_ _null_ ));
131133
DESCR("");
132134

133135
#define RELKIND_INDEX 'i' /* secondary index */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy