Fix bug in brin_minmax_multi_union
authorTomas Vondra <[email protected]>
Sun, 4 Apr 2021 17:36:10 +0000 (19:36 +0200)
committerTomas Vondra <[email protected]>
Sun, 4 Apr 2021 17:36:12 +0000 (19:36 +0200)
When calling sort_expanded_ranges() we need to remember the return
value, because the function sorts and also deduplicates the ranges. So
the number of ranges may decrease. brin_minmax_multi_union failed to do
that, which resulted in crashes due to bogus ranges (equal minval/maxval
but not marked as compacted).

Reported-by: Jaime Casanova
Discussion: https://postgr.es/m/20210404052550.GA4376%40ahch-to

src/backend/access/brin/brin_minmax_multi.c

index 2f4e92695c79061039855fe791584991cd329dc3..4163abef3f03bf6abc08a0ac093dd231d9372cb0 100644 (file)
@@ -2794,7 +2794,7 @@ brin_minmax_multi_union(PG_FUNCTION_ARGS)
                                               BTLessStrategyNumber);
 
    /* sort the expanded ranges */
-   sort_expanded_ranges(cmpFn, colloid, eranges, neranges);
+   neranges = sort_expanded_ranges(cmpFn, colloid, eranges, neranges);
 
    /*
     * We've loaded two different lists of expanded ranges, so some of them