aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/cache
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-01-22 01:35:23 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-01-22 01:35:23 +0000
commit5a7471c307533a1b56260b3b074dfdd20e1be5ae (patch)
tree6a3cff705e779eefac734882a66aee1631224394 /src/backend/utils/cache
parenta85e9c61e579b15d0635e04870cf1cb069fdf9ee (diff)
downloadpostgresql-5a7471c307533a1b56260b3b074dfdd20e1be5ae.tar.gz
postgresql-5a7471c307533a1b56260b3b074dfdd20e1be5ae.zip
Add COST and ROWS options to CREATE/ALTER FUNCTION, plus underlying pg_proc
columns procost and prorows, to allow simple user adjustment of the estimated cost of a function call, as well as control of the estimated number of rows returned by a set-returning function. We might eventually wish to extend this to allow function-specific estimation routines, but there seems to be consensus that we should try a simple constant estimate first. In particular this provides a relatively simple way to control the order in which different WHERE clauses are applied in a plan node, which is a Good Thing in view of the fact that the recent EquivalenceClass planner rewrite made that much less predictable than before.
Diffstat (limited to 'src/backend/utils/cache')
-rw-r--r--src/backend/utils/cache/lsyscache.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c
index d2041a507d0..c449ad6e742 100644
--- a/src/backend/utils/cache/lsyscache.c
+++ b/src/backend/utils/cache/lsyscache.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/cache/lsyscache.c,v 1.145 2007/01/21 00:57:15 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/cache/lsyscache.c,v 1.146 2007/01/22 01:35:21 tgl Exp $
*
* NOTES
* Eventually, the index information should go through here, too.
@@ -1295,6 +1295,48 @@ func_volatile(Oid funcid)
return result;
}
+/*
+ * get_func_cost
+ * Given procedure id, return the function's procost field.
+ */
+float4
+get_func_cost(Oid funcid)
+{
+ HeapTuple tp;
+ float4 result;
+
+ tp = SearchSysCache(PROCOID,
+ ObjectIdGetDatum(funcid),
+ 0, 0, 0);
+ if (!HeapTupleIsValid(tp))
+ elog(ERROR, "cache lookup failed for function %u", funcid);
+
+ result = ((Form_pg_proc) GETSTRUCT(tp))->procost;
+ ReleaseSysCache(tp);
+ return result;
+}
+
+/*
+ * get_func_rows
+ * Given procedure id, return the function's prorows field.
+ */
+float4
+get_func_rows(Oid funcid)
+{
+ HeapTuple tp;
+ float4 result;
+
+ tp = SearchSysCache(PROCOID,
+ ObjectIdGetDatum(funcid),
+ 0, 0, 0);
+ if (!HeapTupleIsValid(tp))
+ elog(ERROR, "cache lookup failed for function %u", funcid);
+
+ result = ((Form_pg_proc) GETSTRUCT(tp))->prorows;
+ ReleaseSysCache(tp);
+ return result;
+}
+
/* ---------- RELATION CACHE ---------- */
/*