15
15
*
16
16
*
17
17
* IDENTIFICATION
18
- * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.202 2006/04/2700:46:58 tgl Exp $
18
+ * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.203 2006/04/2717:52:40 tgl Exp $
19
19
*
20
20
*-------------------------------------------------------------------------
21
21
*/
@@ -420,7 +420,7 @@ scalarineqsel(PlannerInfo *root, Oid operator, bool isgt,
420
420
* to the result selectivity. Also add up the total fraction represented
421
421
* by MCV entries.
422
422
*/
423
- mcv_selec = mcv_selectivity (vardata ,& opproc ,constval ,
423
+ mcv_selec = mcv_selectivity (vardata ,& opproc ,constval , true,
424
424
& sumcommon );
425
425
426
426
/*
@@ -460,16 +460,17 @@ scalarineqsel(PlannerInfo *root, Oid operator, bool isgt,
460
460
*mcv_selectivity- Examine the MCV list for scalarineqsel
461
461
*
462
462
* Determine the fraction of the variable's MCV population that satisfies
463
- * the predicate (VAR OP CONST),as well as the fraction of the total column
464
- *population represented by theMCV list. This code will work for any
465
- * boolean-returning predicate operator.
463
+ * the predicate (VAR OP CONST),or (CONST OP VAR) if !varonleft. Also
464
+ *compute thefraction of the total column population represented by the MCV
465
+ *list. This code will work for any boolean-returning predicate operator.
466
466
*
467
467
* The function result is the MCV selectivity, and the fraction of the
468
468
* total population is returned into *sumcommonp. Zeroes are returned
469
469
* if there is no MCV list.
470
470
*/
471
471
double
472
- mcv_selectivity (VariableStatData * vardata ,FmgrInfo * opproc ,Datum constval ,
472
+ mcv_selectivity (VariableStatData * vardata ,FmgrInfo * opproc ,
473
+ Datum constval ,bool varonleft ,
473
474
double * sumcommonp )
474
475
{
475
476
double mcv_selec ,
@@ -483,11 +484,6 @@ mcv_selectivity(VariableStatData *vardata, FmgrInfo *opproc, Datum constval,
483
484
mcv_selec = 0.0 ;
484
485
sumcommon = 0.0 ;
485
486
486
- /*
487
- * If we have most-common-values info, add up the fractions of the MCV
488
- * entries that satisfy MCV OP CONST. Also add up the total fraction
489
- * represented by MCV entries.
490
- */
491
487
if (HeapTupleIsValid (vardata -> statsTuple )&&
492
488
get_attstatsslot (vardata -> statsTuple ,
493
489
vardata -> atttype ,vardata -> atttypmod ,
@@ -497,9 +493,13 @@ mcv_selectivity(VariableStatData *vardata, FmgrInfo *opproc, Datum constval,
497
493
{
498
494
for (i = 0 ;i < nvalues ;i ++ )
499
495
{
500
- if (DatumGetBool (FunctionCall2 (opproc ,
496
+ if (varonleft ?
497
+ DatumGetBool (FunctionCall2 (opproc ,
501
498
values [i ],
502
- constval )))
499
+ constval )) :
500
+ DatumGetBool (FunctionCall2 (opproc ,
501
+ constval ,
502
+ values [i ])))
503
503
mcv_selec += numbers [i ];
504
504
sumcommon += numbers [i ];
505
505
}
@@ -1018,7 +1018,7 @@ patternsel(PG_FUNCTION_ARGS, Pattern_Type ptype)
1018
1018
* represented by MCV entries.
1019
1019
*/
1020
1020
fmgr_info (get_opcode (operator ),& opproc );
1021
- mcv_selec = mcv_selectivity (& vardata ,& opproc ,constval ,
1021
+ mcv_selec = mcv_selectivity (& vardata ,& opproc ,constval , true,
1022
1022
& sumcommon );
1023
1023
1024
1024
/*