-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Querying
-
Query Execution
-
Query 2020-12-14, Query 2020-12-28
Today the plan cache is protected by a single coarse-grain mutex. We have recently seen a case where this mutex was a bottleneck when many threads were calling PlanCache::get(). The query was relatively complex, which made copying CachedSolutions (a complex tree data structure roughly proportional to the size of the plan) from the cache expensive. Copying CachedSolutions is (and must be) done while holding the plan cache mutex.
We could get rid of the bottleneck in this situation by using a read-write lock in the plan cache.
We could also introduce a versioning mechanism where each thread calling PlanCache::get() gets a pointer to a "version" of a CachedSolution, avoiding the copy altogether. Writes to the plan cache (done via replanning, and other less frequent events) would introduce a new "version." Old versions could be removed via reference counting.
It's important to note that simply partitioning the plan cache would not actually help in many scenarios. Users may (often) run many queries of the same shape simultaneously, in which case all of the operations would end up reading from the same partition.
I suspect that this will be an important improvement to make before making the plan cache process-global (SERVER-40360).
- is related to
-
SERVER-90940 Partition the Classic plan cache to reduce lock contention
- Open