[MDEV-7132] SQL_NO_CACHE / SQL_CACHE only handled/optimized by qc, if used in the right order Created: 2014-11-19 Updated: 2015-09-04 Resolved: 2015-09-04 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Query Cache |
| Affects Version/s: | 5.5, 10.0, 10.1 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Minor |
| Reporter: | roberto spadim | Assignee: | Oleksandr Byelkin |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
when using
or
the query cache 'parser' don't check for SQL_CACHE/SQL_NO_CACHE if it's not after "SELECT", we should check more bytes after "SELECT" to make sure we don't have "SQL_NO_CACHE"/"SQL_CACHE" hint, i think 50~100 bytes of search is ok, but we can have some situations like
or
or
must check what's a nice number to have as 'buffer size' to execute this "HINT" search
|
| Comments |
| Comment by Daniel Black [ 2014-11-19 ] |
|
rspadim as per your parent issue comment yes only a propper parse will probably do. ./sql/sql_parse.cc:mysql_parse contains some FIXMEs that seem to indicate this. Attempting to parse the query as just a SELECT before deciding on query_cache_send_result_to_client is one way, but looking at the bison generated parse code I'm out of my depth. |
| Comment by Elena Stepanova [ 2015-05-01 ] |
|
Can you provide a test case which demonstrates the actual problem? |
| Comment by roberto spadim [ 2015-05-01 ] |
|
hi Elena, well i can't "explain" with tests, but i can "explain" the "problem" 1) sql query -> check sql_cache/sql_no_cache hint -> seach query at query cache (SQL_CACHE) -> parser -> execute query -> return/save at query cache string search is faster and consume less cpu/memory than parser, that's not a bug/problem, but since we only execute string search we don't know if SQL_CACHE/SQL_NO_CACHE is really a "hint" or just a comment or something like it, and if it's not at the right order "SELECT SQL_CACHE" it don't optimize the query cache "check" in other words: |
| Comment by Elena Stepanova [ 2015-05-01 ] |
|
But shouldn't at least (3) be very easy to reproduce, if it's so? |
| Comment by roberto spadim [ 2015-05-03 ] |
|
short answer: it can be reproduced but not easily checked >QCache_inserts and QCache_queries_in_cache should show if SELECT SQL_SMALL_RESULT SQL_NO_CACHE ... is actually saved at query cache, or QCache_hits will show if it's taken from the query cache? no we don't have a status variable to sum how many queries was searched at query cache full answer: 1) CREATE DATABASE IF NOT EXISTS test well for test case i think it's ok, what you think? queries with SQL_NO_CACHE is never cached after query execution that could be tested with a qcache_info plugin, or "Qcache_queries_in_cache" variable after reseting query cache and executing two queries one with SQL_NO_CACHE and one with SQL_CACHE, queries cached must be = 1 ideas from this MDEV: to solve this useless search in any case, database should execute parser before query cache check and check if SQL_NO_CACHE exists or ignore (reducing cpu/memory use with parser before a cached query) and reporting a warning about SQL_NO_CACHE, for example: |
| Comment by Oleksandr Byelkin [ 2015-09-03 ] |
|
SQL_NO_CACHE in the query cache is just fast check to see it before parser (if we do not cache it so probably no sens to check cache because none of the query with SQL_NO_CACHE could be found in the cache) the check could fail, but then parser will care. Other misunderstanding here that SQL_CACHE could force caching in case of SQL_NO_CACHE: SQL_CACHE works only for on demand cache. |
| Comment by Oleksandr Byelkin [ 2015-09-03 ] |
|
My opinion is that it is not a bug. |
| Comment by Elena Stepanova [ 2015-09-03 ] |
|
If I understand Roberto's initial complaint correctly, he says that the current algorithm is sub-optimal performance-wise. However, currently it's just a theory. rspadim, if you can provide a proof-of-concept where the performance improvement from your suggestion will be clearly seen, please comment with it to re-open the issue. For now, I am closing it as sanja suggested. |
| Comment by roberto spadim [ 2015-09-03 ] |
|
hi guys if i execute — if i execute — if i execute — should be interesting report a warning to db client telling that SQL_NO_CACHE should be used after SELECT, avoiding a query cache check — the idea is always report warnings when using SQL_NO_CACHE and "check query cache" happen (when the SQL_NO_CACHE isn't after SELECT) |
| Comment by Elena Stepanova [ 2015-09-03 ] |
|
Looking at the syntax of SELECT command and definition of SQL_CACHE/SQL_NO_CACHE options, formally the complaint is justified (given that it's valid technically, I did not actually check). So, I think the better way to close this bug is probably not as 'Not a bug', but as 'Won't fix', and maybe add a note about it to our documentation to avoid further arguments about it. The only good reason to fix this bug would be a presence of a quantifiable proof that it would give considerable performance improvement, which I don't see so far. rspadim, do you have a patch which fixes the problem you are describing and shows the performance improvement? |
| Comment by roberto spadim [ 2015-09-03 ] |
|
this MDEV is related to MDEV-6631 |
| Comment by roberto spadim [ 2015-09-03 ] |
|
no i didn't included a patch that create warnings after parser, this should be something like: parser why FIRST? SELECT SQL_CACHE ..... FROM (SELECT SQL_NO_CACHE ...) AS t about performance, query cache check is only executed before parser, if we check query cache every time even with SQL_NO_CACHE we have a performace loss, i don't know if it's a O(1) O |
| Comment by roberto spadim [ 2015-09-03 ] |
|
MDEV-6631 show performace loss! |
| Comment by Elena Stepanova [ 2015-09-03 ] |
|
rspadim, Same goes for "feature requests" you were coming up with while commenting on this issue, they will simply be ignored, because they have nothing to do with the original complaint. All in all, theories are great, and undoubtedly every additional operation is a performance loss, but unless we have a quantifiable proof of performance loss that is meaningful in real life, it will stand little to no chance to be fixed. |
| Comment by roberto spadim [ 2015-09-03 ] |
|
mdev 6631 -> avoid when possible query cache check with SQL_CACHE / SQL_NO_CACHE hints (in this report that we checked query cache when it shouldn't be checked) |
| Comment by Oleksandr Byelkin [ 2015-09-04 ] |
|
1) SQL parser check it with any number of spaces and comments (see sql/sql_yacc.yy which is the parser description) |
| Comment by roberto spadim [ 2015-09-04 ] |
|
nice, no problem, should we document that sql_no_cache should be after first select to avoid one query cache check? |