Add reloscache and relpgcache cols to pg_class
authorCédric Villemain <[email protected]>
Sun, 1 May 2011 13:35:42 +0000 (15:35 +0200)
committerCédric Villemain <[email protected]>
Sun, 1 May 2011 13:35:42 +0000 (15:35 +0200)
2 columns reloscache and relpgcache to contain the percentage of files
in cache per relation. May be used by the planner and updated with
ANALYZE OSCACHE; and ANALYZE PGCACHE; (not done yet, see next commits)

Conflicts:
src/include/catalog/catversion.h

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

index 7b62818ce4b78cfab607d44bf958d816716cb3d0..25338d0ddc61be28a674c8154661f44ca04bd8e8 100644 (file)
       </entry>
      </row>
 
+     <row>
+      <entry><structfield>reloscache</structfield></entry>
+      <entry><type>float4</type></entry>
+      <entry></entry>
+      <entry>
+       Percentage of the files in OS cache.  This is only an estimate used by
+       the planner.  It is updated by <command>ANALYZE OSCACHE</command>.
+      </entry>
+     </row>
+
+     <row>
+      <entry><structfield>relpgcache</structfield></entry>
+      <entry><type>float4</type></entry>
+      <entry></entry>
+      <entry>
+       Percentage of the files in PostgreSQL cache.  This is only an estimate used by
+       the planner.  It is updated by <command>ANALYZE PGCACHE</command>.
+      </entry>
+     </row>
+
      <row>
       <entry><structfield>reltoastrelid</structfield></entry>
       <entry><type>oid</type></entry>
