-
Notifications
You must be signed in to change notification settings - Fork 1k
Optimize performance and improve query handling in PostgreSQL integration - WIP #5196
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
Open
rahim-kanji
wants to merge
7
commits into
v3.0
Choose a base branch
from
v3.0_optimizations_and_stability
base: v3.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9fa3d75
Backport PQsendPipelineSync from PostgreSQL 17 and update code to use it
rahim-kanji 9eb934e
Buffer response until Extended Query frame completes; send early only…
rahim-kanji 61ba182
Introduce inline functions for efficient ASCII whitespace detection a…
rahim-kanji 7a3a5c7
Optimize hot path: replace std::string with char[] to avoid heap
rahim-kanji 7c665b9
Checking the data stream on both ends doesn’t apply to frontend conne…
rahim-kanji e744c2b
Optimize transaction command parsing to avoid unnecessary tokenization
rahim-kanji 0162e8f
Replaced use of the generic write_generic() helper with direct packet…
rahim-kanji File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| diff --git src/interfaces/libpq/fe-exec.c src/interfaces/libpq/fe-exec.c | ||
| index b833e76..51ad8d8 100644 | ||
| --- src/interfaces/libpq/fe-exec.c | ||
| +++ src/interfaces/libpq/fe-exec.c | ||
| @@ -4558,3 +4558,65 @@ int PShandleRowData(PGconn *conn, bool is_first_packet, PSresult* result) { | ||
| return psHandleRowData(conn, is_first_packet, result); | ||
| } | ||
|
|
||
| +int | ||
| +PQsendPipelineSync(PGconn *conn) | ||
| +{ | ||
| + PGcmdQueueEntry *entry; | ||
| + | ||
| + if (!conn) | ||
| + return 0; | ||
| + | ||
| + if (conn->pipelineStatus == PQ_PIPELINE_OFF) | ||
| + { | ||
| + libpq_append_conn_error(conn, "cannot send pipeline when not in pipeline mode"); | ||
| + return 0; | ||
| + } | ||
| + | ||
| + switch (conn->asyncStatus) | ||
| + { | ||
| + case PGASYNC_COPY_IN: | ||
| + case PGASYNC_COPY_OUT: | ||
| + case PGASYNC_COPY_BOTH: | ||
| + /* should be unreachable */ | ||
| + appendPQExpBufferStr(&conn->errorMessage, | ||
| + "internal error: cannot send pipeline while in COPY\n"); | ||
| + return 0; | ||
| + case PGASYNC_READY: | ||
| + case PGASYNC_READY_MORE: | ||
| + case PGASYNC_BUSY: | ||
| + case PGASYNC_IDLE: | ||
| + case PGASYNC_PIPELINE_IDLE: | ||
| + /* OK to send sync */ | ||
| + break; | ||
| + } | ||
| + | ||
| + entry = pqAllocCmdQueueEntry(conn); | ||
| + if (entry == NULL) | ||
| + return 0; /* error msg already set */ | ||
| + | ||
| + entry->queryclass = PGQUERY_SYNC; | ||
| + entry->query = NULL; | ||
| + | ||
| + /* construct the Sync message */ | ||
| + if (pqPutMsgStart('S', conn) < 0 || | ||
| + pqPutMsgEnd(conn) < 0) | ||
| + goto sendFailed; | ||
| + | ||
| + /* | ||
| + * Give the data a push (in pipeline mode, only if we're past the size | ||
| + * threshold). In nonblock mode, don't complain if we're unable to send | ||
| + * it all; PQgetResult() will do any additional flushing needed. | ||
| + */ | ||
| + if (pqPipelineFlush(conn) < 0) | ||
| + goto sendFailed; | ||
| + | ||
| + /* OK, it's launched! */ | ||
| + pqAppendCmdQueueEntry(conn, entry); | ||
| + | ||
| + return 1; | ||
| + | ||
| +sendFailed: | ||
| + pqRecycleCmdQueueEntry(conn, entry); | ||
| + /* error message should be set up already */ | ||
| + return 0; | ||
| +} | ||
| diff --git src/interfaces/libpq/libpq-fe.h src/interfaces/libpq/libpq-fe.h | ||
| index 47f25e0..b769b64 100644 | ||
| --- src/interfaces/libpq/libpq-fe.h | ||
| +++ src/interfaces/libpq/libpq-fe.h | ||
| @@ -688,6 +688,9 @@ extern const PGresult *PQgetResultFromPGconn(PGconn *conn); | ||
| /* ProxySQL special handler function */ | ||
| extern int PShandleRowData(PGconn *conn, bool is_first_packet, PSresult* result); | ||
|
|
||
| +/* Send a pipeline sync message without flushing the send buffer */ | ||
| +extern int PQsendPipelineSync(PGconn *conn); | ||
| + | ||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.