Sets the characteristics of the current transaction.
SET TRANSACTION [transaction_mode] [READ ONLY | READ WRITE]
SET TRANSACTION SNAPSHOT snapshot_id
SET SESSION CHARACTERISTICS AS TRANSACTION transaction_mode
[READ ONLY | READ WRITE]
[NOT] DEFERRABLE
where transaction_mode is one of the following:
ISOLATION LEVEL {SERIALIZABLE | REPEATABLE READ | READ COMMITTED | READ UNCOMMITTED}
The SET TRANSACTION command sets the characteristics of the current transaction. It has no effect on any subsequent transactions.
Available transaction characteristics are transaction isolation level, transaction access mode (read/write or read-only), and delayable modes.
Note: A delayable transaction requires that the transaction be serializable. The YMatrix database does not support serializable transactions, so including the DEFERRABLE clause is invalid. The YMatrix database does not support the SET TRANSACTION SNAPSHOT command.
The isolation level of a transaction determines what data the transaction can see when other transactions run at the same time.
The SQL standard defines two additional levels, namely READ UNCOMMITTED and SERIALIZABLE. In the YMatrix database, READ UNCOMMITTED is considered as READ COMMITTED. If SERIALIZABLE is specified, the YMatrix database will fall back to REPEATABLE READ.
The transaction isolation level cannot be changed after the first query or data modification statement of a transaction is executed (SELECT, INSERT, DELETE, UPDATE, FETCH, or COPY).
Transaction access mode determines whether a transaction is read/write or read-only. Read/write is the default setting. When the transaction is read-only, the following SQL commands are not allowed: INSERT, UPDATE, DELETE, and COPY FROM (if the table to be written is not a temporary table); all CREATE, ALTER and DROP commands; GRANT, REVOKE, TRUNCATE; if the commands to be executed by EXPLAIN ANALYZE and EXECUTE are not allowed in the above commands, they are not allowed. This is a high-level concept of read-only and does not block all writes to disk.
The DEFERRABLE transaction attribute is invalid unless the transaction is both SERIALIZABLE and READ ONLY. When all these properties are set on the transaction, the transaction may block when it first takes its snapshot, after which it can run without the normal overhead of the SERIALIZABLE transaction and there is no risk of serialization failure or being cancelled by serialization failure. Since the YMatrix database does not support serializable transactions, the DEFERRABLE transaction attribute is invalid in the YMatrix database.
SESSION CHARACTERISTICS
READ UNCOMMITTED
READ COMMITTED
REPEATABLE READ
SERIALIZABLE
READ WRITE
READ ONLY
[NOT] DEFERRABLE
If SET TRANSACTION is executed without START TRANSACTION or BEGIN in advance, a warning will be issued and the command is invalid.
SET TRANSACTION can be omitted by specifying the required transaction mode in BEGIN or START TRANSACTION.
You can also set the default transaction mode of the session by setting the configuration parameters default_transaction_isolation, default_transaction_read_only and default_transaction_deferrable.
Set the transaction isolation level of the current transaction:
BEGIN;
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
Both commands are defined in the SQL standard. SERIALIZABLE is the default transaction isolation level in the standard. In the YMatrix database, the default value is READ COMMITTED. The YMatrix database does not fully support the SERIALIZABLE level due to the lack of predicate locking, so when SERIALIZABLE is specified, it falls back to the REPEATABLE READ level. Essentially, the predicate locking system prevents phantom reading by restricting what is written, while the multi-version concurrency control model (MVCC) used in the YMatrix database prevents phantom reading by restricting what is read.
PostgreSQL provides a true serializable isolation level called serializable snapshot isolation (SSI), which monitors concurrent transactions and rolls back transactions that may introduce serialized exceptions. This isolation mode is not implemented in the YMatrix database.
In the SQL standard, you can set other transaction characteristics using the following command: the size of the diagnostic area. This concept is specific to embedded SQL and is therefore not implemented in the YMatrix database server.
The DEFERRABLE transaction mode is an extension of the YMatrix database language.