From: vlsi (@vlsi) <noreply+vlsi@github.com>
To: pgjdbc/pgjdbc <noreply+pgjdbc-pgjdbc@github.com>
Subject: Re: [pgjdbc/pgjdbc] PR #4394: fix(core): take the command type from the first word of a statement
Date: Thu, 05 Nov 2026 09:28:38 +0000
Message-ID: <gh-pgjdbc-pgjdbc-4394-c6654473461@github.com> (raw)
In-Reply-To: <gh-pgjdbc-pgjdbc-4394@github.com>
References: <gh-pgjdbc-pgjdbc-4394@github.com>
After more analysis I widened the scope of this PR so that it is coherent from the user's side: on its own, the guard fix made `drop table insert` fail with `42601` when generated keys are requested, so the parser now takes the command type from the first word of a statement. EXPLAIN and some MERGE forms behave differently with generated keys requested (see the description), so the earlier "low-risk" note no longer applies.
I see no performance degradation from moving the matchers to `parseKeyword` (third commit): a typical statement parses in the same time, and only a synthetic worst case is about 10% slower on JDK 21. JMH results against the parent commit, Apple M1 Max, `-f 3 -wi 5 -i 5`, measured while other jobs ran on the machine.
`Parser.parseJdbcSql`, µs per call:
| Input | JDK 8 (8.0.402) | JDK 21 (21.0.9) |
| --- | --- | --- |
| `insert into t(a, b, c) values (?, ?, ?)` | 0.26 → 0.28, within noise | 0.33 → 0.34, within noise |
| `with x as (select 1)` + 10000 × `selecz` | ≈285 → ≈290, within noise | 222 → 245 |
| 10000 × `insera;` | 590 → 775 ± 190, noise exceeds the difference | 400 → 397 |
One matcher, ns per call, unrolled → `parseKeyword`:
| Word | JDK 8 | JDK 21 |
| --- | --- | --- |
| `select` | 3.0 → 3.7 | 1.69 → 1.90 |
| `selecz` | 2.9 → 3.1 | 1.55 → 1.74 |
| `zelect` | 2.2 → 2.4 | 0.76 → 0.81 |
The WITH tail is the input with the most matcher calls per character: each word is tested against UPDATE, DELETE, INSERT, SELECT, and VALUES, and `selecz` matches `select` up to its last character. A typical statement makes a few calls and shows no difference. Moving `keyword.length()` into a local variable changes nothing on either JDK.