OSDN Git Service

Add a "relistemp" boolean column to pg_class, which is true for temporary
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 31 Mar 2009 17:59:56 +0000 (17:59 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 31 Mar 2009 17:59:56 +0000 (17:59 +0000)
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.

doc/src/sgml/catalogs.sgml
src/backend/catalog/heap.c
src/backend/utils/cache/relcache.c
src/include/catalog/catversion.h
src/include/catalog/pg_attribute.h
src/include/catalog/pg_class.h

index 0ab11dd..eb17a0b 100644 (file)
@@ -1,4 +1,4 @@
-<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.199 2009/03/05 23:06:45 tgl Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/catalogs.sgml,v 2.200 2009/03/31 17:59:55 tgl Exp $ -->
 <!--
  Documentation of the system catalogs, directed toward PostgreSQL developers
  -->
      </row>
 
      <row>
+      <entry><structfield>relistemp</structfield></entry>
+      <entry><type>bool</type></entry>
+      <entry></entry>
+      <entry>
+       True if this table is a temporary relation.  If so, only the creating
+       session can safely access its contents
+      </entry>
+     </row>
+
+     <row>
       <entry><structfield>relkind</structfield></entry>
       <entry><type>char</type></entry>
       <entry></entry>
index 70083b5..f6b5210 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.351 2009/02/24 01:38:09 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.352 2009/03/31 17:59:56 tgl Exp $
  *
  *
  * INTERFACE ROUTINES
@@ -664,6 +664,7 @@ InsertPgClassTuple(Relation pg_class_desc,
        values[Anum_pg_class_reltoastidxid - 1] = ObjectIdGetDatum(rd_rel->reltoastidxid);
        values[Anum_pg_class_relhasindex - 1] = BoolGetDatum(rd_rel->relhasindex);
        values[Anum_pg_class_relisshared - 1] = BoolGetDatum(rd_rel->relisshared);
+       values[Anum_pg_class_relistemp - 1] = BoolGetDatum(rd_rel->relistemp);
        values[Anum_pg_class_relkind - 1] = CharGetDatum(rd_rel->relkind);
        values[Anum_pg_class_relnatts - 1] = Int16GetDatum(rd_rel->relnatts);
        values[Anum_pg_class_relchecks - 1] = Int16GetDatum(rd_rel->relchecks);
index 196ca01..c39759e 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.284 2009/01/27 12:40:15 petere Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.285 2009/03/31 17:59:56 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1396,6 +1396,12 @@ formrdesc(const char *relationName, Oid relationReltype,
         */
        relation->rd_rel->relisshared = false;
 
+       /*
+        * Likewise, we must know if a relation is temp ... but formrdesc is
+        * not used for any temp relations.
+        */
+       relation->rd_rel->relistemp = false;
+
        relation->rd_rel->relpages = 1;
        relation->rd_rel->reltuples = 1;
        relation->rd_rel->relkind = RELKIND_RELATION;
@@ -2398,6 +2404,9 @@ RelationBuildLocalRelation(const char *relname,
         */
        rel->rd_rel->relisshared = shared_relation;
 
+       /* it is temporary if and only if it is in my temp-table namespace */
+       rel->rd_rel->relistemp = isTempOrToastNamespace(relnamespace);
+
        RelationGetRelid(rel) = relid;
 
        for (i = 0; i < natts; i++)
index e012b10..6073623 100644 (file)
@@ -37,7 +37,7 @@
  * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.526 2009/03/25 22:19:02 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.527 2009/03/31 17:59:56 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -53,6 +53,6 @@
  */
 
 /*                                                     yyyymmddN */
-#define CATALOG_VERSION_NO     200903251
+#define CATALOG_VERSION_NO     200903311
 
 #endif
index 3fddf7e..6fd6a08 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/catalog/pg_attribute.h,v 1.146 2009/01/22 20:16:08 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/pg_attribute.h,v 1.147 2009/03/31 17:59:56 tgl Exp $
  *
  * NOTES
  *       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_));
 { 1259, {"reltoastidxid"}, 26, -1,     4, 11, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, { 0 } }, \
 { 1259, {"relhasindex"},   16, -1,     1, 12, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
 { 1259, {"relisshared"},   16, -1,     1, 13, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
-{ 1259, {"relkind"},      18, -1,      1, 14, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
-{ 1259, {"relnatts"},     21, -1,      2, 15, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, { 0 } }, \
-{ 1259, {"relchecks"},    21, -1,      2, 16, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, { 0 } }, \
-{ 1259, {"relhasoids"},    16, -1,     1, 17, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
-{ 1259, {"relhaspkey"},    16, -1,     1, 18, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
-{ 1259, {"relhasrules"},   16, -1,     1, 19, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
-{ 1259, {"relhastriggers"},16, -1,     1, 20, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
-{ 1259, {"relhassubclass"},16, -1,     1, 21, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
-{ 1259, {"relfrozenxid"},  28, -1,     4, 22, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, { 0 } }, \
-{ 1259, {"relacl"},             1034, -1, -1, 23, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, { 0 } }, \
-{ 1259, {"reloptions"},  1009, -1, -1, 24, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, { 0 } }
+{ 1259, {"relistemp"},     16, -1,     1, 14, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
+{ 1259, {"relkind"},      18, -1,      1, 15, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
+{ 1259, {"relnatts"},     21, -1,      2, 16, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, { 0 } }, \
+{ 1259, {"relchecks"},    21, -1,      2, 17, 0, -1, -1, true, 'p', 's', true, false, false, true, 0, { 0 } }, \
+{ 1259, {"relhasoids"},    16, -1,     1, 18, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
+{ 1259, {"relhaspkey"},    16, -1,     1, 19, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
+{ 1259, {"relhasrules"},   16, -1,     1, 20, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
+{ 1259, {"relhastriggers"},16, -1,     1, 21, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
+{ 1259, {"relhassubclass"},16, -1,     1, 22, 0, -1, -1, true, 'p', 'c', true, false, false, true, 0, { 0 } }, \
+{ 1259, {"relfrozenxid"},  28, -1,     4, 23, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0, { 0 } }, \
+{ 1259, {"relacl"},             1034, -1, -1, 24, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, { 0 } }, \
+{ 1259, {"reloptions"},  1009, -1, -1, 25, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0, { 0 } }
 
 DATA(insert ( 1259 relname                     19 -1 NAMEDATALEN       1 0 -1 -1 f p c t f f t 0 _null_));
 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_));
 DATA(insert ( 1259 reltoastidxid       26 -1 4  11 0 -1 -1 t p i t f f t 0 _null_));
 DATA(insert ( 1259 relhasindex         16 -1 1  12 0 -1 -1 t p c t f f t 0 _null_));
 DATA(insert ( 1259 relisshared         16 -1 1  13 0 -1 -1 t p c t f f t 0 _null_));
-DATA(insert ( 1259 relkind                     18 -1 1  14 0 -1 -1 t p c t f f t 0 _null_));
-DATA(insert ( 1259 relnatts                    21 -1 2  15 0 -1 -1 t p s t f f t 0 _null_));
-DATA(insert ( 1259 relchecks           21 -1 2  16 0 -1 -1 t p s t f f t 0 _null_));
-DATA(insert ( 1259 relhasoids          16 -1 1  17 0 -1 -1 t p c t f f t 0 _null_));
-DATA(insert ( 1259 relhaspkey          16 -1 1  18 0 -1 -1 t p c t f f t 0 _null_));
-DATA(insert ( 1259 relhasrules         16 -1 1  19 0 -1 -1 t p c t f f t 0 _null_));
-DATA(insert ( 1259 relhastriggers      16 -1 1  20 0 -1 -1 t p c t f f t 0 _null_));
-DATA(insert ( 1259 relhassubclass      16 -1 1  21 0 -1 -1 t p c t f f t 0 _null_));
-DATA(insert ( 1259 relfrozenxid                28 -1 4  22 0 -1 -1 t p i t f f t 0 _null_));
-DATA(insert ( 1259 relacl                1034 -1 -1 23 1 -1 -1 f x i f f f t 0 _null_));
-DATA(insert ( 1259 reloptions    1009 -1 -1 24 1 -1 -1 f x i f f f t 0 _null_));
+DATA(insert ( 1259 relistemp           16 -1 1  14 0 -1 -1 t p c t f f t 0 _null_));
+DATA(insert ( 1259 relkind                     18 -1 1  15 0 -1 -1 t p c t f f t 0 _null_));
+DATA(insert ( 1259 relnatts                    21 -1 2  16 0 -1 -1 t p s t f f t 0 _null_));
+DATA(insert ( 1259 relchecks           21 -1 2  17 0 -1 -1 t p s t f f t 0 _null_));
+DATA(insert ( 1259 relhasoids          16 -1 1  18 0 -1 -1 t p c t f f t 0 _null_));
+DATA(insert ( 1259 relhaspkey          16 -1 1  19 0 -1 -1 t p c t f f t 0 _null_));
+DATA(insert ( 1259 relhasrules         16 -1 1  20 0 -1 -1 t p c t f f t 0 _null_));
+DATA(insert ( 1259 relhastriggers      16 -1 1  21 0 -1 -1 t p c t f f t 0 _null_));
+DATA(insert ( 1259 relhassubclass      16 -1 1  22 0 -1 -1 t p c t f f t 0 _null_));
+DATA(insert ( 1259 relfrozenxid                28 -1 4  23 0 -1 -1 t p i t f f t 0 _null_));
+DATA(insert ( 1259 relacl                1034 -1 -1 24 1 -1 -1 f x i f f f t 0 _null_));
+DATA(insert ( 1259 reloptions    1009 -1 -1 25 1 -1 -1 f x i f f f t 0 _null_));
 DATA(insert ( 1259 ctid                                27 0  6  -1 0 -1 -1 f p s t f f t 0 _null_));
 DATA(insert ( 1259 oid                         26 0  4  -2 0 -1 -1 t p i t f f t 0 _null_));
 DATA(insert ( 1259 xmin                                28 0  4  -3 0 -1 -1 t p i t f f t 0 _null_));
index 7761588..7ad4b42 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/catalog/pg_class.h,v 1.112 2009/01/22 20:16:09 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/catalog/pg_class.h,v 1.113 2009/03/31 17:59:56 tgl Exp $
  *
  * NOTES
  *       the genbki.sh script reads this file and generates .bki
@@ -43,6 +43,7 @@ CATALOG(pg_class,1259) BKI_BOOTSTRAP
        Oid                     reltoastidxid;  /* if toast table, OID of chunk_id index */
        bool            relhasindex;    /* T if has (or has had) any indexes */
        bool            relisshared;    /* T if shared across databases */
+       bool            relistemp;              /* T if temporary relation */
        char            relkind;                /* see RELKIND_xxx constants below */
        int2            relnatts;               /* number of user attributes */
 
@@ -85,7 +86,7 @@ typedef FormData_pg_class *Form_pg_class;
  * ----------------
  */
 
-#define Natts_pg_class                                 24
+#define Natts_pg_class                                 25
 #define Anum_pg_class_relname                  1
 #define Anum_pg_class_relnamespace             2
 #define Anum_pg_class_reltype                  3
@@ -99,17 +100,18 @@ typedef FormData_pg_class *Form_pg_class;
 #define Anum_pg_class_reltoastidxid            11
 #define Anum_pg_class_relhasindex              12
 #define Anum_pg_class_relisshared              13
-#define Anum_pg_class_relkind                  14
-#define Anum_pg_class_relnatts                 15
-#define Anum_pg_class_relchecks                        16
-#define Anum_pg_class_relhasoids               17
-#define Anum_pg_class_relhaspkey               18
-#define Anum_pg_class_relhasrules              19
-#define Anum_pg_class_relhastriggers   20
-#define Anum_pg_class_relhassubclass   21
-#define Anum_pg_class_relfrozenxid             22
-#define Anum_pg_class_relacl                   23
-#define Anum_pg_class_reloptions               24
+#define Anum_pg_class_relistemp                        14
+#define Anum_pg_class_relkind                  15
+#define Anum_pg_class_relnatts                 16
+#define Anum_pg_class_relchecks                        17
+#define Anum_pg_class_relhasoids               18
+#define Anum_pg_class_relhaspkey               19
+#define Anum_pg_class_relhasrules              20
+#define Anum_pg_class_relhastriggers   21
+#define Anum_pg_class_relhassubclass   22
+#define Anum_pg_class_relfrozenxid             23
+#define Anum_pg_class_relacl                   24
+#define Anum_pg_class_reloptions               25
 
 /* ----------------
  *             initial contents of pg_class
@@ -121,13 +123,13 @@ typedef FormData_pg_class *Form_pg_class;
  */
 
 /* Note: "3" in the relfrozenxid column stands for FirstNormalTransactionId */
-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_ ));
+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_ ));
 DESCR("");
-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_ ));
+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_ ));
 DESCR("");
-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_ ));
+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_ ));
 DESCR("");
-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_ ));
+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_ ));
 DESCR("");
 
 #define                  RELKIND_INDEX                   'i'           /* secondary index */