Commit b9243cad authored by Tom Lane's avatar Tom Lane

Partially undo commit 94da73281.

On closer inspection, mcv.c isn't as broken for ScalarArrayOpExpr
as I thought.  The Var-on-right issue is real enough, but actually
it does cope fine with a NULL array constant --- I was misled by
an XXX comment suggesting it didn't.  Undo that part of the code
change, and replace the XXX comment with something less misleading.
parent 3fe2fc6b
...@@ -1452,7 +1452,6 @@ statext_is_compatible_clause_internal(PlannerInfo *root, Node *clause, ...@@ -1452,7 +1452,6 @@ statext_is_compatible_clause_internal(PlannerInfo *root, Node *clause,
RangeTblEntry *rte = root->simple_rte_array[relid]; RangeTblEntry *rte = root->simple_rte_array[relid];
ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) clause; ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) clause;
Node *clause_expr; Node *clause_expr;
Const *cst;
bool expronleft; bool expronleft;
/* Only expressions with two arguments are considered compatible. */ /* Only expressions with two arguments are considered compatible. */
...@@ -1460,11 +1459,11 @@ statext_is_compatible_clause_internal(PlannerInfo *root, Node *clause, ...@@ -1460,11 +1459,11 @@ statext_is_compatible_clause_internal(PlannerInfo *root, Node *clause,
return false; return false;
/* Check if the expression has the right shape (one Var, one Const) */ /* Check if the expression has the right shape (one Var, one Const) */
if (!examine_opclause_args(expr->args, &clause_expr, &cst, &expronleft)) if (!examine_opclause_args(expr->args, &clause_expr, NULL, &expronleft))
return false; return false;
/* We only support Var on left and non-null array constants */ /* We only support Var on left, Const on right */
if (!expronleft || cst->constisnull) if (!expronleft)
return false; return false;
/* /*
......
...@@ -1740,17 +1740,24 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses, ...@@ -1740,17 +1740,24 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
if (!examine_opclause_args(expr->args, &clause_expr, &cst, &expronleft)) if (!examine_opclause_args(expr->args, &clause_expr, &cst, &expronleft))
elog(ERROR, "incompatible clause"); elog(ERROR, "incompatible clause");
/* We expect Var on left and non-null constant on right */ /* We expect Var on left */
if (!expronleft || cst->constisnull) if (!expronleft)
elog(ERROR, "incompatible clause"); elog(ERROR, "incompatible clause");
arrayval = DatumGetArrayTypeP(cst->constvalue); /*
get_typlenbyvalalign(ARR_ELEMTYPE(arrayval), * Deconstruct the array constant, unless it's NULL (we'll cover
&elmlen, &elmbyval, &elmalign); * that case below)
deconstruct_array(arrayval, */
ARR_ELEMTYPE(arrayval), if (!cst->constisnull)
elmlen, elmbyval, elmalign, {
&elem_values, &elem_nulls, &num_elems); arrayval = DatumGetArrayTypeP(cst->constvalue);
get_typlenbyvalalign(ARR_ELEMTYPE(arrayval),
&elmlen, &elmbyval, &elmalign);
deconstruct_array(arrayval,
ARR_ELEMTYPE(arrayval),
elmlen, elmbyval, elmalign,
&elem_values, &elem_nulls, &num_elems);
}
/* match the attribute/expression to a dimension of the statistic */ /* match the attribute/expression to a dimension of the statistic */
idx = mcv_match_expression(clause_expr, keys, exprs, &collid); idx = mcv_match_expression(clause_expr, keys, exprs, &collid);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment