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
| Item | Value |
|---|---|
| Isolation levels | READ COMMITTED (default, read view per statement), REPEATABLE READ (read view per transaction) |
| Rejected | SERIALIZABLE (out of scope), READ UNCOMMITTED (not supported), SAVEPOINT, ROLLBACK TO, COMMIT AND CHAIN |
| Write conflict | first-updater-wins. A holder whose outcome is undecided is waited for. Only a conflict that waiting cannot resolve raises TXN_CONFLICT retryable=1 |
| Retry target | TXN_CONFLICT with retryable=1, the only one. On receiving it, ROLLBACK and rerun the whole transaction |
| Failed transaction | After a failed statement, accepts only ROLLBACK/ABORT/SYNC/STOP/PING |
| Lifetime ceiling | txn_lifetime_ceiling_ms (default 60,000). Cannot be turned off |
| Lock wait ceiling | lock_wait_fault_net_ms (default 1,000) |
| DDL | CREATE 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
BEGINreceives an id even if it writes nothing, leaves begin and commit records, and waits for sync understrict. - 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, orLIMIT.FOR SHARE,NOWAIT, andSKIP LOCKEDare rejected. This is because acceptingFOR SHAREas 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 blockINSERTinto a foreign key child. - If the new value is an expression of the old value (
SET balance = balance - 10), a singleUPDATEwithout 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
| KDBS | PostgreSQL | Oracle | SQL Server | |
|---|---|---|---|---|
| Default isolation | Read Committed | Read Committed | Read Committed | Read Committed (locking), RCSI optional |
| Highest isolation | Repeatable Read | Serializable (SSI) | Serializable (actually snapshot) | Serializable |
| Savepoints | None | Yes | Yes | Yes |
| Read-only transaction | BEGIN READ ONLY (no id, no log) | BEGIN READ ONLY | SET TRANSACTION READ ONLY | None |
| Retry signal | TXN_CONFLICT retryable=1 | 40001, 40P01 | ORA-08177, ORA-00060 | 1205 (deadlock) |