Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 476f9d5

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 c102d11 commit 476f9d5

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
@@ -1051,19 +1051,18 @@ statext_is_compatible_clause_internal(PlannerInfo *root, Node *clause,
10511051
RangeTblEntry *rte = root->simple_rte_array[relid];
10521052
ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) clause;
10531053
Var *var;
1054-
Const *cst;
10551054
bool expronleft;
10561055

10571056
/* Only expressions with two arguments are considered compatible. */
10581057
if (list_length(expr->args) != 2)
10591058
return false;
10601059

10611060
/* Check if the expression has the right shape (one Var, one Const) */
1062-
if (!examine_clause_args(expr->args, &var, &cst, &expronleft))
1061+
if (!examine_clause_args(expr->args, &var, NULL, &expronleft))
10631062
return false;
10641063

1065-
/* We only support Var on left and non-null array constants */
1066-
if (!expronleft || cst->constisnull)
1064+
/* We only support Var on left, Const on right */
1065+
if (!expronleft)
10671066
return false;
10681067

10691068
/*

src/backend/statistics/mcv.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,17 +1679,24 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
16791679
Datum *elem_values;
16801680
bool *elem_nulls;
16811681

1682-
/* We expect Var on left and non-null constant on right */
1683-
if (!varonleft || cst->constisnull)
1682+
/* We expect Var on left */
1683+
if (!varonleft)
16841684
elog(ERROR, "incompatible clause");
16851685

1686-
arrayval = DatumGetArrayTypeP(cst->constvalue);
1687-
get_typlenbyvalalign(ARR_ELEMTYPE(arrayval),
1688-
&elmlen, &elmbyval, &elmalign);
1689-
deconstruct_array(arrayval,
1690-
ARR_ELEMTYPE(arrayval),
1691-
elmlen, elmbyval, elmalign,
1692-
&elem_values, &elem_nulls, &num_elems);
1686+
/*
1687+
* Deconstruct the array constant, unless it's NULL (we'll
1688+
* cover that case below)
1689+
*/
1690+
if (!cst->constisnull)
1691+
{
1692+
arrayval = DatumGetArrayTypeP(cst->constvalue);
1693+
get_typlenbyvalalign(ARR_ELEMTYPE(arrayval),
1694+
&elmlen, &elmbyval, &elmalign);
1695+
deconstruct_array(arrayval,
1696+
ARR_ELEMTYPE(arrayval),
1697+
elmlen, elmbyval, elmalign,
1698+
&elem_values, &elem_nulls, &num_elems);
1699+
}
16931700

16941701
/* match the attribute to a dimension of the statistic */
16951702
idx = bms_member_index(keys, var->varattno);

0 commit comments

Comments
 (0)