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 1rE1Hu-003uPA-RI for pgsql-bugs@arkaria.postgresql.org; Fri, 15 Dec 2023 06:03:06 +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 1rE1Ht-00G45v-HX for pgsql-bugs@arkaria.postgresql.org; Fri, 15 Dec 2023 06:03:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rE1F5-00G1ol-Pt for pgsql-bugs@lists.postgresql.org; Fri, 15 Dec 2023 06:00:11 +0000 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rE1Ez-00ATa0-6Z for pgsql-bugs@lists.postgresql.org; Fri, 15 Dec 2023 06:00:10 +0000 Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-50e1b82f949so270811e87.2 for ; Thu, 14 Dec 2023 22:00:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702620003; x=1703224803; darn=lists.postgresql.org; h=in-reply-to:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=IhUV8KK2VcvGdTq3d3aeh8GX77LsyIIIp6du/6fityA=; b=UaKRyxj/rOooq3jm3MBKpQYAL1pcSowf1/f2LkJIvnUa5HCmY78dL16YvqkNBvsoRC iEnQz+8O5kUQZqzRtf2wt9NUNYk3+loocTVtmp3Gv4vc2Z0GsNTYbiYI1Adh4hlBajV2 WbH9qhxiMkTcKKe6HxKzDQlGnKaqsHlom9+KeZXbn51Ms4EiZOEU7JJJIxReoB6g9mRX gSOpWM8IkulMzd8MTTnL1MyCDCuA88jYstBxGYyH0IO7yzVH1COWGu3F3/Uew40SVJ0P D+PgbTtykvL5ryYj2gH2lUAkq/qh6UZ0vCx0Tm2rZG1fxuXAVz5QfWlzfj5YS0lU/uuN cNtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702620003; x=1703224803; h=in-reply-to:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=IhUV8KK2VcvGdTq3d3aeh8GX77LsyIIIp6du/6fityA=; b=FZM308ojZYrVCbjZA9hDSBC2rsp/sCsTN/1EdEGMO9iEPveEkd9N3dX+VW8og2H545 xWHpzLWIe+n01xSXsw9I4oCMYjxRCqXt7kFFqalL3JhVTINLm9cZcgwu+VpXGj1KVdeW xdQ1lXvn6sDJtyo28U9kOufmapD444ldxNMh5t1zP4wbf+2yPpPjYadan0cHrbb3P59n uzUFbbtIgx3Wk/EAxBH9HF3tP1cKgd+gO4uGNKdXdLHlJi47TIiEKBzVizVdQERUhpVC SGK8XrpzjDscTbMhpVun5DH4veZiOMQLTxwB/sUhLM2vrOesgZEhtD+scRASc9dpFhWa OorA== X-Gm-Message-State: AOJu0YyBdVGfLUWzlmgqcbGry0tQCiWvOcLTIzBviigICzCcYbRP3BCo VjfRjdqpriWNUS+LO1IWiAOlzRsU5N+Ixw== X-Google-Smtp-Source: AGHT+IEJs2uh6a6fdIjaZWPNcIPc7PG/H9LdnH/a33b6l3QjynbcPa963FWN4Rucu1L0G+dmhr3YPg== X-Received: by 2002:a05:6512:55c:b0:50e:1ea8:f3ec with SMTP id h28-20020a056512055c00b0050e1ea8f3ecmr115308lfl.131.1702620003018; Thu, 14 Dec 2023 22:00:03 -0800 (PST) Received: from [1.0.0.7] ([178.155.26.88]) by smtp.gmail.com with ESMTPSA id w2-20020a0565120b0200b0050d14878d00sm1988279lfu.92.2023.12.14.22.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Dec 2023 22:00:02 -0800 (PST) Content-Type: multipart/alternative; boundary="------------ZJgIoj8d2N2WXWsT00KatzUl" Message-ID: Date: Fri, 15 Dec 2023 09:00:00 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: BUG #18247: Integer overflow leads to negative width Content-Language: en-US To: Richard Guo , Tom Lane Cc: rekgrpth@gmail.com, pgsql-bugs@lists.postgresql.org References: <18247-11ac477f02954422@postgresql.org> <2781181.1702565025@sss.pgh.pa.us> From: Alexander Lakhin In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------ZJgIoj8d2N2WXWsT00KatzUl Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hello Richard, 15.12.2023 05:28, Richard Guo wrote: > > Fair point.  How about the attached patch? Your patch looks good to me, but maybe you would find it suitable to fix in passing one more integer overflow in costsize.c? Concretely, the query: CREATE TABLE t(id int PRIMARY KEY, i int); EXPLAIN (VERBOSE) UPDATE t SET i = ni FROM (SELECT g id, 1 ni FROM generate_series(1, 2147483648) g) s WHERE t.id = s.id; when executed with ubsan-enabled build, gives: costsize.c:1017:12: runtime error: 2.14748e+09 is outside the range of representable values of type 'int'     #0 0x5603325818e0 in cost_bitmap_heap_scan .../src/backend/optimizer/path/costsize.c:1017:12     #1 0x5603326cc519 in create_bitmap_heap_path .../src/backend/optimizer/util/pathnode.c:1065:2 ... Without ubsan enabled, the query: EXPLAIN (VERBOSE) UPDATE t SET i = ni FROM (SELECT g id, 1 ni FROM generate_series(1, 2147483648) g) s WHERE t.id = s.id; executed visually similar to: EXPLAIN (VERBOSE, ANALYZE) UPDATE t SET i = ni FROM (SELECT g id, 1 ni FROM generate_series(1, 2147483647) g) s WHERE t.id = s.id; but quite longer:  Update on public.t  (cost=60.85..27122613.04 rows=0 width=0) (actual time=225204.159..225204.162 rows=0 loops=1) vs  Update on public.t  (cost=60.85..27122613.03 rows=0 width=0) (actual time=153015.851..153015.852 rows=0 loops=1) Best regards, Alexander --------------ZJgIoj8d2N2WXWsT00KatzUl Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
Hello Richard,

