Skip to content

planner: instance/node level plan cache - phase 1 #54057

@qw4990

Description

@qw4990

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, so if there are 500 same sessions, 1000 plans of each, then the total memory consumptions is 100KB5001000=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.

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/enhancementThe issue or PR belongs to an enhancement.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions