summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane2022-08-05 19:57:46 +0000
committerTom Lane2022-08-05 19:57:46 +0000
commit476f9d533084f2ad3f625b5092021b6c23c8e196 (patch)
treed10064629c096e46244bab152e6fdb3ab2a49244 /src
parentc102d1106732189de2bfeb93c11b358f9c6b4e1f (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/backend/statistics/extended_stats.c7
-rw-r--r--src/backend/statistics/mcv.c25
2 files changed, 19 insertions, 13 deletions
diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c
index 3c94e3c7626..18f6e6dd6d9 100644
--- a/src/backend/statistics/extended_stats.c
+++ b/src/backend/statistics/extended_stats.c
@@ -1051,7 +1051,6 @@ statext_is_compatible_clause_internal(PlannerInfo *root, Node *clause,
RangeTblEntry *rte = root->simple_rte_array[relid];
ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) clause;
Var *var;
- Const *cst;
bool expronleft;
/* Only expressions with two arguments are considered compatible. */
@@ -1059,11 +1058,11 @@ statext_is_compatible_clause_internal(PlannerInfo *root, Node *clause,
return false;
/* Check if the expression has the right shape (one Var, one Const) */
- if (!examine_clause_args(expr->args, &var, &cst, &expronleft))
+ if (!examine_clause_args(expr->args, &var, NULL, &expronleft))
return false;
- /* We only support Var on left and non-null array constants */
- if (!expronleft || cst->constisnull)
+ /* We only support Var on left, Const on right */
+ if (!expronleft)
return false;
/*
diff --git a/src/backend/statistics/mcv.c b/src/backend/statistics/mcv.c
index 9afd7e551fa..2b3080ffe4c 100644
--- a/src/backend/statistics/mcv.c
+++ b/src/backend/statistics/mcv.c
@@ -1679,17 +1679,24 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
Datum *elem_values;
bool *elem_nulls;
- /* We expect Var on left and non-null constant on right */
- if (!varonleft || cst->constisnull)
+ /* We expect Var on left */
+ if (!varonleft)
elog(ERROR, "incompatible clause");
- 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);
+ /*
+ * Deconstruct the array constant, unless it's NULL (we'll
+ * cover that case below)
+ */
+ if (!cst->constisnull)
+ {
+ 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 to a dimension of the statistic */
idx = bms_member_index(keys, var->varattno);