Re: BUG #19350: Short circuit optimization missed when runningsqlscriptes in JDBC
Dave Cramer <davecramer@postgres.rocks>
From: Dave Cramer <davecramer@postgres.rocks>
To: Greg Sabino Mullane <htamfids@gmail.com>
Cc: ZhangChi <798604270@qq.com>,
"David G. Johnston" <david.g.johnston@gmail.com>, "pgsql-bugs@lists.postgresql.org" <pgsql-bugs@lists.postgresql.org>
Date: 2025-12-17T15:39:21Z
Lists: pgsql-bugs
Dave Cramer
www.postgres.rocks
On Wed, 17 Dec 2025 at 10:33, Dave Cramer <davecramer@postgres.rocks> wrote:
>
>
>
> On Wed, 17 Dec 2025 at 09:51, Greg Sabino Mullane <htamfids@gmail.com>
> wrote:
>
>> Possibly because JDBC does everything using the V3 protocol whereas psql
>>> does not. psql uses simple query.
>>
>>
>> Maybe JDBC is doing something else? I cannot duplicate the error when
>> doing it via the protocol (DBD::Pg) or via psql. Even forcing
>> non-server-side prepares (i.e. making the driver replace the vars itself)
>> fails to fail.
>>
>
> Logs from the server. I can replicate it.
>
> 2025-12-17 10:31:07.860 EST [27985] LOG: duration: 5.875 ms statement:
> SET application_name = 'PostgreSQL JDBC Driver'
> 2025-12-17 10:31:07.880 EST [27985] LOG: duration: 0.945 ms parse
> <unnamed>: SET plan_cache_mode = force_generic_plan
> 2025-12-17 10:31:07.880 EST [27985] LOG: duration: 0.057 ms bind
> <unnamed>: SET plan_cache_mode = force_generic_plan
> 2025-12-17 10:31:07.880 EST [27985] LOG: duration: 0.019 ms execute
> <unnamed>: SET plan_cache_mode = force_generic_plan
> 2025-12-17 10:31:07.885 EST [27985] LOG: duration: 3.442 ms parse
> <unnamed>: CREATE TABLE t0(c0 int4range)
> 2025-12-17 10:31:07.885 EST [27985] LOG: duration: 0.023 ms bind
> <unnamed>: CREATE TABLE t0(c0 int4range)
> 2025-12-17 10:31:07.939 EST [27985] LOG: duration: 54.701 ms execute
> <unnamed>: CREATE TABLE t0(c0 int4range)
> 2025-12-17 10:31:07.944 EST [27985] LOG: duration: 2.667 ms parse
> <unnamed>: INSERT INTO t0(c0) VALUES('[-1920846305,-1018839689)'::int4range)
> 2025-12-17 10:31:07.945 EST [27985] LOG: duration: 0.695 ms bind
> <unnamed>: INSERT INTO t0(c0) VALUES('[-1920846305,-1018839689)'::int4range)
> 2025-12-17 10:31:07.946 EST [27985] LOG: duration: 1.593 ms execute
> <unnamed>: INSERT INTO t0(c0) VALUES('[-1920846305,-1018839689)'::int4range)
> 2025-12-17 10:31:07.947 EST [27985] LOG: duration: 0.311 ms parse
> <unnamed>: PREPARE prepare_query (int8, int8) AS SELECT
> ((((((upper(t0.c0))))/($1)))*(($2::int8))) FROM ONLY t0
> 2025-12-17 10:31:07.947 EST [27985] LOG: duration: 0.006 ms bind
> <unnamed>: PREPARE prepare_query (int8, int8) AS SELECT
> ((((((upper(t0.c0))))/($1)))*(($2::int8))) FROM ONLY t0
> 2025-12-17 10:31:07.952 EST [27985] LOG: duration: 4.653 ms execute
> <unnamed>: PREPARE prepare_query (int8, int8) AS SELECT
> ((((((upper(t0.c0))))/($1)))*(($2::int8))) FROM ONLY t0
> 2025-12-17 10:31:07.953 EST [27985] LOG: duration: 0.020 ms parse
> <unnamed>: EXECUTE prepare_query(0, NULL)
> 2025-12-17 10:31:07.953 EST [27985] LOG: duration: 0.005 ms bind
> <unnamed>: EXECUTE prepare_query(0, NULL)
> 2025-12-17 10:31:07.954 EST [27985] ERROR: division by zero
>
>
I also get the division by zero error with psql
bin/psql -h localhost -U test -f ~/projects/jdbc/testjdbc/test.sql
SET
CREATE TABLE
INSERT 0 1
PREPARE
psql:/Users/davecra/projects/jdbc/testjdbc/test.sql:5: ERROR: division by
zero
?column?
----------
(1 row)
> Dave Cramer
> www.postgres.rocks
>
>