mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +03:00
Build out the planner support function infrastructure.
Add support function requests for estimating the selectivity, cost, and number of result rows (if a SRF) of the target function. The lack of a way to estimate selectivity of a boolean-returning function in WHERE has been a recognized deficiency of the planner since Berkeley days. This commit finally fixes it. In addition, non-constant estimates of cost and number of output rows are now possible. We still fall back to looking at procost and prorows if the support function doesn't service the request, of course. To make concrete use of the possibility of estimating output rowcount for SRFs, this commit adds support functions for array_unnest(anyarray) and the integer variants of generate_series; the lack of plausible rowcount estimates for those, even when it's obvious to a human, has been a repeated subject of complaints. Obviously, much more could now be done in this line, but I'm mostly just trying to get the infrastructure in place. Discussion: https://postgr.es/m/15193.1548028093@sss.pgh.pa.us
This commit is contained in:
45
src/backend/utils/cache/lsyscache.c
vendored
45
src/backend/utils/cache/lsyscache.c
vendored
@ -1605,41 +1605,28 @@ get_func_leakproof(Oid funcid)
|
||||
}
|
||||
|
||||
/*
|
||||
* get_func_cost
|
||||
* Given procedure id, return the function's procost field.
|
||||
* get_func_support
|
||||
*
|
||||
* Returns the support function OID associated with a given function,
|
||||
* or InvalidOid if there is none.
|
||||
*/
|
||||
float4
|
||||
get_func_cost(Oid funcid)
|
||||
RegProcedure
|
||||
get_func_support(Oid funcid)
|
||||
{
|
||||
HeapTuple tp;
|
||||
float4 result;
|
||||
|
||||
tp = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcid));
|
||||
if (!HeapTupleIsValid(tp))
|
||||
elog(ERROR, "cache lookup failed for function %u", funcid);
|
||||
if (HeapTupleIsValid(tp))
|
||||
{
|
||||
Form_pg_proc functup = (Form_pg_proc) GETSTRUCT(tp);
|
||||
RegProcedure result;
|
||||
|
||||
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 = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcid));
|
||||
if (!HeapTupleIsValid(tp))
|
||||
elog(ERROR, "cache lookup failed for function %u", funcid);
|
||||
|
||||
result = ((Form_pg_proc) GETSTRUCT(tp))->prorows;
|
||||
ReleaseSysCache(tp);
|
||||
return result;
|
||||
result = functup->prosupport;
|
||||
ReleaseSysCache(tp);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
return (RegProcedure) InvalidOid;
|
||||
}
|
||||
|
||||
/* ---------- RELATION CACHE ---------- */
|
||||
|
Reference in New Issue
Block a user