aboutsummaryrefslogtreecommitdiff
path: root/src/backend/statistics/mcv.c
diff options
context:
space:
mode:
authorTomas Vondra <tomas.vondra@postgresql.org>2021-04-06 16:12:37 +0200
committerTomas Vondra <tomas.vondra@postgresql.org>2021-04-06 16:56:06 +0200
commit518442c7f334f3b05ea28b7ef50f1b551cfcc23e (patch)
tree5a24b7e2dea054ed0fb094afbb8dcbd7fa441d70 /src/backend/statistics/mcv.c
parent7ab96cf6b312cfcd79cdc1a69c6bdb75de0ed30f (diff)
downloadpostgresql-518442c7f334f3b05ea28b7ef50f1b551cfcc23e.tar.gz
postgresql-518442c7f334f3b05ea28b7ef50f1b551cfcc23e.zip
Fix handling of clauses incompatible with extended statistics
Handling of incompatible clauses while applying extended statistics was a bit confused - while handling a mix of compatible and incompatible clauses it sometimes incorrectly treated the incompatible clauses as compatible, resulting in a crash. Fixed by reworking the code applying the selected statistics object to make it easier to understand, and adding a proper compatibility check. Reported-by: David Rowley Discussion: https://postgr.es/m/CAApHDvpYT10-nkSp8xXe-nbO3jmoaRyRFHbzh-RWMfAJynqgpQ%40mail.gmail.com
Diffstat (limited to 'src/backend/statistics/mcv.c')
-rw-r--r--src/backend/statistics/mcv.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/backend/statistics/mcv.c b/src/backend/statistics/mcv.c
index 2a00fb48483..9ab3e81a91d 100644
--- a/src/backend/statistics/mcv.c
+++ b/src/backend/statistics/mcv.c
@@ -1575,6 +1575,8 @@ mcv_match_expression(Node *expr, Bitmapset *keys, List *exprs, Oid *collid)
(idx <= bms_num_members(keys) + list_length(exprs)));
}
+ Assert((idx >= 0) && (idx < bms_num_members(keys) + list_length(exprs)));
+
return idx;
}
@@ -1654,6 +1656,8 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
/* match the attribute/expression to a dimension of the statistic */
idx = mcv_match_expression(clause_expr, keys, exprs, &collid);
+ Assert((idx >= 0) && (idx < bms_num_members(keys) + list_length(exprs)));
+
/*
* Walk through the MCV items and evaluate the current clause. We
* can skip items that were already ruled out, and terminate if