pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexander Lakhin <exclusion@gmail.com>
To: Richard Guo <guofenglinux@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: rekgrpth@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18247: Integer overflow leads to negative width
Date: Fri, 15 Dec 2023 09:00:00 +0300
Message-ID: <f5e15fe1-202d-1936-f47c-f0c69a936b72@gmail.com> (raw)
In-Reply-To: <CAMbWs4_8+mtt5C8EXmfHa_Hs-OW6EhEz_XjhzBk8miwg2h65CQ@mail.gmail.com>
References: <18247-11ac477f02954422@postgresql.org>
	<CAMbWs48nZf9XgAVpXbOnwGWWLnmoOZb51wnhkNW5xfz_PyOyCw@mail.gmail.com>
	<2781181.1702565025@sss.pgh.pa.us>
	<CAMbWs4_8+mtt5C8EXmfHa_Hs-OW6EhEz_XjhzBk8miwg2h65CQ@mail.gmail.com>

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

view thread (21+ messages)  latest in thread

Message-ID: <f5e15fe1-202d-1936-f47c-f0c69a936b72@gmail.com>
Permalink:  ../f5e15fe1-202d-1936-f47c-f0c69a936b72@gmail.com/
Also on:    postgresql.org/message-id/f5e15fe1-202d-1936-f47c-f0c69a936b72@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: exclusion@gmail.com, guofenglinux@gmail.com, tgl@sss.pgh.pa.us, rekgrpth@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #18247: Integer overflow leads to negative width
  In-Reply-To: <f5e15fe1-202d-1936-f47c-f0c69a936b72@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox