Skip to content

re-organize the reuse chunk pool implementation #49661

@YangKeao

Description

@YangKeao

Enhancement

Sometimes, we re-used the chunk pool to avoid re-allocating memories across multiple statements. This chunk pool located in the "connection", and is set into session context when it's possible to re-use the allocator. This part of code is quite confusing:

  1. chunk.Allocator is not safe to call concurrently. Therefore, we always use GetNewChunkWithCapacity to allocate chunks from the allocator, and it'll use (*SessionVars).ChunkPool.mu to protect the allocator inside the BaseExecutor. It's reasonable because usually all BaseExecutor just used the ChunkPool in session context. However, just from the code, the relationship between the (*SessionVars).ChunkPool.mu and the BaseExecutor.Alloc is not significant.
  2. We expect to remove session context from the BaseExecutor, so we have to remove the GetNewChunkWithCapacity function call in the implementation of BaseExecutor.

And also, we'll need to use a session variable to tell whether the re-use chunk pool optimization is enabled. Also, we have a read-only session variable to tell the users whether last statement used the re-used chunk 🤦 . It's a little complicated.

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