This patch adds an option to make the server ignore comments when checking for a query cache hit. For example pick these two queries:
/* first query */ select name from users where users.name like 'Bob%'; /* retry search */ select name from users where users.name like 'Bob%';
By default (option disabled) the queries are considered different so the server will execute them both and cache them both.
If the option is enabled the queries are considered identical so the server will execute and cache the first one and will directly serve the second one from the query cache.
| Percona-Server Version | Comments |
|---|---|
| 5.1.47-11.0 | Ctirical bug - when feature disabled, your query don't cachable (see MySQL bug 55032). Release was recall. |
| 5.1.47-11.1 | Fixed critical bug from previous release. MySQL bug 55032 actual. Bug b603618 actual. Bug 603619 actual. |
| 5.1.47-11.2 | Full functionality available. |
| 5.1.48-12.0 | Full functionality available. |
| Type | System and command-line variable |
| Scope | Global |
| Dynamic | Yes |
| Default | OFF |
Makes the server ignore comments when checking for a query cache hit.
This patch add file
query_strip_comments.h
This file contain class QueryStripComments
class QueryStripComments
{
private:
QueryStripComments(const QueryStripComments&);
QueryStripComments& operator=(const QueryStripComments&);
public:
QueryStripComments();
~QueryStripComments();
void set(const char* a_query, uint a_query_length, uint a_additional_length);
char* query() { return buffer; }
uint query_length() { return length; }
};
In call
void set(const char* a_query, uint a_query_length, uint a_additional_length);
, QueryStripComments strip all comments and double-spaces from query length, save this in internal buffer, and also reserved plaсe for additional information. After
set
we can call
query and query_length
for access rewrited query.
If feature is enabled, set work as described above. If the feature disabled,
class QueryStripComments
simple map to arguments.
QueryStripComments is a member of
class THD
, file
sql/mysql_class.h
, and life time of this class equal life time of THD. On desctruction of member internal buffer was cleaned.
This class follow RAII and Scope guard idioms.
In call
QueryStripComments_Backup guard(thd,thd->query_script_comments)
instance of class call
thd->query_script_comments->set(thd->query(),thd->query_length());
and on call
QueryStripComments_Backup::~QueryStripComments_Backup()
(destruction of guard) instance was restore previous value query and query_length in THD.
MySQL query cache contain file
sql/sql_cache.cc
Function
send_result_to_client
. Before search this method write to query string, after the end additional information - database info, flags, so on. After it this buffer:
|/* first query */ select name from users where users.name like 'Bob%';\0|database.name|flags|
uses as key for search in cache. This patch use
class QueryStripComments
for replace original query by striped query</code>.
This patch use
class QueryStripComments
and
class QueryStripComments_Backup
for replace original query by rewrited similar described in above.
Please report bugs to https://bugs.launchpad.net/percona-project/+filebug and ask general questions in maillist Percona-discussions
Discussion