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

executor: support Chunk in LimitExec #5200

Merged
merged 17 commits into from
Nov 28, 2017
Merged

Conversation

zz-jason
Copy link
Member

No description provided.

@zz-jason zz-jason added the WIP label Nov 23, 2017
@zz-jason zz-jason removed the WIP label Nov 23, 2017
@zz-jason
Copy link
Member Author

/run-all-tests

if src.isFixed() {
elemLen := len(src.elemBuf)
if len(dst.data) < elemLen*(end-begin) {
dst.data = make([]byte, elemLen*(end-begin), elemLen*(end-begin))
Copy link
Member

@coocood coocood Nov 23, 2017

Choose a reason for hiding this comment

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

If we make data here, we won't be able to reuse the memory.

if len(dst.nullBitmap) < numBytesInBitmap {
dst.nullBitmap = make([]byte, numBytesInBitmap)
}
for i := begin; i < end; i++ {
Copy link
Member

Choose a reason for hiding this comment

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

We should be able to append the bitmap bytes directly, in the case of not aligned, we can shift the bitmap.

col.data = col.data[:(col.length-tailRows)*elemLen]
} else if col.isVarlen() {
col.data = col.data[:col.offsets[col.length-tailRows+1]]
col.offsets = col.offsets[:col.length-tailRows]
Copy link
Member

Choose a reason for hiding this comment

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

The length of offsets is larger than col.length by 1.

@coocood
Copy link
Member

coocood commented Nov 26, 2017

@zz-jason
Please add tests for Append and Truncate.

src.AppendNull(1)
src.AppendNull(2)

for i := 0; i < 7; i++ {
Copy link
Member

Choose a reason for hiding this comment

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

Why not i < 8 to save the above 6 lines?

if e.cursor > e.end {
batchSize -= e.cursor - e.end
}
fmt.Printf("matched, batchSize: %v\n", batchSize)
Copy link
Member

Choose a reason for hiding this comment

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

remove the debug log.

if batchSize == 0 {
return nil
}
e.cursor += batchSize
Copy link
Member

Choose a reason for hiding this comment

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

I think to update the cursor after we append the data is easier to understand.
Then the cursor will never be greater than e.end.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not that hard to understand and if we update cursor after appending data the code will be more or less ugly.

Copy link
Member

Choose a reason for hiding this comment

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

I think there is a way to make the code easier to understand.

return errors.Trace(err)
}
e.cursor = 0
e.meetFirstBatch = false
Copy link
Member

Choose a reason for hiding this comment

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

If the offset is 0, we can set meetFirstBatch to true

}

// Truncate truncates "tailRows" rows from the tail..
func (c *Chunk) Truncate(tailRows int) {
Copy link
Member

Choose a reason for hiding this comment

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

I think truncate to length is more commonly used.

if batchSize == 0 {
return nil
}
if e.cursor > e.end {
Copy link
Member

Choose a reason for hiding this comment

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

Should update cursor before this check.
Seems not covered by tests.

@coocood
Copy link
Member

coocood commented Nov 27, 2017

@zz-jason
We need to write test cases for multiple chunk limit.
Our existing tests usually have a small row count, less than one chunk.

@zz-jason
Copy link
Member Author

@coocood we can add a session variable to control max chunk capacity, before testing, we can set a small chunk size, like 2.

@coocood
Copy link
Member

coocood commented Nov 27, 2017

LGTM

@zz-jason zz-jason added the status/LGT1 Indicates that a PR has LGTM 1. label Nov 27, 2017
@zz-jason zz-jason added this to the 1.1 milestone Nov 27, 2017
end uint64
cursor uint64

meetFirstBatch bool
Copy link
Contributor

Choose a reason for hiding this comment

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

add a comment for this

@@ -146,6 +149,51 @@ func (c *Chunk) AppendRow(colIdx int, row Row) {
}
}

// Append appends rows in [begin, end) in another Chunk to a Chunk.
func (c *Chunk) Append(other *Chunk, begin, end int) {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we check the validation of begin and end first.

Copy link
Member Author

Choose a reason for hiding this comment

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

no need to, all Chunk's API should not do the validation work.

}

// TruncateTo truncates rows from tail to head in a Chunk to "numRows" rows.
func (c *Chunk) TruncateTo(numRows int) {
Copy link
Contributor

Choose a reason for hiding this comment

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

check validation of numRows?

@zz-jason
Copy link
Member Author

/run-all-tests tidb-test=pr/411

@zz-jason
Copy link
Member Author

@XuHuaiyu PTAL

@XuHuaiyu
Copy link
Contributor

LGTM

@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 Nov 28, 2017
@XuHuaiyu XuHuaiyu merged commit 5b73623 into pingcap:master Nov 28, 2017
@zz-jason zz-jason deleted the dev/chunk/limit branch November 28, 2017 08:33
@zz-jason zz-jason mentioned this pull request Nov 29, 2017
41 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants