pingcap / pingcap/tidb

planner: instance/node level plan cache - phase 1

Open
#54,057 0 comments 4 reactions 0 assignees View on GitHub
type/enhancement
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Enhancement
We only support Session Level Plan Cache now, which have 2 downsides:
1. Unnecessary memory consumption since different sessions might cache the same Plan, for example, on our prior test, the avg memory of a cached plan is [100KB](https://docs.pingcap.com/tidb/v6.1/sql-prepared-plan-cache#memory-management-of-prepared-plan-cache), so if there are 500 same sessions, 1000 plans of each, then the total memory consumptions is 100KB*500*1000=50GB; After we support Instance Level Plan Cache, it can be reduced 500 times to 100KB*1000=100MB.
2. Can't control the overall memory consumption of Plan Cache, instead we can only control memory consumption for each single session by using [tidb_session_plan_cache_size](https://docs.pingcap.com/tidb/stable/system-variables#tidb_session_plan_cache_size-new-in-v710).

Instance Level Plan Cache can solve these 2 problems, decrease the memory consumption and bring a higher cache hit ratio to improve performance further.

In phase-1 we're going to do 2 things:
1. a new performant and thread-safe LRU Cache for this feature;
2. solve the cross-session sharing problem to let the optimizer can share the same plan across multiple sessions at the same time safely;

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.