Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rEALH-004QEP-3D for pgsql-bugs@arkaria.postgresql.org; Fri, 15 Dec 2023 15:43:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rEALF-003Iqz-Gs for pgsql-bugs@arkaria.postgresql.org; Fri, 15 Dec 2023 15:43:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rEALF-003Iqq-7u for pgsql-bugs@lists.postgresql.org; Fri, 15 Dec 2023 15:43:09 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rEALC-00C9Vo-Kj for pgsql-bugs@lists.postgresql.org; Fri, 15 Dec 2023 15:43:08 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 3BFFh3hl2993261; Fri, 15 Dec 2023 10:43:03 -0500 From: Tom Lane To: Richard Guo cc: rekgrpth@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18247: Integer overflow leads to negative width In-reply-to: References: <18247-11ac477f02954422@postgresql.org> <2781181.1702565025@sss.pgh.pa.us> Comments: In-reply-to Richard Guo message dated "Fri, 15 Dec 2023 10:28:10 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <2993259.1702654983.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Fri, 15 Dec 2023 10:43:03 -0500 Message-ID: <2993260.1702654983@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Richard Guo writes: > On Thu, Dec 14, 2023 at 10:43 PM Tom Lane wrote: >> Probably better to clamp tuple width estimates to MaxAllocSize. >> Anything larger would not correspond to reality anyhow. > Fair point. How about the attached patch? We'd need to hit at least build_joinrel_tlist too. Not sure offhand whether this is enough to cover upper-relation tlists. As far as the specifics go, is it enough to clamp once? I think we'd either have to clamp after each addition, or change the running-sum variables to double and clamp just before storing into the final width field. The latter seems probably less error-prone in the long run. Also, given that we'll need at least three copies of the clamp rule, I wonder if it's worth inventing a function comparable to clamp_row_est(). regards, tom lane