PostgreSQL's Extended Query Protocol Support in ProxySQL [WIP]#5044
PostgreSQL's Extended Query Protocol Support in ProxySQL [WIP]#5044renecannao merged 61 commits intov3.0from
Conversation
This commit lays the groundwork for handling PostgreSQL’s extended query protocol (prepared statements) by introducing parsing, it's caching and execution framework stubs. - Implement Parse handling - Implement caching of parse (reuse) - Introduce Execute framework stub for future binding and execution logic.
Improved extended query frame handling
…s in a single frame will now use the same backend connection. * Fixed few compilation warnings. * Removed AutoCommit relate code from PostgreSQL session.
…er in PgSQL_Protocol. * Moved get_uint32be() and get_uint16be() to gen_utils.h * Split PgSQL_*_Message into distinct Message and Data components.
…simple query or statement execution
…ndling - Always send Describe Portal to the backend - Enforce check for unnamed portals in Bind, Describe, Close, and Execute; raise errors for named portals - Improve error handling for extended query flow - Introduce Extended_Query_Info struct to unify extended query-related members and reduce redundancy
* Introduced an error generator method to reduce code duplication * Added several comments for clarity * Addressed edge cases related to libpq limitations
There was a problem hiding this comment.
Summary of Changes
Hello @rahim-kanji, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces foundational support for PostgreSQL's Extended Query Protocol within ProxySQL. It enables ProxySQL to handle prepared statements (Parse, Bind, Describe, Execute, Close messages) from PostgreSQL clients, allowing for more efficient and secure communication. The changes involve significant additions to the PostgreSQL-specific protocol handling, a new prepared statement management system, and refactoring of existing components to better align with PostgreSQL's unique characteristics.
Highlights
- Extended Query Protocol Implementation: Introduced a comprehensive implementation of PostgreSQL's Extended Query Protocol (Parse, Describe, Bind, Execute, Close) within ProxySQL. This involves new message parsing, state machine handling, and response generation.
- Prepared Statement Management: Added a robust system for managing PostgreSQL prepared statements, including global and session-local caches, reference counting, and metadata storage.
- PostgreSQL-Specific Refactoring: Performed significant refactoring of existing MySQL-centric code paths (e.g.,
MySQL_Session,MySQL_Data_Stream) to align with PostgreSQL's specific protocol and transaction semantics, including renaming variables and functions. - Enhanced Query Information Tracking: Updated the
PgSQL_Query_Infostructure to support detailed tracking of extended query parameters and prepared statement metadata. - Improved Error Handling and Logging: Adjusted error handling and logging mechanisms to provide more specific information for PostgreSQL extended queries, including logging of client-side statement names.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This is a substantial pull request that introduces support for PostgreSQL's Extended Query Protocol. The changes are extensive, adding new classes for message parsing, a manager for prepared statements, and significant modifications to the session and connection state machines. The overall architecture is sound and follows existing patterns in the codebase.
I've identified one critical bug in the parsing logic for bind formats that could lead to incorrect behavior. I also have a couple of medium-severity comments regarding potentially missing timeout logic and some unreachable code. Once these points are addressed, this will be a great addition to ProxySQL's capabilities.
…nded query frame. If it is an Execute message, indicating that client is sending a Bind/Describe/Execute sequence skip processing the Describe Portal. This is because libpq automatically includes a Describe Portal during execution, and sending it again would be redundant. * Removed server_capabilities from PgSQL modules
…xperimentation << >> Do not use in production << This library provides basic functionality to connect to a PostgreSQL database and execute simple queries.
e4178cf to
0638375
Compare
3fce71c to
344ba25
Compare
Renamed status to ssl_status Removed STATE_SLEEP_MULTI_PACKET from PgSQL session handler
Fixed connection reset for client connection
…k, with automatic reset on transaction end * Added tracking for pg_advisory_lock, with status reset only on pg_advisory_unlock_all * Implemented support for CREATE SEQUENCE and CREATE TEMP SEQUENCE, with reset on DISCARD SEQUENCES * Added handling for CREATE TEMP TABLE, with reset triggered by DISCARD TEMP
… INTERNAL SESSION output
f9af85f to
58eac30
Compare
Added test_deallocate_non_existent_stmt
…ATE_SLEEP___PGSQL_QUERY_qpo. * Fixed a crash occurring during session destruction. * Query rules will now apply only to the first message in an extended query frame. * OK message will apply to execute message. * Query rewrite, error messages, and large packet handling will apply to parse message. * Added query processing support for the Bind message.
|


Closes#5018
Closes#5039