diff options
Diffstat (limited to 'src/backend/optimizer')
-rw-r--r-- | src/backend/optimizer/path/costsize.c | 14 | ||||
-rw-r--r-- | src/backend/optimizer/util/plancat.c | 24 |
2 files changed, 21 insertions, 17 deletions
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c index 4e17fac6c13..8fb483aaebd 100644 --- a/src/backend/optimizer/path/costsize.c +++ b/src/backend/optimizer/path/costsize.c @@ -75,6 +75,7 @@ #endif #include <math.h> +#include "access/amapi.h" #include "access/htup_details.h" #include "access/tsmapi.h" #include "executor/executor.h" @@ -364,6 +365,7 @@ cost_index(IndexPath *path, PlannerInfo *root, double loop_count) IndexOptInfo *index = path->indexinfo; RelOptInfo *baserel = index->rel; bool indexonly = (path->path.pathtype == T_IndexOnlyScan); + amcostestimate_function amcostestimate; List *qpquals; Cost startup_cost = 0; Cost run_cost = 0; @@ -419,14 +421,10 @@ cost_index(IndexPath *path, PlannerInfo *root, double loop_count) * the fraction of main-table tuples we will have to retrieve) and its * correlation to the main-table tuple order. */ - OidFunctionCall7(index->amcostestimate, - PointerGetDatum(root), - PointerGetDatum(path), - Float8GetDatum(loop_count), - PointerGetDatum(&indexStartupCost), - PointerGetDatum(&indexTotalCost), - PointerGetDatum(&indexSelectivity), - PointerGetDatum(&indexCorrelation)); + amcostestimate = index->amcostestimate; /* cast to proper type */ + amcostestimate(root, path, loop_count, + &indexStartupCost, &indexTotalCost, + &indexSelectivity, &indexCorrelation); /* * Save amcostestimate's results for possible use in bitmap scan planning. diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index d5528e03818..0ea9fcf7c20 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -27,6 +27,7 @@ #include "catalog/catalog.h" #include "catalog/dependency.h" #include "catalog/heap.h" +#include "catalog/pg_am.h" #include "foreign/fdwapi.h" #include "miscadmin.h" #include "nodes/makefuncs.h" @@ -163,6 +164,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, Oid indexoid = lfirst_oid(l); Relation indexRelation; Form_pg_index index; + IndexAmRoutine *amroutine; IndexOptInfo *info; int ncolumns; int i; @@ -223,13 +225,17 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, } info->relam = indexRelation->rd_rel->relam; - info->amcostestimate = indexRelation->rd_am->amcostestimate; - info->amcanorderbyop = indexRelation->rd_am->amcanorderbyop; - info->amoptionalkey = indexRelation->rd_am->amoptionalkey; - info->amsearcharray = indexRelation->rd_am->amsearcharray; - info->amsearchnulls = indexRelation->rd_am->amsearchnulls; - info->amhasgettuple = OidIsValid(indexRelation->rd_am->amgettuple); - info->amhasgetbitmap = OidIsValid(indexRelation->rd_am->amgetbitmap); + + /* We copy just the fields we need, not all of rd_amroutine */ + amroutine = indexRelation->rd_amroutine; + info->amcanorderbyop = amroutine->amcanorderbyop; + info->amoptionalkey = amroutine->amoptionalkey; + info->amsearcharray = amroutine->amsearcharray; + info->amsearchnulls = amroutine->amsearchnulls; + info->amhasgettuple = (amroutine->amgettuple != NULL); + info->amhasgetbitmap = (amroutine->amgetbitmap != NULL); + info->amcostestimate = amroutine->amcostestimate; + Assert(info->amcostestimate != NULL); /* * Fetch the ordering information for the index, if any. @@ -240,7 +246,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, * If it's a btree index, we can use its opfamily OIDs * directly as the sort ordering opfamily OIDs. */ - Assert(indexRelation->rd_am->amcanorder); + Assert(amroutine->amcanorder); info->sortopfamily = info->opfamily; info->reverse_sort = (bool *) palloc(sizeof(bool) * ncolumns); @@ -254,7 +260,7 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, info->nulls_first[i] = (opt & INDOPTION_NULLS_FIRST) != 0; } } - else if (indexRelation->rd_am->amcanorder) + else if (amroutine->amcanorder) { /* * Otherwise, identify the corresponding btree opfamilies by |