forked from sfackler/rust-postgres
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configuration to disable internal stmt cache
This enables usage with pgBouncer's transaction mode. Typically when using the transaction mode, a client gets a new connection from pgBouncer for every new transaction. It's quite useful and allows one to use prepared statements in this mode. The workflow goes: ```sql -- start a new transaction BEGIN -- deallocate all stored statements from the server to prevent -- collisions DEALLOCATE ALL -- run the queries here -- .. -- .. COMMIT -- or ROLLBACK ``` Now in a case where the query uses custom types such as enums, what tokio-postgres does is it fetches the type info for the given type, stores the info to the cache and also caches the statements for fetching the info to the client. Now when we have two tables with different custom types in both of them, we can imagine the following workflow: ```rust // first query client.simple_query("BEGIN")?; client.simple_query("DEALLOCATE ALL")?; let stmt = client.prepare("SELECT \"public\".\"User\".\"id\", \"public\".\"User\".\"userType\" FROM \"public\".\"User\" WHERE 1=1 OFFSET $1")?; dbg!(client.query(&stmt, &[&0i64])?); client.simple_query("COMMIT")?; // second query client.simple_query("BEGIN")?; client.simple_query("DEALLOCATE ALL")?; let stmt = client.prepare("SELECT \"public\".\"Work\".\"id\", \"public\".\"Work\".\"workType\" FROM \"public\".\"Work\" WHERE 1=1 OFFSET $1")?; dbg!(client.query(&stmt, &[&0i64])?); client.simple_query("COMMIT")?; ``` The `userType` and `workType` are both enums, and the preparing of the second query will give an error `prepared statement "s1" does not exist`, where `s1` is the query to the `pg_catalog` for the type info. The change here gives an extra flag for the client to disable caching of statements.
- Loading branch information
Julius de Bruijn
committed
Jul 22, 2020
1 parent
f6620e6
commit 87316f0
Showing
4 changed files
with
66 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters