h2database / h2database/h2database

Suspicious auto-commit logic in BEGIN + (COMMIT | ROLLBACK)

Open
#1,988 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
4.6k
Forks
1.3k
Avg merge
1d 2h
Merged PRs (30d)
9

Description

H2 has an undocumented non-standard BEGIN [ WORK | TRANSACTION ] command.
https://github.com/h2database/h2database/blob/6b359b683cd4899f96f42a914cc511b310461c15/h2/src/main/org/h2/command/Parser.java#L1046-L1053
https://github.com/h2database/h2database/blob/6b359b683cd4899f96f42a914cc511b310461c15/h2/src/main/org/h2/command/dml/TransactionCommand.java#L42-L44
Perhaps this command exists for compatibility with some other databases
https://docs.microsoft.com/sql/t-sql/language-elements/begin-transaction-transact-sql?view=sql-server-2017
https://www.ibm.com/support/knowledgecenter/en/SSGU8G_14.1.0/com.ibm.sqls.doc/ids_sqs_0329.htm

The command sets Session.autoCommit to false and Session.autoCommitAtTransactionEnd to true.
https://github.com/h2database/h2database/blob/6b359b683cd4899f96f42a914cc511b310461c15/h2/src/main/org/h2/engine/Session.java#L1462-L1465

COMMIT and ROLLBACK commands set Session.autoCommit to the value of Session.autoCommitAtTransactionEnd (true) and reset Session.autoCommitAtTransactionEnd back to false.
https://github.com/h2database/h2database/blob/6b359b683cd4899f96f42a914cc511b310461c15/h2/src/main/org/h2/engine/Session.java#L700-L703
https://github.com/h2database/h2database/blob/6b359b683cd4899f96f42a914cc511b310461c15/h2/src/main/org/h2/engine/Session.java#L805-L808

It means that combinations of BEGIN WORK + COMMIT WORK or BEGIN TRANSACTION + COMMIT and similar enable the auto-commit in the session uncoditionally. Perhaps they should not enable it if it wasn't enabled before the BEGIN …?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the referenced BEGIN handling in Parser.java and TransactionCommand.java, then trace Session.autoCommit and Session.autoCommitAtTransactionEnd at the referenced Session.java locations. Reproduce BEGIN WORK or BEGIN TRANSACTION followed by COMMIT or ROLLBACK, and verify that the final auto-commit state matches the state before BEGIN rather than being enabled unconditionally.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, sql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.