~~REDIRECT>percona-server:features:query_cache_enhance~~
====== 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 ^
| [[http://www.percona.com/docs/wiki/percona-server:release_notes_51#release_5147-110|5.1.47-11.0]] | Ctirical bug - when feature disabled, your query don't cachable (see [[http://bugs.mysql.com/bug.php?id=55032|MySQL bug 55032]]). Release was recall. |
| [[http://www.percona.com/docs/wiki/percona-server:release_notes_51#release_5147-111|5.1.47-11.1]] | Fixed critical bug from previous release. [[http://bugs.mysql.com/bug.php?id=55032|MySQL bug 55032]] actual. Bug [[https://bugs.launchpad.net/percona-server/+bug/603618|b603618]] actual. Bug [[https://bugs.launchpad.net/percona-server/+bug/603619|603619]] actual. |
| [[http://www.percona.com/docs/wiki/percona-server:release_notes_51#release_5147-112|5.1.47-11.2]] | Full functionality available. |
| [[http://www.percona.com/docs/wiki/percona-server:release_notes_51#release_5147-120|5.1.48-12.0]] | Full functionality available. |
===== Variables Provided =====
==== query_cache_strip_comments ====
| Type|System and command-line variable|
| Scope|Global|
| Dynamic|Yes|
| Default|OFF|
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 [[http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Resource_Acquisition_Is_Initialization|RAII]] and [[http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Scope_Guard|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.
=== 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 =====
[[http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Resource_Acquisition_Is_Initialization|RAII]]
[[http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Scope_Guard|Scope guard]]