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 MAX/MIN in new evaluation framework partially #6971

Merged
merged 17 commits into from
Jul 12, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions executor/aggfuncs/func_max_min.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type partialResult4MaxMinUint struct {
}

type partialResult4MaxMinDecimal struct {
val *types.MyDecimal
val types.MyDecimal
isNull bool
}

Expand Down Expand Up @@ -138,14 +138,14 @@ func (e *maxMin4Uint) UpdatePartialResult(sctx sessionctx.Context, rowsInGroup [
if isNull {
continue
}
i := uint64(input)
uintVal := uint64(input)
if p.isNull {
p.val = i
p.val = uintVal
p.isNull = false
continue
}
if e.isMax && i > p.val || !e.isMax && i < p.val {
p.val = i
if e.isMax && uintVal > p.val || !e.isMax && uintVal < p.val {
p.val = uintVal
}
Copy link
Contributor

Choose a reason for hiding this comment

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

        uint64Input := uint64(input)
		if !e.executed {
			*p = uint64Input
			e.executed = true
			continue
		}
		if e.isMax && uint64Input > *p || !e.isMax && uint64Input < *p {
			*p = uint64Input
		}

}
return nil
Expand Down Expand Up @@ -255,13 +255,14 @@ type maxMin4Decimal struct {

func (e *maxMin4Decimal) AllocPartialResult() PartialResult {
p := new(partialResult4MaxMinDecimal)
p.val = *new(types.MyDecimal)
Copy link
Member

Choose a reason for hiding this comment

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

This operation can be removed? since we only set it once the first non-NULL value comes.

p.isNull = true
return PartialResult(p)
}

func (e *maxMin4Decimal) ResetPartialResult(pr PartialResult) {
p := (*partialResult4MaxMinDecimal)(pr)
p.val = new(types.MyDecimal)
p.val = *new(types.MyDecimal)
Copy link
Member

Choose a reason for hiding this comment

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

ditto

p.isNull = true
}

Expand All @@ -271,7 +272,7 @@ func (e *maxMin4Decimal) AppendFinalResult2Chunk(sctx sessionctx.Context, pr Par
chk.AppendNull(e.ordinal)
return nil
}
chk.AppendMyDecimal(e.ordinal, p.val)
chk.AppendMyDecimal(e.ordinal, &p.val)
return nil
}

Expand All @@ -286,13 +287,13 @@ func (e *maxMin4Decimal) UpdatePartialResult(sctx sessionctx.Context, rowsInGrou
continue
}
if p.isNull {
p.val = input
p.val = *input
p.isNull = false
continue
}
cmp := input.Compare(p.val)
cmp := input.Compare(&p.val)
if e.isMax && cmp == 1 || !e.isMax && cmp == -1 {
p.val = input
p.val = *input
}
Copy link
Contributor

@crazycs520 crazycs520 Jul 6, 2018

Choose a reason for hiding this comment

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

                cmp := input.Compare(*p)
		if e.isMax && cmp == 1 || !e.isMax && cmp == -1 {
			*p = input
		}

}
return nil
Expand Down