15.12.2023 05:28, Richard Guo wrote:

Fair point.  How about the attached patch?

Your patch looks good to me, but maybe you would find it suitable to fix in
passing one more integer overflow in costsize.c?

Concretely, the query:
CREATE TABLE t(id int PRIMARY KEY, i int);
EXPLAIN (VERBOSE)
UPDATE t SET i = ni FROM (SELECT g id, 1 ni FROM generate_series(1, 2147483648) g) s WHERE t.id = s.id;

when executed with ubsan-enabled build, gives:
costsize.c:1017:12: runtime error: 2.14748e+09 is outside the range of representable values of type 'int'
    #0 0x5603325818e0 in cost_bitmap_heap_scan .../src/backend/optimizer/path/costsize.c:1017:12
    #1 0x5603326cc519 in create_bitmap_heap_path .../src/backend/optimizer/util/pathnode.c:1065:2
...

Without ubsan enabled, the query:
EXPLAIN (VERBOSE)
UPDATE t SET i = ni FROM (SELECT g id, 1 ni FROM generate_series(1, 2147483648) g) s WHERE t.id = s.id;

executed visually similar to:
EXPLAIN (VERBOSE, ANALYZE)
UPDATE t SET i = ni FROM (SELECT g id, 1 ni FROM generate_series(1, 2147483647) g) s WHERE t.id = s.id;

but quite longer:
 Update on public.t  (cost=60.85..27122613.04 rows=0 width=0) (actual time=225204.159..225204.162 rows=0 loops=1)
vs
 Update on public.t  (cost=60.85..27122613.03 rows=0 width=0) (actual time=153015.851..153015.852 rows=0 loops=1)

Best regards,
Alexander
--------------ZJgIoj8d2N2WXWsT00KatzUl--