Skip to content
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

Merged
merged 13 commits into from
Sep 27, 2018
Merged

*: use chunk grow for simple executor #7540

merged 13 commits into from
Sep 27, 2018

Conversation

lysu
Copy link
Contributor

@lysu lysu commented Aug 29, 2018

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.

  • modify ChunkList use chunk grow, more bigger chunk node as more chunk node inserted
  • Prepare, Deallocate, Simple, Set, Insert, Dual, Sort, MaxOneRow, Update, Delete, TopN, Limit use NoDataCap for exec result chunk
  • CancelDDLJobsExec, ShowDDLJobQueriesExec, ShowDDLJobsExec, SelectionExec, TableScanExec, ExplainExec, ShowExec, UnionScanExec check batch size use chunk.Capacity() instead of baseExecutor.maxChunkSize
  • use GrowAndReset to replace Reset in some executors
  • replace some chunk.NewChunkWithCapacity(which will be depercated soon) with chunk.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

  • Unit test
  • Integration test

Code changes

  • Refactor

Side effects

  • No

Related changes

  • No for this PR.

This change is Reviewable

@lysu lysu added type/enhancement The issue or PR belongs to an enhancement. status/WIP sig/execution SIG execution labels Aug 29, 2018
@lysu
Copy link
Contributor Author

lysu commented Aug 29, 2018

/run-all-tests

@lysu lysu removed the status/WIP label Sep 3, 2018
@@ -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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why math.MaxInt64?

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why 32*3?

@@ -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 {
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes~

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about renaming it?

Copy link
Member

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()

@@ -133,6 +135,16 @@ func newBaseExecutor(ctx sessionctx.Context, schema *expression.Schema, id strin
return e
}

func (e baseExecutor) withInitCap(initCap int) (ret baseExecutor) {
Copy link
Member

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

Copy link
Contributor Author

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 🤣

@@ -38,6 +38,7 @@ type Chunk struct {
// Capacity constants.
const (
InitialCapacity = 32
NoDataChunkCap = -1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about:

ZeroCapacity = 0

Copy link
Contributor Author

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.

Copy link
Member

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.

@zz-jason
Copy link
Member

@XuHuaiyu PTAL

@@ -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)
Copy link
Contributor

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.

e.initCap = initCap
}

func (e *baseExecutor) setMaxChunkSize(maxChunkSize int) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be removed?

@@ -133,6 +135,14 @@ func newBaseExecutor(ctx sessionctx.Context, schema *expression.Schema, id strin
return e
}

func (e *baseExecutor) setInitCap(initCap int) {
Copy link
Member

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?

  1. the function is not exported to be used as an API.
  2. 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,
Copy link
Member

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)?

Copy link
Contributor Author

@lysu lysu Sep 25, 2018

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.
Copy link
Contributor

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

Copy link
Contributor Author

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 😆

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@lysu
Copy link
Contributor Author

lysu commented Sep 25, 2018

PTAL @XuHuaiyu

@lysu
Copy link
Contributor Author

lysu commented Sep 26, 2018

fping @XuHuaiyu

@tiancaiamao
Copy link
Contributor

LGTM

@tiancaiamao tiancaiamao added the status/LGT1 Indicates that a PR has LGTM 1. label Sep 26, 2018
@@ -38,6 +38,7 @@ type Chunk struct {
// Capacity constants.
const (
InitialCapacity = 32
ZeroCapacity = -1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ZeroCapacity = 0?

Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zz-jason
Copy link
Member

/run-all-tests

@zz-jason zz-jason added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Sep 26, 2018
@lysu
Copy link
Contributor Author

lysu commented Sep 26, 2018

/run-all-tests

@zz-jason zz-jason merged commit 05b37de into pingcap:master Sep 27, 2018
@lysu lysu deleted the dev-simple-executor-chunk branch September 27, 2018 03:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution status/LGT2 Indicates that a PR has LGTM 2. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants