Skip to content

Commit 4c81a50

Browse files
committed
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 e33ae53 commit 4c81a50

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/backend/statistics/extended_stats.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,19 +1452,18 @@ statext_is_compatible_clause_internal(PlannerInfo *root, Node *clause,
14521452
RangeTblEntry *rte = root->simple_rte_array[relid];
14531453
ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) clause;
14541454
Node *clause_expr;
1455-
Const *cst;
14561455
bool expronleft;
14571456

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

14621461
/* Check if the expression has the right shape (one Var, one Const) */
1463-
if (!examine_opclause_args(expr->args, &clause_expr, &cst, &expronleft))
1462+
if (!examine_opclause_args(expr->args, &clause_expr, NULL, &expronleft))
14641463
return false;
14651464

1466-
/* We only support Var on left and non-null array constants */
1467-
if (!expronleft || cst->constisnull)
1465+
/* We only support Var on left, Const on right */
1466+
if (!expronleft)
14681467
return false;
14691468

14701469
/*

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)