Transactions and Isolation Levels

KDBS defaults to autocommit, and BEGIN … COMMIT opens an explicit transaction. There is one transaction per connection, with no nesting and no savepoints. A transaction commits as a whole or rolls back as a whole.

Key specs

ItemValue
Isolation levelsREAD COMMITTED (default, read view per statement), REPEATABLE READ (read view per transaction)
RejectedSERIALIZABLE (out of scope), READ UNCOMMITTED (not supported), SAVEPOINT, ROLLBACK TO, COMMIT AND CHAIN
Write conflictfirst-updater-wins. A holder whose outcome is undecided is waited for. Only a conflict that waiting cannot resolve raises TXN_CONFLICT retryable=1
Retry targetTXN_CONFLICT with retryable=1, the only one. On receiving it, ROLLBACK and rerun the whole transaction
Failed transactionAfter a failed statement, accepts only ROLLBACK/ABORT/SYNC/STOP/PING
Lifetime ceilingtxn_lifetime_ceiling_ms (default 60,000). Cannot be turned off
Lock wait ceilinglock_wait_fault_net_ms (default 1,000)
DDLCREATE TABLE, DROP TABLE, CREATE INDEX, DROP INDEX, ADD/DROP COLUMN, CREATE VIEW are rolled back inside a transaction

READ ONLY transactions

BEGIN READ ONLY ISOLATION LEVEL REPEATABLE READ;
SELECT COUNT(*) FROM orders;
SELECT SUM(amt) FROM orders WHERE status = 'PAID';   -- same snapshot
ROLLBACK;
  • It does not receive a transaction id, writes no log, and does not wait for sync at commit. It holds only a snapshot.
  • A write inside it is rejected with READ_ONLY_TRANSACTION retryable=0, but the transaction does not fail and can keep going.
  • The manual recommends this form for reports that read several times in one go. A plain BEGIN receives an id even if it writes nothing, leaves begin and commit records, and waits for sync under strict.
  • Every run in the sandbox uses this form.

Read, compute, and write: FOR UPDATE

In READ COMMITTED, if you do SELECT balance … and then UPDATE … SET balance = <computed value>, another commit that arrived in between is overwritten without an error. Adding FOR UPDATE to the read holds that row until commit.

BEGIN;
SELECT balance FROM accounts WHERE id = 7 FOR UPDATE;
UPDATE accounts SET balance = 90 WHERE id = 7;
COMMIT;
  • Only inside a transaction, only in read-write transactions. One table, with no join, aggregate, ORDER BY, or LIMIT. FOR SHARE, NOWAIT, and SKIP LOCKED are rejected. This is because accepting FOR SHARE as a weaker lock would enforce something different from what was written.
  • The lock it takes corresponds to PostgreSQL's FOR NO KEY UPDATE. It does not block INSERT into a foreign key child.
  • If the new value is an expression of the old value (SET balance = balance - 10), a single UPDATE without a read is cheaper.
  • The manual recommends updating rows shared by many transactions (accounts, counters, inventory) last. In an 8-session measurement, updating that row first gave 1,571 tps and updating it last gave 4,447 tps.

Comparison with other DBMSs

KDBSPostgreSQLOracleSQL Server
Default isolationRead CommittedRead CommittedRead CommittedRead Committed (locking), RCSI optional
Highest isolationRepeatable ReadSerializable (SSI)Serializable (actually snapshot)Serializable
SavepointsNoneYesYesYes
Read-only transactionBEGIN READ ONLY (no id, no log)BEGIN READ ONLYSET TRANSACTION READ ONLYNone
Retry signalTXN_CONFLICT retryable=140001, 40P01ORA-08177, ORA-000601205 (deadlock)

Related pages