-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
*: use chunk grow for simple executor #7540
Conversation
/run-all-tests |
executor/builder.go
Outdated
@@ -420,8 +421,9 @@ func (b *executorBuilder) buildLimit(v *plan.PhysicalLimit) Executor { | |||
b.err = errors.Trace(b.err) | |||
return nil | |||
} | |||
n := int(mathutil.MinUint64(v.Count, math.MaxInt64)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why math.MaxInt64
?
distsql/distsql_test.go
Outdated
@@ -69,7 +69,7 @@ func (s *testSuite) TestSelectNormal(c *C) { | |||
response.Fetch(context.TODO()) | |||
|
|||
// Test Next. | |||
chk := chunk.NewChunkWithCapacity(colTypes, 32) | |||
chk := chunk.New(colTypes, 32, 32*3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why 32*3?
executor/executor.go
Outdated
@@ -102,7 +103,7 @@ func (e *baseExecutor) Schema() *expression.Schema { | |||
|
|||
// newChunk creates a new chunk to buffer current executor's result. | |||
func (e *baseExecutor) newChunk() *chunk.Chunk { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that after this patch, newChunk
should only be called once in the parent operator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about renaming it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lysu how about renaming it to newFirstChk()
executor/executor.go
Outdated
@@ -133,6 +135,16 @@ func newBaseExecutor(ctx sessionctx.Context, schema *expression.Schema, id strin | |||
return e | |||
} | |||
|
|||
func (e baseExecutor) withInitCap(initCap int) (ret baseExecutor) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about:
s/withInitCap/setInitCap/
- don't return
baseExecutor
, because this object takes a lot of memory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
withXX
and return is common chain builder pattern, I test that go compiler can inline but still do return alloc and copy as you said , so we back to ugly way 🤣
util/chunk/chunk.go
Outdated
@@ -38,6 +38,7 @@ type Chunk struct { | |||
// Capacity constants. | |||
const ( | |||
InitialCapacity = 32 | |||
NoDataChunkCap = -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about:
ZeroCapacity = 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0
is ok, but it will still alloc columns and field num of column.. use magic -1 we can alloc less.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
considered there is a InitialCapacity
, I think ZeroCapacity
is more suitable.
@XuHuaiyu PTAL |
session/session.go
Outdated
@@ -553,7 +553,7 @@ func (s *session) ExecRestrictedSQL(sctx sessionctx.Context, sql string) ([]chun | |||
) | |||
// Execute all recordset, take out the first one as result. | |||
for i, rs := range recordSets { | |||
tmp, err := drainRecordSet(ctx, rs) | |||
tmp, err := drainRecordSet(ctx, sctx, rs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it is better to use se
here because it is the session that is used to execute the sql.
executor/executor.go
Outdated
e.initCap = initCap | ||
} | ||
|
||
func (e *baseExecutor) setMaxChunkSize(maxChunkSize int) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be removed?
executor/executor.go
Outdated
@@ -133,6 +135,14 @@ func newBaseExecutor(ctx sessionctx.Context, schema *expression.Schema, id strin | |||
return e | |||
} | |||
|
|||
func (e *baseExecutor) setInitCap(initCap int) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe these kind of setters can be removed?
- the function is not exported to be used as an API.
- the function logic is too simple.
@@ -121,6 +122,7 @@ func newBaseExecutor(ctx sessionctx.Context, schema *expression.Schema, id strin | |||
ctx: ctx, | |||
id: id, | |||
schema: schema, | |||
initCap: ctx.GetSessionVars().MaxChunkSize, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should set to math.Min(chunk.InitialCapacity, ctx.GetSessionVars().MaxChunkSize)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this PR, we can not do that, because JOIN relate modification will in next PR which will make grow real work.
then we will make initCap be configurable and check constrait in set config stage.
@@ -296,6 +293,10 @@ func (p *MySQLPrivilege) loadTable(sctx sessionctx.Context, sql string, | |||
return errors.Trace(err) | |||
} | |||
} | |||
// NOTE: decodeTableRow decodes data from a chunk Row, that is a shallow copy. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please read the NOTE once again! @lysu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, in here, use Renew
will always create a new chunk just like old logic 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
PTAL @XuHuaiyu |
fping @XuHuaiyu |
LGTM |
util/chunk/chunk.go
Outdated
@@ -38,6 +38,7 @@ type Chunk struct { | |||
// Capacity constants. | |||
const ( | |||
InitialCapacity = 32 | |||
ZeroCapacity = -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ZeroCapacity = 0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/run-all-tests |
/run-all-tests |
What problem does this PR solve?
ref issue #7077 and base on PR #7473
in this PR we start to make executor use chunk grow.
What is changed and how it works?
There are several small modification in this PR.
ChunkList
use chunk grow, more bigger chunk node as more chunk node insertedPrepare
,Deallocate
,Simple
,Set
,Insert
,Dual
,Sort
,MaxOneRow
,Update
,Delete
,TopN
,Limit
useNoDataCap
for exec result chunkCancelDDLJobsExec
,ShowDDLJobQueriesExec
,ShowDDLJobsExec
,SelectionExec
,TableScanExec
,ExplainExec
,ShowExec
,UnionScanExec
check batch size usechunk.Capacity()
instead ofbaseExecutor.maxChunkSize
GrowAndReset
to replaceReset
in some executorschunk.NewChunkWithCapacity
(which will be depercated soon) withchunk.New
This PR doesn't modify join/agg/distsql/sort operators which are the most sophisticated. We will handle them in next PR.
Check List
Tests
Code changes
Side effects
Related changes
This change is