summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCédric Villemain2011-05-01 13:35:42 +0000
committerCédric Villemain2011-05-01 13:35:42 +0000
commit4d428b46015525b162dd6dc4e37c82e5ab423e14 (patch)
tree3f8962a87db6832a74de5ffd03ced20c4f74bcc5
parent5a71b641309ea982593edf1f28d408c21885897b (diff)
Add reloscache and relpgcache cols to pg_class
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
-rw-r--r--doc/src/sgml/catalogs.sgml20
-rw-r--r--src/backend/catalog/heap.c2
-rw-r--r--src/backend/utils/cache/relcache.c4
-rw-r--r--src/include/catalog/pg_class.h46
4 files changed, 51 insertions, 21 deletions
diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml
index 7b62818ce4..25338d0ddc 100644
--- a/doc/src/sgml/catalogs.sgml
+++ b/doc/src/sgml/catalogs.sgml
@@ -1634,6 +1634,26 @@
</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>
<entry><literal><link linkend="catalog-pg-class"><structname>pg_class</structname></link>.oid</literal></entry>
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 71c9931834..73ba67bbb7 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -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);
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index d7e94ffc12..159096a29a 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -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;
diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h
index ffcce3c87c..dc79df51ca 100644
--- a/src/include/catalog/pg_class.h
+++ b/src/include/catalog/pg_class.h
@@ -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("");