Subject | Re: autocommit mode |
---|---|
Author | Roman Rokytskyy |
Post date | 2003-06-08T07:05:42Z |
Hi,
According to the JDBC specification, in auto-commit mode each
statement is executed in its own transaction context. This means that
for each statement database server will start new transaction and
commit it after statement is finished (for selects it means "when last
row was fetched", for updates/inserts/deletes right after
executeUpdate() method) or before a new statement is executed.
Transaction start and commit are _expensive_ operations, so
setAutocommit(true) always slows things down.
is just setting a boolean flag in the FBConnection class. If there is
transaction running, it will cause transaction commit. Since you
execute all statements in auto-commit mode, there hardly will be any
active transaction when you call setAutocommit(true).
but you have to consider transaction isolation level. Firebird's
lowest transaction isolation level is TRANSACTION_READ_COMMITTED, this
means that your transaction will "see" changes made by concurrent
transactions only when they commit. If this is ok for you, switch
auto-commit off, if no - switch it on.
before executing a statement that should be executed in new
transaction context. In other words, when you commit/rollback, old
transaction is finished (by either commit or rollback). Then next call
to Statement.execute() will check if there is any active transaction,
and will start new one if no active transaction is found.
Best regards,
Roman Rokytskyy
> Why should I always set autoCommit(false) if most of the databaseIf you do not need transactions, you can use setAutocommit(true).
> accesses are just one SQL statement?
> Reusable code means that every database access sets its transactionSorry, I do not understand this sentense.
> mode, so they all are completelly independent. That's why I set the
> particular autoCommit mode, in most cases to true.
According to the JDBC specification, in auto-commit mode each
statement is executed in its own transaction context. This means that
for each statement database server will start new transaction and
commit it after statement is finished (for selects it means "when last
row was fetched", for updates/inserts/deletes right after
executeUpdate() method) or before a new statement is executed.
Transaction start and commit are _expensive_ operations, so
setAutocommit(true) always slows things down.
> So, my main questions are:Almost none. If there is no transaction started, setAutocommit(true)
>
> Is there any performance penalty if I set autoCommit(true) repeated
> times, even knowing that autocommit is already switched on in most
> cases?
is just setting a boolean flag in the FBConnection class. If there is
transaction running, it will cause transaction commit. Since you
execute all statements in auto-commit mode, there hardly will be any
active transaction when you call setAutocommit(true).
> Should it be better to switch autocommit off, even if most databaseDepends on your usage scenario. It will definitely speed things up,
> accesses are just one SQL statement?
but you have to consider transaction isolation level. Firebird's
lowest transaction isolation level is TRANSACTION_READ_COMMITTED, this
means that your transaction will "see" changes made by concurrent
transactions only when they commit. If this is ok for you, switch
auto-commit off, if no - switch it on.
> If I switch autoCommit off, does a new transaction start inmediatelyAccording to the JDBC specification transaction is started right
> either after executing that opertation or after performing a
> commit/rollback?
before executing a statement that should be executed in new
transaction context. In other words, when you commit/rollback, old
transaction is finished (by either commit or rollback). Then next call
to Statement.execute() will check if there is any active transaction,
and will start new one if no active transaction is found.
Best regards,
Roman Rokytskyy