Patch: query_cache_with_comments

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.

Version-Specific Information

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.

Variables Provided

query_cache_strip_comments

TypeSystem and command-line variable
ScopeGlobal
DynamicYes
DefaultOFF

Makes the server ignore comments when checking for a query cache hit.

Implementation details

class QueryStripComments

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.

Important - about enable/disable feature

If feature is enabled, set work as described above. If the feature disabled,

class QueryStripComments

simple map to arguments.

Important - life time

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.

class QueryStripComments_Backup

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.

Search and store in query cache

MySQL query cache contain file

sql/sql_cache.cc

Search in query cache

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>.

Store to query cache

This patch use

class QueryStripComments

and

class QueryStripComments_Backup

for replace original query by rewrited similar described in above.

Related Reading

Please note that this is NOT a place to ask questions or report bugs. This comment system is only intended for users to share tips and documentation additions concerning particular document.
Please report bugs to https://bugs.launchpad.net/percona-project/+filebug and ask general questions in maillist Percona-discussions

Discussion

Enter your comment (wiki syntax is allowed):
WCWOV
 
patches/query_cache_with_comments.txt · Last modified: 2010/07/13 17:03 by oleg.tsarev
 
Except where otherwise noted, content on this wiki is licensed under the following license:GNU Free Documentation License 1.2
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki