Summary
Add support for parallel consistent reads across multiple connections using Postgres's snapshot export mechanism. This enables structured concurrency patterns where a parent transaction fans out read-only queries to child virtual threads, each with their own JDBC Connection, all seeing an identical consistent view of the database.
Mechanism
-- Connection A (parent)
BEGIN ISOLATION LEVEL REPEATABLE READ;
SELECT pg_export_snapshot(); -- → '00000003-1'
-- Connection B (child, before A commits)
BEGIN ISOLATION LEVEL REPEATABLE READ;
SET TRANSACTION SNAPSHOT '00000003-1';
-- now runs parallel query with same view as A
pg_export_snapshot() returns a snapshot ID that another transaction can import via SET TRANSACTION SNAPSHOT '<id>'. Both transactions then see an identical consistent view of the DB.
When to use
- Parallel queries + cross-connection consistency required + queries are long enough that the parallelism benefit outweighs ~2 extra roundtrips (BEGIN + SET TRANSACTION SNAPSHOT per child)
- Avoid on high-write tables where the snapshot hold time would be long
- Don't use if slight inconsistency is acceptable — which it often is for analytical/reporting queries
Constraints
- Child connections must use
REPEATABLE READ or SERIALIZABLE isolation level
- Children are read-only — writes in children are not part of the parent's transaction
- Each child requires its own Connection from the pool — pool must be sized for fan-out
- Snapshot is only valid while the exporting transaction is open
Prerequisites
This feature builds on top of the transaction system (once implemented). The parent transaction scope would export the snapshot, and a structured concurrency API would provide child scopes that automatically import it.
Summary
Add support for parallel consistent reads across multiple connections using Postgres's snapshot export mechanism. This enables structured concurrency patterns where a parent transaction fans out read-only queries to child virtual threads, each with their own JDBC Connection, all seeing an identical consistent view of the database.
Mechanism
pg_export_snapshot()returns a snapshot ID that another transaction can import viaSET TRANSACTION SNAPSHOT '<id>'. Both transactions then see an identical consistent view of the DB.When to use
Constraints
REPEATABLE READorSERIALIZABLEisolation levelPrerequisites
This feature builds on top of the transaction system (once implemented). The parent transaction scope would export the snapshot, and a structured concurrency API would provide child scopes that automatically import it.