You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
proxysql/deps/mariadb-client-library/ps_buffer_stmt_read_all_row...

30 lines
1.5 KiB

diff --git libmariadb/mariadb_stmt.c libmariadb/mariadb_stmt.c
index bbc2831..e66d810 100644
--- libmariadb/mariadb_stmt.c
+++ libmariadb/mariadb_stmt.c
@@ -207,6 +207,24 @@ int mthd_stmt_read_all_rows(MYSQL_STMT *stmt)
while ((packet_len = ma_net_safe_read(stmt->mysql, &is_data_packet)) != packet_error)
{
+ // This change is required due to the new algorithm introduced in ProxySQL in #3295.
+ // ********************************************************************************
+ // DETAILS:
+ // Since #3295 ProxySQL performs a buffering on the resulset received by a prepared
+ // statement. This way ProxySQL doesn't require to retain the whole result of the
+ // prepared statement in memory. For this purpose it's required to free the memory
+ // allocated in 'MYSQL_STMT' via 'ma_free_root'. Because of this, local pointers
+ // within this function pointing to the result data gets invalidated due to stack
+ // swapping. Reinitializing then to the current values pointing to the new allocated
+ // memory for 'MYSQL_STMT' is required. Since this only happens when we force
+ // 'stmt->result.rows' to be '1', it's the only case in which these variables
+ // need a reset.
+ if (stmt->result.rows == 1) {
+ result= &stmt->result;
+ pprevious= &result->data->next;
+ }
+ // ********************************************************************************
+
p= stmt->mysql->net.read_pos;
// The check is by 'ma_net_safe_read'
if (p[0] == 0 || is_data_packet)