EmergencyEMERGENCY? Get 24/7 Help Now!

Query_cache and column level privileges

 | August 6, 2007 |  Posted In: Insight for Developers

PREVIOUS POST
NEXT POST

Recently we were puzzled by question how query_cache works with column level privileges. The question was appeared as we discovered function query_cache_send_result_to_client is called before real parsing of query, so at the moment of execution the query_cache is not able to know which columns are accessed.
Looking into source code I found out that in the case when table has column level privileges – function query_cache_send_result_to_client just stopped and returns to usual execution. So initial assumtion was that query against table with defined column privilege is just not cached, though it is not reflected in documentation.
It was worth to test it experimentally and the reality turned out more interesting.

under root:

and under user ‘vadim’

As you see the query was inserted into query cache with allocated memory for.

Let’s try second execution:

So query hits was not increased that proves the initial assumption – the query that includes tables with defined column level privileges can’t be cached – but actually even more – the query is stored in query cache area and eats memory, even the result cannot be used later.

PREVIOUS POST
NEXT POST
Vadim Tkachenko

Vadim Tkachenko co-founded Percona in 2006 and serves as its Chief Technology Officer. Vadim leads Percona Labs, which focuses on technology research and performance evaluations of Percona’s and third-party products. Percona Labs designs no-gimmick tests of hardware, filesystems, storage engines, and databases that surpass the standard performance and functionality scenario benchmarks. Vadim’s expertise in LAMP performance and multi-threaded programming help optimize MySQL and InnoDB internals to take full advantage of modern hardware. Oracle Corporation and its predecessors have incorporated Vadim’s source code patches into the mainstream MySQL and InnoDB products. He also co-authored the book High Performance MySQL: Optimization, Backups, and Replication 3rd Edition.

5 Comments

  • You know, profiling would answer it definitively perhaps easier:

    mysql> SELECT id FROM xp.test1 WHERE id> 1;
    +——+
    | id |
    +——+
    | 5 |
    +——+
    1 row in set (0.00 sec)

    mysql> show profile;
    +——————————–+———-+
    | Status | Duration |
    +——————————–+———-+
    | (initialization) | 0.000005 |
    | checking query cache for query | 0.000049 |
    | checking permissions | 0.00001 |
    | Opening tables | 0.000011 |
    | System lock | 0.000007 |
    | Table lock | 0.000017 |
    | init | 0.000021 |
    | optimizing | 0.000009 |
    | statistics | 0.000028 |
    | preparing | 0.000013 |
    | executing | 0.000005 |
    | Sending data | 0.000036 |
    | end | 0.000008 |
    | query end | 0.000005 |
    | storing result in query cache | 0.000005 |
    | freeing items | 0.000012 |
    | closing tables | 0.000007 |
    | logging slow query | 0.000224 |
    +——————————–+———-+
    18 rows in set (0.00 sec)

    mysql> SELECT id FROM xp.test1 WHERE id> 1;
    +——+
    | id |
    +——+
    | 5 |
    +——+
    1 row in set (0.00 sec)

    mysql> show profile;
    +——————————–+———-+
    | Status | Duration |
    +——————————–+———-+
    | (initialization) | 0.000005 |
    | checking query cache for query | 0.000008 |
    | checking privileges on cached | 0.000006 |
    | checking permissions | 0.000051 |
    | Opening tables | 0.000012 |
    | System lock | 0.000006 |
    | Table lock | 0.00001 |
    | init | 0.000021 |
    | optimizing | 0.00001 |
    | statistics | 0.000028 |
    | preparing | 0.000012 |
    | executing | 0.000005 |
    | Sending data | 0.000024 |
    | end | 0.000007 |
    | query end | 0.000004 |
    | freeing items | 0.000012 |
    | closing tables | 0.000007 |
    | logging slow query | 0.000004 |
    +——————————–+———-+
    18 rows in set (0.00 sec)

  • Thanks Jeremy,

    We’re just trying to keep things usable for people which are still stuck with MySQL Enterprise version.

    Though I hope you’ve seen my post regarding potentially high overhead of SHOW PROFILE patch even when it is disabled
    if there is huge query volume.

Leave a Reply

 
 

Percona’s widely read Percona Data Performance blog highlights our expertise in enterprise-class software, support, consulting and managed services solutions for both MySQL® and MongoDB® across traditional and cloud-based platforms. The decades of experience represented by our consultants is found daily in numerous and relevant blog posts.

Besides specific database help, the blog also provides notices on upcoming events and webinars.
Want to get weekly updates listing the latest blog posts? Subscribe to our blog now! Submit your email address below and we’ll send you an update every Friday at 1pm ET.

No, thank you. Please do not ask me again.