pingcap / pingcap/tidb

Provide a method to clone the `tableReaderExecutorContext`

Open
#52,847 0 comments 0 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 already have a small enough `tableReaderExecutorContext` to be cloned. Let's figure out how to clone each fields of it:

- `*distsqlctx.DistSQLContext`. Most of the fields in `DistSQLContext` is just a value and it's safe to clone. However, there are still some fields that need us to take care of:
- (Clone) `*tikvstore.Variables`. I'm not sure why it's a pointer, maybe some fields of it will be changed during execution :thinking: .
- (Optional) `*stmtstats.KvExecCounter`. It'll not be re-used for each statement, so it's safe to just use the reference directly.
- (No) `SessionMemTracker *memory.Tracker`. As it always points to the memory tracker on session, so it's safe to use the reference directly.
- (Optional) `*execdetails.RuntimeStatsColl`. It'll not be re-used, so use the reference directly is safe.
- (**TODO**) `*sqlkiller.SQLKiller`.
- (Optional) `*execdetails.SyncExecDetails`. It'll not be re-used, so it's safe to just use the reference directly.
- `*rangerctx.RangerContext`. Most of the fields are fine. We only need to re-build it with a cloned `WarnHandler`. We'll discuss `WarnHandler` field later.
- `*planctx.BuildPBContext`.
- [ ] `AppendWarning` and `AppendExtraWarning`. We'll need to refactor them into the `WarnHandler` before considering clone it.
- `exprctx.BuildContext`. We already have `StaticEvalContext` https://github.com/pingcap/tidb/pull/52631/files
- (Clone) `isctx.MetaOnlyInfoSchema`. The base of `MetaOnlyInfoSchema` is returned from `vars.SnapshotInfoschema`. It's not safe to use by different statements concurrently. Therefore, it'll need to be cloned.
- (No) `getDDLOwner`. The current implementation of `getDDLOwner` only depends on `ownerManager` (of `ddl`), which is safe to be used in multiple statements.

## Fields which are used across many contexts

- `Warnhandler`. It's widely used in `errctx`, `typectx` and many other contexts, which means that we'll need to re-build all these contexts according to the dependency.
- `kv.Client`. **TODO**. I'm not sure whether it can be used in parallel statement 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.