Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nqzDL-0003Y3-JO for pgsql-bugs@arkaria.postgresql.org; Tue, 17 May 2022 15:34:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nqzDK-0004SX-B8 for pgsql-bugs@arkaria.postgresql.org; Tue, 17 May 2022 15:34:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nqzDK-0004SN-2u for pgsql-bugs@lists.postgresql.org; Tue, 17 May 2022 15:34:22 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nqzDI-0000uh-1U for pgsql-bugs@lists.postgresql.org; Tue, 17 May 2022 15:34:21 +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 24HFYHtc1584432; Tue, 17 May 2022 11:34:18 -0400 From: Tom Lane To: Andrey Lepikhov cc: pgsql-bugs@lists.postgresql.org Subject: Re: Negative value of numGroups In-reply-to: References: Comments: In-reply-to Andrey Lepikhov message dated "Tue, 17 May 2022 17:59:23 +0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1584430.1652801657.1@sss.pgh.pa.us> Date: Tue, 17 May 2022 11:34:17 -0400 Message-ID: <1584431.1652801657@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andrey Lepikhov writes: > On 13/5/2022 11:56, Andrey Lepikhov wrote: >> (long) Min(numGroups, (double) LONG_MAX); >> >> can return negative value, if numGroups > LONG_MAX. I see your point, but I don't think that repeating the same finicky and undocumented coding pattern in multiple places is a future-proof fix. I'm inclined to think we should invent a function along the lines of "long clamp_double_to_long(double x)". Given where it's used, maybe putting it beside clamp_row_est() would be good. regards, tom lane