Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: handling of named prepared statements #207

Merged
merged 4 commits into from Dec 8, 2023
Merged

Conversation

abc3
Copy link
Member

@abc3 abc3 commented Dec 6, 2023

This PR introduces support for prepared named statements in transaction mode.

Supavisor attempts to decode all incoming queries from connected users and retrieves the SQL statement by parsing the decoded queries through an existing Rustler wrapper around libpg_query. When the parsed query contains PrepareStmt or DeallocateStmt (which requires removing an existing named statement), the ClientHandler broadcasts it to all other DbHandlers in the pool.

In DbHandler, these queries accumulate in the anon_buffer list and will be applied when data.caller is nil. They will wait until the current PID is unlinked in cases where the process is reserved by another client

Screenshot 2023-12-07 at 11 02 40

@abc3 abc3 changed the title feat: handling of named prepared statements. feat: handling of named prepared statements Dec 6, 2023
@abc3 abc3 linked an issue Dec 7, 2023 that may be closed by this pull request
@abc3 abc3 requested a review from a team December 7, 2023 11:17
@josevalim
Copy link
Contributor

Excellent description and diagram. I have only one question though: @abc3 does it mean the statement will be prepared once per db handler? Would it make sense to keep the statements in memory and, given you parse queries, when there is an attempt to execute the statement, you immediately prepare it before (which then stays prepared)?

Copy link
Contributor

@josevalim josevalim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code wise the changes look great to me :D

@abc3
Copy link
Member Author

abc3 commented Dec 8, 2023

does it mean the statement will be prepared once per db handler?

yes

@josevalim Thanks for the review and the excellent suggestion for improvement 🔥
We will try to implement it in the next iteration

@abc3 abc3 merged commit 89c03a5 into feat/read-replicas Dec 8, 2023
@abc3 abc3 deleted the feat/named_ps branch December 8, 2023 18:14
abc3 added a commit that referenced this pull request Dec 8, 2023
* call pg_query.statement_types() via rustler

* handle READ ONLY SQL TRANSACTION error

* clusters crud

* update migrations and pool starting

* safe statement_types

* configs validation

* feat: handling of named prepared statements (#207)

* fix caller unlinking
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support named prepared statements
2 participants