Skip to content

fix: enable cursor-based fetching in extended protocol when transaction started via SQL command - #3996

Merged
vlsi merged 1 commit into
pgjdbc:masterfrom
vlsi:issue3993
Mar 24, 2026
Merged

vlsi merged 1 commit into
pgjdbc:masterfrom
vlsi:issue3993

Conversation

@vlsi

@vlsi vlsi commented Mar 23, 2026

Copy link
Copy Markdown
Member

When a user starts a transaction with START TRANSACTION or BEGINSQL commands (instead of setAutoCommit(false)), cursor-based fetching was not activated because PgStatement.executeInternal() only checked getAutoCommit().
The server is already in a transaction block in this case, so server-side cursors will survive across fetches.

The fix checks the actual server transaction state in addition to the autoCommit flag.

Fixes #3993

@vlsi vlsi added the bug label Mar 23, 2026
@vlsi
vlsi force-pushed the issue3993 branch 2 times, most recently from 53437b6 to 028d380 Compare March 23, 2026 13:21
…on started via SQL command

When a user starts a transaction with START TRANSACTION or BEGIN SQL
commands (instead of setAutoCommit(false)), cursor-based fetching was
not activated because PgStatement.executeInternal() only checked
getAutoCommit(). The server is already in a transaction block in this
case, so server-side cursors will survive across fetches.

The fix checks the actual server transaction state in addition to the
autoCommit flag.

The test is skipped for simple and extendedForPrepared query modes
since non-prepared statements use the simple query protocol there,
which does not support server-side cursors.

Fixes pgjdbc#3993

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vlsi vlsi changed the title fix: enable cursor-based fetching when transaction started via SQL command fix: enable cursor-based fetching in extended protocol when transaction started via SQL command Mar 23, 2026
@davecramer

Copy link
Copy Markdown
Member

we should probably check the transaction state before we do anything on the connection as well.

@vlsi

vlsi commented Mar 23, 2026

Copy link
Copy Markdown
Member Author

What do you mean?

@davecramer

Copy link
Copy Markdown
Member

Well since we are getting the transaction state from the queryExecutor just want to put a check in there to make sure that the query executor is instantiated correctly. So if we don't execute any statements what is the transaction state ?

@vlsi

vlsi commented Mar 23, 2026

Copy link
Copy Markdown
Member Author

I am not following your question.
There's a valid API use, and currently it skips using cursor (==It loads everything at once in a single go).
As far as I understand, the code wants to skip cursor in certain cases so the cursor does not disappear mid-fetch.

The condition for "use vs not use" the cursor was not quite right, so the condition could be lifted.

I don't understand how your question maps to the test case at hand

@vlsi

vlsi commented Mar 23, 2026

Copy link
Copy Markdown
Member Author

Do you mean "add a test case that a fresh connection responds IDLE transaction state"?

@davecramer

Copy link
Copy Markdown
Member

Do you mean "add a test case that a fresh connection responds IDLE transaction state"?

yes

@vlsi

vlsi commented Mar 24, 2026

Copy link
Copy Markdown
Member Author

I've filed transaction state tests under #4006

@vlsi
vlsi merged commit 0fe8619 into pgjdbc:master Mar 24, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix Enable cursor-based bug, when start transaction by 'START TRANSAC'

2 participants