-
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
executor: support the remained types for max/min #7056
Conversation
LGTM |
/run-all-tests |
@XuHuaiyu please add some labels |
LGTM |
/run-common-test tidb-test=pr/578 |
/run-common-test tidb-test=pr/578 |
I tried these ways @zz-jason
BenchmarkCopyString-4 10000000 132 ns/op 19 B/op 2 allocs/op |
@XuHuaiyu |
/run-all-tests tidb-test=pr/578 |
@XuHuaiyu BenchmarkCopyString2 is not correct, it have not copy import . "github.com/pingcap/tidb/util/hack"
func TestStringcs(t *testing.T) {
a := "abc"
b := a + ""
bufA := Slice(a)
bufB := Slice(b)
fmt.Println(&bufA[0], &bufB[0]) // the adress is same
} Another question: Why we need to copy string? string cannot be modified after create. |
@@ -290,9 +311,202 @@ func (e *maxMin4Decimal) UpdatePartialResult(sctx sessionctx.Context, rowsInGrou | |||
continue | |||
} | |||
cmp := input.Compare(&p.val) | |||
if e.isMax && cmp == 1 || !e.isMax && cmp == -1 { | |||
if e.isMax && cmp > 0 || !e.isMax && cmp < 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.
Why only change this line? line#363,411?
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.
caused by the implementation of different compare
function.
executor/aggfuncs/func_max_min.go
Outdated
} | ||
if p.isNull { | ||
// We need to copy the value of input to avoid the original value be covered. | ||
p.val = "" + input |
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.
Better wrap it as a method in util package.
util/stringutil/string_util.go
Outdated
@@ -234,3 +235,8 @@ func DoMatch(str string, patChars, patTypes []byte) bool { | |||
} | |||
return sIdx == len(str) | |||
} | |||
|
|||
// CopyString deep copies a string. | |||
func CopyString(src string) string { |
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/CopyString/Copy/
? We usually call the function with the package name, "stringutil.Copy()" would be simpler.
@@ -234,3 +235,8 @@ func DoMatch(str string, patChars, patTypes []byte) bool { | |||
} | |||
return sIdx == len(str) | |||
} | |||
|
|||
// Copy deep copies a string. |
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.
add comment why we need to copy a string. because the string is hack
from byte(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.
no need to add it here, should add the comments in the caller side.
/run-all-tests tidb-test=pr/578 |
What have you changed? (mandatory)
support String/ Time/ Duration/ JSON for max/min
What is the type of the changes? (mandatory)
How has this PR been tested? (mandatory)
The existing test cases.
randgen-test
Does this PR affect documentation (docs/docs-cn) update? (mandatory)
no
Does this PR affect tidb-ansible update? (mandatory)
no
Does this PR need to be added to the release notes? (mandatory)
no
Refer to a related PR or issue link (optional)
#6952
Benchmark result if necessary (optional)
Add a few positive/negative examples (optional)