Skip to content

Commit

Permalink
If query results needs to be cached, the pgsql_thread___query_cache_s…
Browse files Browse the repository at this point in the history
…ize_MB setting takes precedence over pgsql_thread___threshold_resultset_size
  • Loading branch information
rahim-kanji committed Oct 21, 2024
1 parent c71f987 commit 851a573
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
23 changes: 18 additions & 5 deletions lib/PgSQL_Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ PG_ASYNC_ST PgSQL_Connection::handler(short event) {
#if ENABLE_TIMER
Timer timer(myds->sess->thread->Timers.Connections_Handlers);
#endif // ENABLE_TIMER
unsigned long long processed_bytes = 0; // issue #527 : this variable will store the amount of bytes processed during this event
uint64_t processed_bytes = 0; // issue #527 : this variable will store the amount of bytes processed during this event
if (pgsql_conn == NULL) {
// it is the first time handler() is being called
async_state_machine = ASYNC_CONNECT_START;
Expand Down Expand Up @@ -1855,8 +1855,15 @@ PG_ASYNC_ST PgSQL_Connection::handler(short event) {
const unsigned int bytes_recv = query_result->add_row(result.get());
update_bytes_recv(bytes_recv);
processed_bytes += bytes_recv; // issue #527 : this variable will store the amount of bytes processed during this event

bool pause_loop = (processed_bytes > (unsigned int)pgsql_thread___threshold_resultset_size * 8);

if (pause_loop == true && myds->sess && myds->sess->qpo && myds->sess->qpo->cache_ttl > 0) {
pause_loop = (processed_bytes > ((uint64_t)pgsql_thread___query_cache_size_MB) * 1024ULL * 1024ULL);
}

if (
(processed_bytes > (unsigned int)pgsql_thread___threshold_resultset_size * 8)
pause_loop
||
(pgsql_thread___throttle_ratio_server_to_client && pgsql_thread___throttle_max_bytes_per_second_to_client && (processed_bytes > (unsigned long long)pgsql_thread___throttle_max_bytes_per_second_to_client / 10 * (unsigned long long)pgsql_thread___throttle_ratio_server_to_client))
) {
Expand All @@ -1877,8 +1884,14 @@ PG_ASYNC_ST PgSQL_Connection::handler(short event) {
update_bytes_recv(bytes_recv);
processed_bytes += bytes_recv; // issue #527 : this variable will store the amount of bytes processed during this event

bool pause_loop = (processed_bytes > (unsigned int)pgsql_thread___threshold_resultset_size * 8);

if (pause_loop == true && myds->sess && myds->sess->qpo && myds->sess->qpo->cache_ttl > 0) {
pause_loop = (processed_bytes > ((uint64_t)pgsql_thread___query_cache_size_MB) * 1024ULL * 1024ULL);
}

if (
(processed_bytes > (unsigned int)pgsql_thread___threshold_resultset_size * 8)
pause_loop
||
(pgsql_thread___throttle_ratio_server_to_client && pgsql_thread___throttle_max_bytes_per_second_to_client && (processed_bytes > (unsigned long long)pgsql_thread___throttle_max_bytes_per_second_to_client / 10 * (unsigned long long)pgsql_thread___throttle_ratio_server_to_client))
) {
Expand Down Expand Up @@ -2187,7 +2200,7 @@ void PgSQL_Connection::fetch_result_cont(short event) {
if (pgsql_result)
return;

switch (PShandleRowData(pgsql_conn, &ps_result)) {
switch (PShandleRowData(pgsql_conn, new_result, &ps_result)) {
case 0:
result_type = 2;
return;
Expand Down Expand Up @@ -2215,7 +2228,7 @@ void PgSQL_Connection::fetch_result_cont(short event) {
return;
}

switch (PShandleRowData(pgsql_conn, &ps_result)) {
switch (PShandleRowData(pgsql_conn, new_result, &ps_result)) {
case 0:
result_type = 2;
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/PgSQL_Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6240,7 +6240,7 @@ void PgSQL_Session::PgSQL_Result_to_PgSQL_wire(PgSQL_Connection* _conn, PgSQL_Da
bool resultset_completed = query_result->get_resultset(client_myds->PSarrayOUT);
if (_conn->processing_multi_statement == false)
assert(resultset_completed); // the resultset should always be completed if PgSQL_Result_to_PgSQL_wire is called
if (transfer_started == false) { // we have all the resultset when PgSQL_Result_to_PgSQL_wire was called
if (transfer_started == false && _conn->processing_multi_statement == false) { // we have all the resultset when PgSQL_Result_to_PgSQL_wire was called
if (qpo && qpo->cache_ttl > 0 && is_tuple == true) { // the resultset should be cached

if (_conn->is_error_present() == false &&
Expand Down

0 comments on commit 851a573

Please sign in to comment.