summaryrefslogtreecommitdiff
path: root/src/backend/statistics/mcv.c
diff options
context:
space:
mode:
authorTomas Vondra <tomas.vondra@postgresql.org>2019-07-19 16:28:28 +0200
committerTomas Vondra <tomas.vondra@postgresql.org>2019-07-20 16:34:58 +0200
commitfc4faea17971a927daf936a4b17564140ee412f6 (patch)
treec9abf29087f1102b5d1f742aa2e372502c118d5b /src/backend/statistics/mcv.c
parent533522846ba050efe9df740e5916ced87144c8f2 (diff)
Rework examine_opclause_expression to use varonleft
The examine_opclause_expression function needs to return information on which side of the operator we found the Var, but the variable was called "isgt" which is rather misleading (it assumes the operator is either less-than or greater-than, but it may be equality or something else). Other places in the planner use a variable called "varonleft" for this purpose, so just adopt the same convention here. The code also assumed we don't care about this flag for equality, as (Var = Const) and (Const = Var) should be the same thing. But that does not work for cross-type operators, in which case we need to pass the parameters to the procedure in the right order. So just use the same code for all types of expressions. This means we don't need to care about the selectivity estimation function anymore, at least not in this code. We should only get the supported cases here (thanks to statext_is_compatible_clause). Reviewed-by: Tom Lane Discussion: https://postgr.es/m/8736jdhbhc.fsf%40ansel.ydns.eu Backpatch-to: 12
Diffstat (limited to 'src/backend/statistics/mcv.c')
-rw-r--r--src/backend/statistics/mcv.c62
1 files changed, 17 insertions, 45 deletions
diff --git a/src/backend/statistics/mcv.c b/src/backend/statistics/mcv.c
index e5a4e86c5d8..2b685ec67a2 100644
--- a/src/backend/statistics/mcv.c
+++ b/src/backend/statistics/mcv.c
@@ -1581,18 +1581,15 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
OpExpr *expr = (OpExpr *) clause;
FmgrInfo opproc;
- /* get procedure computing operator selectivity */
- RegProcedure oprrest = get_oprrest(expr->opno);
-
/* valid only after examine_opclause_expression returns true */
Var *var;
Const *cst;
- bool isgt;
+ bool varonleft;
fmgr_info(get_opcode(expr->opno), &opproc);
/* extract the var and const from the expression */
- if (examine_opclause_expression(expr, &var, &cst, &isgt))
+ if (examine_opclause_expression(expr, &var, &cst, &varonleft))
{
int idx;
@@ -1629,46 +1626,21 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
if (RESULT_IS_FINAL(matches[i], is_or))
continue;
- switch (oprrest)
- {
- case F_EQSEL:
- case F_NEQSEL:
-
- /*
- * We don't care about isgt in equality, because
- * it does not matter whether it's (var op const)
- * or (const op var).
- */
- match = DatumGetBool(FunctionCall2Coll(&opproc,
- DEFAULT_COLLATION_OID,
- cst->constvalue,
- item->values[idx]));
-
- break;
-
- case F_SCALARLTSEL: /* column < constant */
- case F_SCALARLESEL: /* column <= constant */
- case F_SCALARGTSEL: /* column > constant */
- case F_SCALARGESEL: /* column >= constant */
-
- /*
- * First check whether the constant is below the
- * lower boundary (in that case we can skip the
- * bucket, because there's no overlap).
- */
- if (isgt)
- match = DatumGetBool(FunctionCall2Coll(&opproc,
- DEFAULT_COLLATION_OID,
- cst->constvalue,
- item->values[idx]));
- else
- match = DatumGetBool(FunctionCall2Coll(&opproc,
- DEFAULT_COLLATION_OID,
- item->values[idx],
- cst->constvalue));
-
- break;
- }
+ /*
+ * First check whether the constant is below the lower
+ * boundary (in that case we can skip the bucket, because
+ * there's no overlap).
+ */
+ if (varonleft)
+ match = DatumGetBool(FunctionCall2Coll(&opproc,
+ DEFAULT_COLLATION_OID,
+ item->values[idx],
+ cst->constvalue));
+ else
+ match = DatumGetBool(FunctionCall2Coll(&opproc,
+ DEFAULT_COLLATION_OID,
+ cst->constvalue,
+ item->values[idx]));
/* update the match bitmap with the result */
matches[i] = RESULT_MERGE(matches[i], is_or, match);