What does ACID guarantee, and which part is actually enforced by which mechanism?
basicAtomicity: all statements commit or none do. Consistency: a transaction moves the database from one valid state to another (constraints, triggers; partly the application's duty). Isolation: concurrent transactions do not see each other's intermediate state, to a degree set by the isolation level. Durability: committed data survives a crash.
- Atomicity and durability come from the write-ahead log (WAL in PostgreSQL, redo/undo logs in InnoDB): changes are logged and fsynced at commit, undone on rollback or crash recovery.
- Isolation comes from locks and/or MVCC.
- Consistency is enforced by constraints (PK, FK, CHECK, UNIQUE); business invariants spanning rows need the right isolation or explicit locks.
- Durability depends on settings:
synchronous_commit=off(PostgreSQL) orinnodb_flush_log_at_trx_commit=2trade durability for speed.
- Is "C" in ACID the same as "C" in CAP? No; ACID consistency is about invariants, CAP consistency is linearizability across replicas.
- Does a DDL statement roll back? In PostgreSQL yes (transactional DDL); in MySQL DDL causes an implicit commit.