Add reloscache & relpgcache to (Index|Rel)OptInfo
authorCédric Villemain <[email protected]>
Sun, 1 May 2011 14:17:55 +0000 (16:17 +0200)
committerCédric Villemain <[email protected]>
Sun, 1 May 2011 14:17:55 +0000 (16:17 +0200)
So that costsize.c can use the values

src/backend/access/hash/hash.c
src/backend/optimizer/util/plancat.c
src/include/nodes/relation.h
src/include/optimizer/plancat.h

index 4cb29b2bb45159991551d7fc14671dacf6bacfcc..7f39a93a732b03ffc465f2467e52e493b4374e8f 100644 (file)
@@ -54,6 +54,8 @@ hashbuild(PG_FUNCTION_ARGS)
        IndexBuildResult *result;
        BlockNumber relpages;
        double          reltuples;
+       float4          reloscache;
+       float4          relpgcache;
        uint32          num_buckets;
        HashBuildState buildstate;
 
@@ -66,7 +68,7 @@ hashbuild(PG_FUNCTION_ARGS)
                         RelationGetRelationName(index));
 
        /* Estimate the number of rows currently present in the table */
-       estimate_rel_size(heap, NULL, &relpages, &reltuples);
+       estimate_rel_size(heap, NULL, &relpages, &reltuples, &reloscache, &relpgcache);
 
        /* Initialize the hash index metadata page and initial buckets */
        num_buckets = _hash_metapinit(index, reltuples, MAIN_FORKNUM);
index fd8ea45b4a7bfb391e7bb003c2d34b7645826e81..39f9eabacda230581c5280cd9fc5b3e9ff5739c6 100644 (file)
@@ -108,7 +108,8 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
         */
        if (!inhparent)
                estimate_rel_size(relation, rel->attr_widths - rel->min_attr,
-                                                 &rel->pages, &rel->tuples);
+                                                 &rel->pages, &rel->tuples,
+                                                 &rel->oscache, &rel->pgcache);
 
        /*
         * Make list of indexes.  Ignore indexes on system catalogs if told to.
@@ -323,11 +324,14 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
                        {
                                info->pages = RelationGetNumberOfBlocks(indexRelation);
                                info->tuples = rel->tuples;
+                               info->oscache = 0;
+                               info->pgcache = 0;
                        }
                        else
                        {
                                estimate_rel_size(indexRelation, NULL,
-                                                                 &info->pages, &info->tuples);
+                                                                 &info->pages, &info->tuples,
+                                                                 &info->oscache, &info->pgcache);
                                if (info->tuples > rel->tuples)
                                        info->tuples = rel->tuples;
                        }
@@ -362,7 +366,8 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
  */
 void
 estimate_rel_size(Relation rel, int32 *attr_widths,
-                                 BlockNumber *pages, double *tuples)
+                                 BlockNumber *pages, double *tuples,
+                                 float4 *oscache, float4 *pgcache)
 {
        BlockNumber curpages;
        BlockNumber relpages;
@@ -451,21 +456,29 @@ estimate_rel_size(Relation rel, int32 *attr_widths,
                                density = (BLCKSZ - SizeOfPageHeaderData) / tuple_width;
                        }
                        *tuples = rint(density * (double) curpages);
+                       *oscache = (float4) rel->rd_rel->reloscache;
+                       *pgcache = (float4) rel->rd_rel->relpgcache;
                        break;
                case RELKIND_SEQUENCE:
                        /* Sequences always have a known size */
                        *pages = 1;
                        *tuples = 1;
+                       *oscache = 0;
+                       *pgcache = 0;
                        break;
                case RELKIND_FOREIGN_TABLE:
                        /* Just use whatever's in pg_class */
                        *pages = rel->rd_rel->relpages;
                        *tuples = rel->rd_rel->reltuples;
+                       *oscache = 0;
+                       *pgcache = 0;
                        break;
                default:
                        /* else it has no disk storage; probably shouldn't get here? */
                        *pages = 0;
                        *tuples = 0;
+                       *oscache = 0;
+                       *pgcache = 0;
                        break;
        }
 }
index f6592697e44557d2b0850a3bcea0de7d4507df83..3f08bb00e34844c13943016c901cc89c0d85b681 100644 (file)
@@ -408,6 +408,8 @@ typedef struct RelOptInfo
        List       *indexlist;          /* list of IndexOptInfo */
        BlockNumber pages;
        double          tuples;
+       float4          oscache;
+       float4          pgcache;
        struct Plan *subplan;           /* if subquery */
        List       *subrtable;          /* if subquery */
        List       *subrowmark;         /* if subquery */
@@ -466,6 +468,8 @@ typedef struct IndexOptInfo
        /* statistics from pg_class */
        BlockNumber pages;                      /* number of disk pages in index */
        double          tuples;                 /* number of index tuples in index */
+       float4          oscache;
+       float4          pgcache;
 
        /* index descriptor information */
        int                     ncolumns;               /* number of columns in index */
index c0b8eda8137dc23ff6707e7d90da0ed6473ea4e5..1dc78d5bbb4a269093de8435ee6d76c75a37cbfc 100644 (file)
@@ -29,7 +29,8 @@ extern void get_relation_info(PlannerInfo *root, Oid relationObjectId,
                                  bool inhparent, RelOptInfo *rel);
 
 extern void estimate_rel_size(Relation rel, int32 *attr_widths,
-                                 BlockNumber *pages, double *tuples);
+                                                         BlockNumber *pages, double *tuples,
+                                                         float4 *oscache, float4 *pgcache);
 
 extern int32 get_relation_data_width(Oid relid, int32 *attr_widths);