From 883fdf2053b45be6b4d6ce3f0d7ff8331bc09217 Mon Sep 17 00:00:00 2001 From: Richard Guo Date: Fri, 15 Dec 2023 10:22:10 +0800 Subject: [PATCH v1] Clamp tuple_width to MaxAllocSize --- src/backend/optimizer/path/costsize.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c index d6ceafd51c..a707f90184 100644 --- a/src/backend/optimizer/path/costsize.c +++ b/src/backend/optimizer/path/costsize.c @@ -6239,6 +6239,14 @@ set_rel_width(PlannerInfo *root, RelOptInfo *rel) tuple_width += wholerow_width; } + /* + * Clamp tuple_width to MaxAllocSize in case it exceeds the limit or + * overflows. Anything larger than MaxAllocSize would not align with + * reality. + */ + if (tuple_width > (int) MaxAllocSize || tuple_width < 0) + tuple_width = (int) MaxAllocSize; + Assert(tuple_width >= 0); rel->reltarget->width = tuple_width; } @@ -6282,6 +6290,14 @@ set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target) } } + /* + * Clamp tuple_width to MaxAllocSize in case it exceeds the limit or + * overflows. Anything larger than MaxAllocSize would not align with + * reality. + */ + if (tuple_width > (int) MaxAllocSize || tuple_width < 0) + tuple_width = (int) MaxAllocSize; + Assert(tuple_width >= 0); target->width = tuple_width; -- 2.31.0