Skip to content

Commit 0d3b0d8

Browse files
tglsfdcreshke
authored andcommitted
Partially undo commit 94da732.
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.
1 parent b21886b commit 0d3b0d8

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

src/backend/statistics/extended_stats.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,19 +1454,18 @@ statext_is_compatible_clause_internal(PlannerInfo *root, Node *clause,
14541454
RangeTblEntry *rte = root->simple_rte_array[relid];
14551455
ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) clause;
14561456
Node *clause_expr;
1457-
Const *cst;
14581457
bool expronleft;
14591458

14601459
/* Only expressions with two arguments are considered compatible. */
14611460
if (list_length(expr->args) != 2)
14621461
return false;
14631462

14641463
/* Check if the expression has the right shape (one Var, one Const) */
1465-
if (!examine_opclause_args(expr->args, &clause_expr, &cst, &expronleft))
1464+
if (!examine_opclause_args(expr->args, &clause_expr, NULL, &expronleft))
14661465
return false;
14671466

1468-
/* We only support Var on left and non-null array constants */
1469-
if (!expronleft || cst->constisnull)
1467+
/* We only support Var on left, Const on right */
1468+
if (!expronleft)
14701469
return false;
14711470

14721471
/*

src/backend/statistics/mcv.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,17 +1740,24 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
17401740
if (!examine_opclause_args(expr->args, &clause_expr, &cst, &expronleft))
17411741
elog(ERROR, "incompatible clause");
17421742

1743-
/* We expect Var on left and non-null constant on right */
1744-
if (!expronleft || cst->constisnull)
1743+
/* We expect Var on left */
1744+
if (!expronleft)
17451745
elog(ERROR, "incompatible clause");
17461746

1747-
arrayval = DatumGetArrayTypeP(cst->constvalue);
1748-
get_typlenbyvalalign(ARR_ELEMTYPE(arrayval),
1749-
&elmlen, &elmbyval, &elmalign);
1750-
deconstruct_array(arrayval,
1751-
ARR_ELEMTYPE(arrayval),
1752-
elmlen, elmbyval, elmalign,
1753-
&elem_values, &elem_nulls, &num_elems);
1747+
/*
1748+
* Deconstruct the array constant, unless it's NULL (we'll cover
1749+
* that case below)
1750+
*/
1751+
if (!cst->constisnull)
1752+
{
1753+
arrayval = DatumGetArrayTypeP(cst->constvalue);
1754+
get_typlenbyvalalign(ARR_ELEMTYPE(arrayval),
1755+
&elmlen, &elmbyval, &elmalign);
1756+
deconstruct_array(arrayval,
1757+
ARR_ELEMTYPE(arrayval),
1758+
elmlen, elmbyval, elmalign,
1759+
&elem_values, &elem_nulls, &num_elems);
1760+
}
17541761

17551762
/* match the attribute/expression to a dimension of the statistic */
17561763
idx = mcv_match_expression(clause_expr, keys, exprs, &collid);

0 commit comments

Comments
 (0)