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

From: ZhangChi <798604270(at)qq(dot)com>
To: Greg Sabino Mullane <htamfids(at)gmail(dot)com>
Cc: 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 01:40:29
Message-ID: tencent_D9E4BA699E83ACD964358E23B46C29753705@qq.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi Greg,

Thanks for your reply. I can understand what you describe.

But my question is that in the CLI, the test case (like foo2) I showed can return the results. But when I run the same test case in JDBC, the test case triggers an error. I wonder why there is an inconsistency.

```
SET plan_cache_mode = force_generic_plan;
CREATE TABLE t0(c0 int4range);
INSERT INTO t0(c0) VALUES('[-1920846305,-1018839689)'::int4range);
PREPARE prepare_query (int8, int8) AS SELECT
((((((upper(t0.c0))))/($1)))*(($2::int8))) FROM ONLY t0;
EXECUTE prepare_query(0, NULL); -- trigger error in JDBC but no error in CLI
```

Original


From: Greg Sabino Mullane <htamfids(at)gmail(dot)com&gt;
Date: 2025-12-16 23:17
To: ZhangChi <798604270(at)qq(dot)com&gt;
Cc: David G. Johnston <david(dot)g(dot)johnston(at)gmail(dot)com&gt;, pgsql-bugs(at)lists(dot)postgresql(dot)org <pgsql-bugs(at)lists(dot)postgresql(dot)org&gt;
Subject: Re: BUG #19350: Short circuit optimization missed when runningsqlscriptes in JDBC

I wonder why this query triggers an error under JDBC but not in the CLI.

Fails as expected from the command line:

prepare foo1 as select 99 / $1::int * $2;
PREPARE
execute foo1(0, null);
ERROR: &nbsp;division by zero

prepare foo2 as select 99 / ($1::int * $2);
PREPARE
execute foo2(0, null);
&nbsp;?column?
----------
&nbsp; &nbsp; &nbsp; &nbsp; ☃
(1 row)

prepare foo3 as select (99 / $1::int) * $2;
PREPARE
execute foo3(0, null);
ERROR: &nbsp;division by zero

If you want the "null combined with anything = null" to always happen before the "divide by zero is wrong" make your query specific like in foo2 above.

Cheers,
Greg

--
Crunchy Data - https://www.crunchydata.com
Enterprise Postgres Software Products &amp; Tech Support

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Paquier 2025-12-17 02:59:17 Re: BUG #19354: JOHAB rejects valid byte sequences
Previous Message Jhonathan Cruz 2025-12-17 00:25:08 Possible performance issues: DISTINCT ON + ORDER BY and JIT with aggregation