Add minor performance improvements to readwritesplit

The multi-statement detection did not check for the existence of
semicolons before doing the heavier processing.

Calculcate the packet length only once for the result state management.
This commit is contained in:
Markus Mäkelä
2017-10-06 13:34:07 +03:00
committed by Johan Wikman
parent b1e224ac84
commit fbb45ead1a
3 changed files with 23 additions and 16 deletions

View File

@ -514,11 +514,11 @@ static bool route_stored_query(RWSplitSession *rses)
return rval;
}
static inline bool is_eof(GWBUF* buffer)
static inline bool is_eof(GWBUF* buffer, size_t len)
{
uint8_t* data = GWBUF_DATA(buffer);
return data[MYSQL_HEADER_LEN] == MYSQL_REPLY_EOF &&
gw_mysql_get_byte3(data) + MYSQL_HEADER_LEN == MYSQL_EOF_PACKET_LEN;
len == MYSQL_EOF_PACKET_LEN - MYSQL_HEADER_LEN;
}
static inline bool is_ok(GWBUF* buffer)
@ -526,10 +526,6 @@ static inline bool is_ok(GWBUF* buffer)
uint8_t* data = GWBUF_DATA(buffer);
return data[MYSQL_HEADER_LEN] == MYSQL_REPLY_OK;
}
static inline bool is_large(GWBUF* buffer)
{
return gw_mysql_get_byte3(GWBUF_DATA(buffer)) == GW_MYSQL_MAX_PACKET_LEN;
}
static inline bool more_results_exist(GWBUF* buffer)
{
@ -584,24 +580,23 @@ bool reply_is_complete(SRWBackend& backend, GWBUF *buffer)
}
else
{
bool large = backend->is_large_packet();
int n_eof = backend->get_reply_state() == REPLY_STATE_RSET_ROWS ? 1 : 0;
if (is_large(buffer))
size_t len = gw_mysql_get_byte3(GWBUF_DATA(buffer));
if (len == GW_MYSQL_MAX_PACKET_LEN)
{
large = true;
backend->set_large_packet(true);
}
else if (large)
else if (backend->is_large_packet())
{
large = false;
backend->set_large_packet(false);
}
else if (is_eof(buffer))
else if (is_eof(buffer, len))
{
n_eof++;
}
backend->set_large_packet(large);
if (n_eof == 0)
{
/** Waiting for the EOF packet after the column definitions */

View File

@ -783,7 +783,6 @@ handle_multi_temp_and_load(RWSplitSession *rses, GWBUF *querybuf,
rses->target_node = rses->current_master;
MXS_INFO("Multi-statement query or stored procedure call, routing "
"all future queries to master.");
}
else
{

View File

@ -179,6 +179,19 @@ void check_create_tmp_table(RWSplitSession *router_cli_ses,
}
}
inline bool have_semicolon(const char* ptr, int len)
{
for (int i = 0; i < len; i++)
{
if (ptr[i] == ';')
{
return true;
}
}
return false;
}
/**
* @brief Detect multi-statement queries
*
@ -203,7 +216,7 @@ bool check_for_multi_stmt(GWBUF *buf, void *protocol, uint8_t packet_type)
/** Payload size without command byte */
int buflen = gw_mysql_get_byte3((uint8_t *)GWBUF_DATA(buf)) - 1;
if ((ptr = strnchr_esc_mysql(data, ';', buflen)))
if (have_semicolon(data, buflen) && (ptr = strnchr_esc_mysql(data, ';', buflen)))
{
/** Skip stored procedures etc. */
while (ptr && is_mysql_sp_end(ptr, buflen - (ptr - data)))