index 71c99318343c4c8f80b03ad237b7943b872769a8..73ba67bbb79e9833694ccd493782c9533c6fc334 100644 (file)
@@ -756,6 +756,8 @@ InsertPgClassTuple(Relation pg_class_desc,
        values[Anum_pg_class_reltablespace - 1] = ObjectIdGetDatum(rd_rel->reltablespace);
        values[Anum_pg_class_relpages - 1] = Int32GetDatum(rd_rel->relpages);
        values[Anum_pg_class_reltuples - 1] = Float4GetDatum(rd_rel->reltuples);
+       values[Anum_pg_class_reloscache - 1] = Float4GetDatum(rd_rel->reloscache);
+       values[Anum_pg_class_relpgcache - 1] = Float4GetDatum(rd_rel->relpgcache);
        values[Anum_pg_class_reltoastrelid - 1] = ObjectIdGetDatum(rd_rel->reltoastrelid);
        values[Anum_pg_class_reltoastidxid - 1] = ObjectIdGetDatum(rd_rel->reltoastidxid);
        values[Anum_pg_class_relhasindex - 1] = BoolGetDatum(rd_rel->relhasindex);
index d7e94ffc125de783d2581b8eac409369c2e5064a..159096a29a29e69e3b9bd602fa1617df3038aa52 100644 (file)
@@ -1417,6 +1417,8 @@ formrdesc(const char *relationName, Oid relationReltype,
 
        relation->rd_rel->relpages = 1;
        relation->rd_rel->reltuples = 1;
+       relation->rd_rel->reloscache = 0;
+       relation->rd_rel->relpgcache = 0;
        relation->rd_rel->relkind = RELKIND_RELATION;
        relation->rd_rel->relhasoids = hasoids;
        relation->rd_rel->relnatts = (int16) natts;
@@ -2661,6 +2663,8 @@ RelationSetNewRelfilenode(Relation relation, TransactionId freezeXid)
        {
                classform->relpages = 0;        /* it's empty until further notice */
                classform->reltuples = 0;
+               classform->reloscache = 0;
+               classform->relpgcache = 0;
        }
        classform->relfrozenxid = freezeXid;
 
index ffcce3c87cc388a327ff14db7f8becf6133f9ae7..dc79df51ca9a1fe0a93e69a0873437774f75cf8e 100644 (file)
@@ -45,6 +45,8 @@ CATALOG(pg_class,1259) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83) BKI_SCHEMA_MACRO
        Oid                     reltablespace;  /* identifier of table space for relation */
        int4            relpages;               /* # of blocks (not always up-to-date) */
        float4          reltuples;              /* # of tuples (not always up-to-date) */
+       float4          reloscache;             /* % of files in OS cache (not always up-to-date) */
+       float4          relpgcache;             /* % of files in PostgreSQL cache (not always up-to-date) */
        Oid                     reltoastrelid;  /* OID of toast table; 0 if none */
        Oid                     reltoastidxid;  /* if toast table, OID of chunk_id index */
        bool            relhasindex;    /* T if has (or has had) any indexes */
@@ -92,7 +94,7 @@ typedef FormData_pg_class *Form_pg_class;
  * ----------------
  */
 
-#define Natts_pg_class                                 26
+#define Natts_pg_class                                 28
 #define Anum_pg_class_relname                  1
 #define Anum_pg_class_relnamespace             2
 #define Anum_pg_class_reltype                  3
@@ -103,22 +105,24 @@ typedef FormData_pg_class *Form_pg_class;
 #define Anum_pg_class_reltablespace            8
 #define Anum_pg_class_relpages                 9
 #define Anum_pg_class_reltuples                        10
-#define Anum_pg_class_reltoastrelid            11
-#define Anum_pg_class_reltoastidxid            12
-#define Anum_pg_class_relhasindex              13
-#define Anum_pg_class_relisshared              14
-#define Anum_pg_class_relpersistence   15
-#define Anum_pg_class_relkind                  16
-#define Anum_pg_class_relnatts                 17
-#define Anum_pg_class_relchecks                        18
-#define Anum_pg_class_relhasoids               19
-#define Anum_pg_class_relhaspkey               20
-#define Anum_pg_class_relhasrules              21
-#define Anum_pg_class_relhastriggers   22
-#define Anum_pg_class_relhassubclass   23
-#define Anum_pg_class_relfrozenxid             24
-#define Anum_pg_class_relacl                   25
-#define Anum_pg_class_reloptions               26
+#define Anum_pg_class_reloscache               11
+#define Anum_pg_class_relpgcache               12
+#define Anum_pg_class_reltoastrelid            13
+#define Anum_pg_class_reltoastidxid            14
+#define Anum_pg_class_relhasindex              15
+#define Anum_pg_class_relisshared              16
+#define Anum_pg_class_relpersistence   17
+#define Anum_pg_class_relkind                  18
+#define Anum_pg_class_relnatts                 19
+#define Anum_pg_class_relchecks                        20
+#define Anum_pg_class_relhasoids               21
+#define Anum_pg_class_relhaspkey               22
+#define Anum_pg_class_relhasrules              23
+#define Anum_pg_class_relhastriggers   24
+#define Anum_pg_class_relhassubclass   25
+#define Anum_pg_class_relfrozenxid             26
+#define Anum_pg_class_relacl                   27
+#define Anum_pg_class_reloptions               28
 
 /* ----------------
  *             initial contents of pg_class
@@ -130,13 +134,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 0 PGUID 0 0 0 0 0 0 0 f f p r 29 0 t f f f f 3 _null_ _null_ ));
+DATA(insert OID = 1247 (  pg_type              PGNSP 71 0 PGUID 0 0 0 0 0 0 0 0 0 f f p r 29 0 t f f f f 3 _null_ _null_ ));
 DESCR("");
-DATA(insert OID = 1249 (  pg_attribute PGNSP 75 0 PGUID 0 0 0 0 0 0 0 f f p r 20 0 f f f f f 3 _null_ _null_ ));
+DATA(insert OID = 1249 (  pg_attribute PGNSP 75 0 PGUID 0 0 0 0 0 0 0 0 0 f f p r 20 0 f f f f f 3 _null_ _null_ ));
 DESCR("");
-DATA(insert OID = 1255 (  pg_proc              PGNSP 81 0 PGUID 0 0 0 0 0 0 0 f f p r 25 0 t f f f f 3 _null_ _null_ ));
+DATA(insert OID = 1255 (  pg_proc              PGNSP 81 0 PGUID 0 0 0 0 0 0 0 0 0 f f p r 25 0 t f f f f 3 _null_ _null_ ));
 DESCR("");
-DATA(insert OID = 1259 (  pg_class             PGNSP 83 0 PGUID 0 0 0 0 0 0 0 f f p r 26 0 t f f f f 3 _null_ _null_ ));
+DATA(insert OID = 1259 (  pg_class             PGNSP 83 0 PGUID 0 0 0 0 0 0 0 0 0 f f p r 28 0 t f f f f 3 _null_ _null_ ));
 DESCR("");