Repository navigation
feat(query): Query Plan Caching — v1.7.0 (Issue #196) - #4229
Merged
Merged
Conversation
Co-authored-by: makr-code <[email protected]>
Copilot
AI
changed the title
[WIP] Implement query plan caching for optimized performance
feat(query): Query Plan Caching — v1.7.0 (Issue #196)
Mar 14, 2026
makr-code
marked this pull request as ready for review
March 14, 2026 17:54
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a thread-safe query plan cache (LRU + TTL + stats-drift invalidation), wires it into build/test infrastructure, and introduces a focused unit test suite to validate the feature against Issue #196.
Changes:
- Introduces
PlanCache(SHA256 fingerprinting, LRU eviction, lazy TTL expiry, stats drift invalidation, table-based invalidation, cache stats). - Adds focused GTest suite + registers dedicated CTest target for plan caching acceptance criteria.
- Updates build system and adds a dedicated CI workflow for the new focused tests (also fixes a missing
endif()intests/CMakeLists.txt).
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
include/query/plan_cache.h |
Declares PlanCache API, config, cached-entry metadata, and statistics reporting. |
src/query/plan_cache.cpp |
Implements cache behavior: fingerprinting, get/put, LRU, TTL eviction, drift checks, and table invalidation. |
tests/test_query_plan_caching.cpp |
Adds focused unit tests covering fingerprinting, reuse, invalidation, drift, TTL, LRU, and stats accuracy. |
tests/CMakeLists.txt |
Registers a new focused test executable + fixes a missing endif(). |
cmake/CMakeLists.txt |
Adds plan_cache.cpp to core sources. |
cmake/ModularBuild.cmake |
Adds plan_cache.cpp to the query module sources. |
src/query/ROADMAP.md |
Marks query plan caching as completed for the roadmap. |
.github/workflows/query-plan-caching-ci.yml |
Adds targeted CI workflow to build and run the focused plan caching tests. |
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+146
to
+150
| // Non-copyable | ||
| PlanCache(const PlanCache&) = delete; | ||
| PlanCache& operator=(const PlanCache&) = delete; | ||
| PlanCache(PlanCache&&) = default; | ||
| PlanCache& operator=(PlanCache&&) = default; |
| * parameterized query can skip the parse + optimize phases. | ||
| * | ||
| * Features: | ||
| * - Plan fingerprinting (SHA256 of query structure + statistics snapshot) |
Comment on lines
+134
to
+135
| auto& fps = table_index_[tbl]; | ||
| fps.erase(std::remove(fps.begin(), fps.end(), fp), fps.end()); |
| #include <gtest/gtest.h> | ||
| #include <chrono> | ||
| #include <string> | ||
| #include <thread> |
Comment on lines
+142
to
+145
| // Evict LRU if at capacity | ||
| while (stats_.current_size >= config_.max_entries && !cache_.empty()) { | ||
| evictLRU_locked(); | ||
| } |
…vered Co-authored-by: makr-code <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements
PlanCacheinsrc/query/— a thread-safe LRU cache forQueryOptimizer::Planobjects that allows repeated parameterized queries to skip parse + optimize entirely.Description
Core:
include/query/plan_cache.h+src/query/plan_cache.cppget()(default 24 h viamax_plan_age)>= 10×cardinality change on any referenced table → automatic invalidationinvalidateTable(name)drops all plans touching a table via anunordered_map<table→fps>indexCachedPlancarriesStatisticssnapshot,ParameterInfobind-param metadata, and referenced-table liststd::mutex;CacheStats(hits/misses/evictions/drifts) viagetStats()Tests:
tests/test_query_plan_caching.cpp— 35 focused unit tests inQueryPlanCachingFocusedTestscovering all 7 acceptance criteria: fingerprint determinism/collision, parameterized reuse, table invalidation (single/multi/sequential), stats drift (both directions, boundary, zero, missing table), 24 h TTL expiry, LRU eviction, andCacheStatsaccuracy.Build integration
src/query/plan_cache.cppadded tocmake/CMakeLists.txtandcmake/ModularBuild.cmaketest_query_plan_caching_focusedregistered intests/CMakeLists.txt; also fixes a pre-existing missingendif()that blocked test builds.github/workflows/query-plan-caching-ci.yml— Ubuntu 22/24, GCC 12/13; cmake flags include-DTHEMIS_ENABLE_MIMALLOC=OFF -DTHEMIS_BUILD_BENCHMARKS=OFFto avoid configure failures on clean runnersDocs
src/query/ROADMAP.md— feature marked[x]completesrc/query/FUTURE_ENHANCEMENTS.md— delivered note added to Query Plan Caching section (matches vectorized-execution-engine convention)Type of Change
Testing
📚 Research & Knowledge (wenn applicable)
/docs/research/angelegt?/docs/research/implementation_influence/eingetragen?Relevante Quellen:
Checklist
Original prompt
📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.