Re: BUG #19350: Short circuit optimization missed when runningsqlscriptes in JDBC

From: Dave Cramer <davecramer(at)postgres(dot)rocks>
To: Greg Sabino Mullane <htamfids(at)gmail(dot)com>
Cc: ZhangChi <798604270(at)qq(dot)com>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #19350: Short circuit optimization missed when runningsqlscriptes in JDBC
Date: 2025-12-17 15:39:21
Message-ID: CADK3HHJgaeXW1+TO9DObZsv3nryujJMzAqYZFFM-S5vcsP5w4A@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Dave Cramer
www.postgres.rocks

On Wed, 17 Dec 2025 at 10:33, Dave Cramer <davecramer(at)postgres(dot)rocks> wrote:

>
>
>
> On Wed, 17 Dec 2025 at 09:51, Greg Sabino Mullane <htamfids(at)gmail(dot)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
>
>

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2025-12-17 15:44:03 Re: BUG #19350: Short circuit optimization missed when runningsqlscriptes in JDBC
Previous Message Tom Lane 2025-12-17 15:39:10 Re: BUG #19357: PostgreSQL generates a custom plan that performs worse than the generic plan for a certain query.