Expand description
Singleflight request coalescing for query deduplication.
When multiple threads issue the SAME query (same sql_hash + same parameter bytes) simultaneously, only one actually executes against PostgreSQL. The others wait for the result and receive a shared copy via a condvar.
This is opt-in: enabled via Pool::builder().singleflight(true).
§Key design
Key = hash of (sql_hash, parameter bytes). We use rapidhash to combine the sql_hash with a hash of the parameter slice. If a request is already in-flight with the same key, the caller waits on its condvar instead of executing a new query.
§Limitations
- Only coalesces
query_rawandquery_raw_readonly(notexecute_raw). Writes must not be coalesced. - The result is
Arc-shared, so callers receive the same data (no mutations). - Large result sets are shared by reference, reducing memory for hot reads.
Structs§
- Flight
Leader - Handle for the leader thread that will execute the query and notify followers.
- Flight
State - State shared between a leader and its followers via condvar.
- Owned
Result Snapshot - A snapshot of query results that can be shared across threads.
- Singleflight
- Singleflight coalescing layer.
Enums§
- Flight
Result - Result of attempting to join a singleflight group.