aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/selfuncs.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2006-04-27 17:52:40 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2006-04-27 17:52:40 +0000
commit0f0a33099cf99e292c832efc60cf07fc8170bc5f (patch)
tree6f59dfa841fa8ce7b45dbdb21e8cc2238b466a17 /src/backend/utils/adt/selfuncs.c
parentafab814a18f5eb75a3f63381fc38e08295be4f76 (diff)
downloadpostgresql-0f0a33099cf99e292c832efc60cf07fc8170bc5f.tar.gz
postgresql-0f0a33099cf99e292c832efc60cf07fc8170bc5f.zip
Generalize mcv_selectivity() to support both VAR OP CONST and CONST OP VAR
cases. This was not needed in the existing uses within selfuncs.c, but if we're gonna export it for general use, the extra generality seems helpful. Motivated by looking at ltree example.
Diffstat (limited to 'src/backend/utils/adt/selfuncs.c')
-rw-r--r--src/backend/utils/adt/selfuncs.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index 17817c0ef3e..082089b9f11 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -15,7 +15,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.202 2006/04/27 00:46:58 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.203 2006/04/27 17:52:40 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -420,7 +420,7 @@ scalarineqsel(PlannerInfo *root, Oid operator, bool isgt,
* to the result selectivity. Also add up the total fraction represented
* by MCV entries.
*/
- mcv_selec = mcv_selectivity(vardata, &opproc, constval,
+ mcv_selec = mcv_selectivity(vardata, &opproc, constval, true,
&sumcommon);
/*
@@ -460,16 +460,17 @@ scalarineqsel(PlannerInfo *root, Oid operator, bool isgt,
* mcv_selectivity - Examine the MCV list for scalarineqsel
*
* Determine the fraction of the variable's MCV population that satisfies
- * the predicate (VAR OP CONST), as well as the fraction of the total column
- * population represented by the MCV list. This code will work for any
- * boolean-returning predicate operator.
+ * the predicate (VAR OP CONST), or (CONST OP VAR) if !varonleft. Also
+ * compute the fraction of the total column population represented by the MCV
+ * list. This code will work for any boolean-returning predicate operator.
*
* The function result is the MCV selectivity, and the fraction of the
* total population is returned into *sumcommonp. Zeroes are returned
* if there is no MCV list.
*/
double
-mcv_selectivity(VariableStatData *vardata, FmgrInfo *opproc, Datum constval,
+mcv_selectivity(VariableStatData *vardata, FmgrInfo *opproc,
+ Datum constval, bool varonleft,
double *sumcommonp)
{
double mcv_selec,
@@ -483,11 +484,6 @@ mcv_selectivity(VariableStatData *vardata, FmgrInfo *opproc, Datum constval,
mcv_selec = 0.0;
sumcommon = 0.0;
- /*
- * If we have most-common-values info, add up the fractions of the MCV
- * entries that satisfy MCV OP CONST. Also add up the total fraction
- * represented by MCV entries.
- */
if (HeapTupleIsValid(vardata->statsTuple) &&
get_attstatsslot(vardata->statsTuple,
vardata->atttype, vardata->atttypmod,
@@ -497,9 +493,13 @@ mcv_selectivity(VariableStatData *vardata, FmgrInfo *opproc, Datum constval,
{
for (i = 0; i < nvalues; i++)
{
- if (DatumGetBool(FunctionCall2(opproc,
+ if (varonleft ?
+ DatumGetBool(FunctionCall2(opproc,
values[i],
- constval)))
+ constval)) :
+ DatumGetBool(FunctionCall2(opproc,
+ constval,
+ values[i])))
mcv_selec += numbers[i];
sumcommon += numbers[i];
}
@@ -1018,7 +1018,7 @@ patternsel(PG_FUNCTION_ARGS, Pattern_Type ptype)
* represented by MCV entries.
*/
fmgr_info(get_opcode(operator), &opproc);
- mcv_selec = mcv_selectivity(&vardata, &opproc, constval,
+ mcv_selec = mcv_selectivity(&vardata, &opproc, constval, true,
&sumcommon);
/*