mirror of
https://github.com/postgres/postgres.git
synced 2025-07-14 08:21:07 +03:00
Restructure index access method API to hide most of it at the C level.
This patch reduces pg_am to just two columns, a name and a handler function. All the data formerly obtained from pg_am is now provided in a C struct returned by the handler function. This is similar to the designs we've adopted for FDWs and tablesample methods. There are multiple advantages. For one, the index AM's support functions are now simple C functions, making them faster to call and much less error-prone, since the C compiler can now check function signatures. For another, this will make it far more practical to define index access methods in installable extensions. A disadvantage is that SQL-level code can no longer see attributes of index AMs; in particular, some of the crosschecks in the opr_sanity regression test are no longer possible from SQL. We've addressed that by adding a facility for the index AM to perform such checks instead. (Much more could be done in that line, but for now we're content if the amvalidate functions more or less replace what opr_sanity used to do.) We might also want to expose some sort of reporting functionality, but this patch doesn't do that. Alexander Korotkov, reviewed by Petr Jelínek, and rather heavily editorialized on by me.
This commit is contained in:
@ -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.
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user