From 42276976a1437c88fb6176fc1a876fd79a139eb0 Mon Sep 17 00:00:00 2001 From: Tomas Vondra Date: Sat, 13 Jul 2019 00:12:16 +0200 Subject: Fix handling of opclauses in extended statistics We expect opclauses to have exactly one Var and one Const, but the code was checking the Const by calling is_pseudo_constant_clause() which is incorrect - we need a proper constant. Fixed by using plain IsA(x,Const) to check type of the node. We need to do these checks in two places, so move it into a separate function that can be called in both places. Reported by Andreas Seltenreich, based on crash reported by sqlsmith. Backpatch to v12, where this code was introduced. Discussion: https://postgr.es/m/8736jdhbhc.fsf%40ansel.ydns.eu Backpatch-to: 12 --- src/include/statistics/extended_stats_internal.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/include/statistics/extended_stats_internal.h') diff --git a/src/include/statistics/extended_stats_internal.h b/src/include/statistics/extended_stats_internal.h index 8fc541993fa..c7f01d4edc7 100644 --- a/src/include/statistics/extended_stats_internal.h +++ b/src/include/statistics/extended_stats_internal.h @@ -97,6 +97,8 @@ extern SortItem *build_sorted_items(int numrows, int *nitems, HeapTuple *rows, TupleDesc tdesc, MultiSortSupport mss, int numattrs, AttrNumber *attnums); +extern bool examine_opclause_expression(OpExpr *expr, Var **varp, + Const **cstp, bool *isgtp); extern Selectivity mcv_clauselist_selectivity(PlannerInfo *root, StatisticExtInfo *stat, -- cgit v1.2.3