-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix cache_empty_result=0 not caching non-empty resultsets (issue #5248) #5250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The `cache_empty_result` field in query rules has three possible values: • -1: Use global setting (`query_cache_stores_empty_result`) • 0: Do NOT cache empty resultsets, but cache non-empty resultsets • 1: Always cache resultsets (both empty and non-empty) Previously, when `cache_empty_result` was set to 0, nothing was cached at all, even for non-empty resultsets. This prevented users from disabling caching for empty resultsets while still allowing caching of non-empty resultsets on a per-rule basis. Changes: 1. Modified caching logic in MySQL_Session.cpp and PgSQL_Session.cpp to add the condition `(qpo->cache_empty_result == 0 && MyRS->num_rows)` (MySQL) and `(qpo->cache_empty_result == 0 && num_rows)` (PgSQL) to allow caching when cache_empty_result=0 AND result has rows. 2. Added comprehensive Doxygen documentation in query_processor.h explaining the semantics of cache_empty_result values. 3. Updated Query_Processor.cpp with inline comments explaining the three possible values. Now when cache_empty_result is set to 0: - Empty resultsets (0 rows) are NOT cached - Non-empty resultsets (>0 rows) ARE cached - This matches the intended per-rule behavior described in issue #5248. Fixes: #5248
Summary of ChangesHello @renecannao, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a long-standing bug in the query caching mechanism where the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request addresses issue #5248 by fixing the behavior of the cache_empty_result setting in query rules. Previously, setting cache_empty_result to 0 would prevent all caching, even for non-empty result sets. The changes update the caching logic in MySQL_Session.cpp and PgSQL_Session.cpp to ensure that when cache_empty_result is 0, only non-empty result sets are cached, while empty ones are not. Additionally, detailed Doxygen-style comments have been added to include/query_processor.h and lib/Query_Processor.cpp to clarify the meaning of the cache_empty_result values (-1 for global setting, 0 for caching non-empty only, and 1 for always caching).
|



Summary
Fixes issue #5248: Setting
cache_empty_resultto "0" on individual mysql_query_rules doesn't work.Problem: When
cache_empty_resultis set to "0" on a query rule, nothing gets cached at all (even non-empty resultsets). According to the issue reporter, they want to disable caching for empty resultsets but still cache non-empty resultsets.Root Cause: The caching logic in
MySQL_Session.cppandPgSQL_Session.cpponly handled two cases:cache_empty_result == 1: Always cachecache_empty_result == -1: Use global setting OR cache if rows > 0Missing case:
cache_empty_result == 0: Cache only if rows > 0Solution: Added the missing condition
(qpo->cache_empty_result == 0 && MyRS->num_rows)(MySQL) /(qpo->cache_empty_result == 0 && num_rows)(PgSQL) to allow caching whencache_empty_result=0AND the resultset has rows.Changes:
cache_empty_result == 0cache_empty_result == 0cache_empty_resultfield explaining its three possible valuesSemantics of cache_empty_result:
query_cache_stores_empty_result)Testing Considerations: The fix maintains backward compatibility:
cache_empty_result=1: Still caches everythingcache_empty_result=-1: Still uses global setting OR caches non-empty resultscache_empty_result=0: Now correctly caches non-empty results (previously cached nothing)References:
lib/MySQL_Session.cpp:7497,lib/PgSQL_Session.cpp:4817