aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2011-12-18 15:49:00 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2011-12-18 15:50:37 -0500
commit3695a555136a6d179cac8ae48d5f90171d5b30e9 (patch)
treeefb7fb5afb3dea1292c9a50635b53215cc548e64 /src/backend
parent19d223171801dda36f84e24dc89c9fbab1ababad (diff)
downloadpostgresql-3695a555136a6d179cac8ae48d5f90171d5b30e9.tar.gz
postgresql-3695a555136a6d179cac8ae48d5f90171d5b30e9.zip
Replace simple constant pg_am.amcanreturn with an AM support function.
The need for this was debated when we put in the index-only-scan feature, but at the time we had no near-term expectation of having AMs that could support such scans for only some indexes; so we kept it simple. However, the SP-GiST AM forces the issue, so let's fix it. This patch only installs the new API; no behavior actually changes.
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/access/index/indexam.c22
-rw-r--r--src/backend/access/nbtree/nbtree.c11
-rw-r--r--src/backend/access/spgist/spgscan.c7
-rw-r--r--src/backend/optimizer/path/indxpath.c4
-rw-r--r--src/backend/optimizer/util/plancat.c2
5 files changed, 43 insertions, 3 deletions
diff --git a/src/backend/access/index/indexam.c b/src/backend/access/index/indexam.c
index 6d423a7d682..e5fb5183897 100644
--- a/src/backend/access/index/indexam.c
+++ b/src/backend/access/index/indexam.c
@@ -26,6 +26,7 @@
* index_getbitmap - get all tuples from a scan
* index_bulk_delete - bulk deletion of index tuples
* index_vacuum_cleanup - post-deletion cleanup of an index
+ * index_can_return - does index support index-only scans?
* index_getprocid - get a support procedure OID
* index_getprocinfo - get a support procedure's lookup info
*
@@ -712,6 +713,27 @@ index_vacuum_cleanup(IndexVacuumInfo *info,
}
/* ----------------
+ * index_can_return - does index support index-only scans?
+ * ----------------
+ */
+bool
+index_can_return(Relation indexRelation)
+{
+ FmgrInfo *procedure;
+
+ RELATION_CHECKS;
+
+ /* amcanreturn is optional; assume FALSE if not provided by AM */
+ if (!RegProcedureIsValid(indexRelation->rd_am->amcanreturn))
+ return false;
+
+ GET_REL_PROCEDURE(amcanreturn);
+
+ return DatumGetBool(FunctionCall1(procedure,
+ PointerGetDatum(indexRelation)));
+}
+
+/* ----------------
* index_getprocid
*
* Index access methods typically require support routines that are
diff --git a/src/backend/access/nbtree/nbtree.c b/src/backend/access/nbtree/nbtree.c
index f3a1d256a05..13c05525179 100644
--- a/src/backend/access/nbtree/nbtree.c
+++ b/src/backend/access/nbtree/nbtree.c
@@ -1091,3 +1091,14 @@ restart:
goto restart;
}
}
+
+/*
+ * btcanreturn() -- Check whether btree indexes support index-only scans.
+ *
+ * btrees always do, so this is trivial.
+ */
+Datum
+btcanreturn(PG_FUNCTION_ARGS)
+{
+ PG_RETURN_BOOL(true);
+}
diff --git a/src/backend/access/spgist/spgscan.c b/src/backend/access/spgist/spgscan.c
index ac309649682..748265ecba7 100644
--- a/src/backend/access/spgist/spgscan.c
+++ b/src/backend/access/spgist/spgscan.c
@@ -559,3 +559,10 @@ spggettuple(PG_FUNCTION_ARGS)
PG_RETURN_BOOL(false);
}
+
+Datum
+spgcanreturn(PG_FUNCTION_ARGS)
+{
+ /* Not implemented yet */
+ PG_RETURN_BOOL(false);
+}
diff --git a/src/backend/optimizer/path/indxpath.c b/src/backend/optimizer/path/indxpath.c
index 74bc7ac7c63..fa6749a2f9c 100644
--- a/src/backend/optimizer/path/indxpath.c
+++ b/src/backend/optimizer/path/indxpath.c
@@ -1075,10 +1075,10 @@ check_index_only(RelOptInfo *rel, IndexOptInfo *index)
ListCell *lc;
int i;
- /* Index-only scans must be enabled, and AM must be capable of it */
+ /* Index-only scans must be enabled, and index must be capable of them */
if (!enable_indexonlyscan)
return false;
- if (!index->amcanreturn)
+ if (!index->canreturn)
return false;
/*
diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c
index de629e93c9a..77080192efd 100644
--- a/src/backend/optimizer/util/plancat.c
+++ b/src/backend/optimizer/util/plancat.c
@@ -212,8 +212,8 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
info->relam = indexRelation->rd_rel->relam;
info->amcostestimate = indexRelation->rd_am->amcostestimate;
+ info->canreturn = index_can_return(indexRelation);
info->amcanorderbyop = indexRelation->rd_am->amcanorderbyop;
- info->amcanreturn = indexRelation->rd_am->amcanreturn;
info->amoptionalkey = indexRelation->rd_am->amoptionalkey;
info->amsearcharray = indexRelation->rd_am->amsearcharray;
info->amsearchnulls = indexRelation->rd_am->amsearchnulls;