diff options
author | Tomas Vondra <tomas.vondra@postgresql.org> | 2022-12-30 19:44:48 +0100 |
---|---|---|
committer | Tomas Vondra <tomas.vondra@postgresql.org> | 2022-12-30 20:49:11 +0100 |
commit | c4f64cfab9fefd7974c9097be72691c33c7afcea (patch) | |
tree | f21ea11c736e2528fae6180fa12e3ab017f2ea84 | |
parent | d8209d09170f0029663da4335979b4f49d48b6be (diff) | |
download | postgresql-c4f64cfab9fefd7974c9097be72691c33c7afcea.tar.gz postgresql-c4f64cfab9fefd7974c9097be72691c33c7afcea.zip |
Fix assert in BRIN build_distances
When brin_minmax_multi_union merges summaries, we may end up with just a
single range after merge_overlapping_ranges. The summaries may contain
just one range each, and they may overlap (or be exactly the same).
With a single range there's no distance to calculate, but we happen to
call build_distances anyway - which is fine, we don't calculate the
distance in this case, except that with asserts this failed due to a
check there are at least two ranges.
The assert is unnecessarily strict, so relax it a bit and bail out if
there's just a single range. The relaxed assert would be enough, but
this way we don't allocate unnecessary memory for distance.
Backpatch to 14, where minmax-multi opclasses were introduced.
Reported-by: Jaime Casanova
Backpatch-through: 14
Discussion: https://postgr.es/m/YzVA55qS0hgz8P3r@ahch-to
-rw-r--r-- | src/backend/access/brin/brin_minmax_multi.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/backend/access/brin/brin_minmax_multi.c b/src/backend/access/brin/brin_minmax_multi.c index baf592b0514..ef8370c1215 100644 --- a/src/backend/access/brin/brin_minmax_multi.c +++ b/src/backend/access/brin/brin_minmax_multi.c @@ -1335,7 +1335,11 @@ build_distances(FmgrInfo *distanceFn, Oid colloid, int ndistances; DistanceValue *distances; - Assert(neranges >= 2); + Assert(neranges > 0); + + /* If there's only a single range, there's no distance to calculate. */ + if (neranges == 1) + return NULL; ndistances = (neranges - 1); distances = (DistanceValue *) palloc0(sizeof(DistanceValue) * ndistances); |