Implementation Details: query_cache_with_comments
class QueryStripComments
This feature adds the souce code file:
query_strip_comments.h
This file defines the 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 strips all comments and double-spaces from the entire query, saves this in internal buffer [Oleg: “internal buffer” = the query cache?], and also reserves spaсe for additional information.
After
set
we can call
query and query_length
to access the rewritten query.
Important - about enable/disable feature
If the feature is enabled, SET works as described above. If the feature is 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 follows the 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 feature uses
class QueryStripComments
to replace the original query by the stripped query</code>.
Store to query cache
This feature uses
class QueryStripComments
and
class QueryStripComments_Backup
to replace the original query by a similar rewriting to what was described above.


