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: introduce a new execution framework for aggregate functions #6852

Merged
merged 24 commits into from
Jun 29, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
182658b
executor: refactor aggregate functions
zz-jason Jun 17, 2018
01ec369
change type name
zz-jason Jun 20, 2018
faa3f7d
Merge branch 'master' into dev/refactor-agg
zz-jason Jun 21, 2018
1ebf4d5
Merge branch 'master' into dev/refactor-agg
zz-jason Jun 21, 2018
038135a
Merge branch 'master' into dev/refactor-agg
zz-jason Jun 21, 2018
7f1fd3a
handle distinct in partial1 and complete mode
zz-jason Jun 21, 2018
e5acefb
handle 0 count
zz-jason Jun 21, 2018
e25d273
Merge branch 'master' into dev/refactor-agg
zz-jason Jun 22, 2018
dca132a
add implementation of SUM
zz-jason Jun 23, 2018
81c812b
Merge branch 'dev/refactor-agg' of https://github.com/zz-jason/tidb i…
zz-jason Jun 23, 2018
cacad7c
add missing file
zz-jason Jun 23, 2018
d3a1ced
only introduce the framework in this PR
zz-jason Jun 24, 2018
cf34a16
remove useless code
zz-jason Jun 24, 2018
b1335c3
remove debug log
zz-jason Jun 24, 2018
ce821f9
Merge branch 'master' into dev/refactor-agg
zz-jason Jun 24, 2018
dbbef24
fix ci
zz-jason Jun 24, 2018
57f57b8
Merge branch 'dev/refactor-agg' of https://github.com/zz-jason/tidb i…
zz-jason Jun 24, 2018
5f17822
address comment
zz-jason Jun 25, 2018
aa71782
address comment
zz-jason Jun 25, 2018
f3b005f
address comment
zz-jason Jun 26, 2018
c7f7144
Merge branch 'master' into dev/refactor-agg
lysu Jun 28, 2018
66801be
Merge branch 'master' into dev/refactor-agg
zz-jason Jun 28, 2018
0d859db
addres comment
zz-jason Jun 29, 2018
7f8134c
Merge branch 'master' into dev/refactor-agg
coocood Jun 29, 2018
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
16 changes: 13 additions & 3 deletions executor/aggfuncs/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/pingcap/tidb/ast"
"github.com/pingcap/tidb/expression/aggregation"
"github.com/pingcap/tidb/mysql"
"github.com/pingcap/tidb/types"
)

// Build is used to build AggFunc according to the aggFuncDesc
Expand Down Expand Up @@ -80,11 +81,20 @@ func buildAvg(aggFuncDesc *aggregation.AggFuncDesc, output []int) AggFunc {
case aggregation.CompleteMode, aggregation.Partial1Mode:
switch aggFuncDesc.Args[0].GetType().Tp {
Copy link
Contributor

Choose a reason for hiding this comment

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

we should consider all the input types,
use EvalType here may be better?

case mysql.TypeNewDecimal:
return &avgOriginal4Decimal{baseAvgDecimal{base}}
if aggFuncDesc.HasDistinct {
return &avgOriginal4Decimal{baseAvgDecimal{base}, make(map[types.MyDecimal]bool)}
}
return &avgOriginal4Decimal{baseAvgDecimal{base}, nil}
case mysql.TypeFloat:
return &avgOriginal4Float32{baseAvgFloat32{base}}
if aggFuncDesc.HasDistinct {
return &avgOriginal4Float32{baseAvgFloat32{base}, make(map[float32]bool)}
}
return &avgOriginal4Float32{baseAvgFloat32{base}, nil}
case mysql.TypeDouble:
return &avgOriginal4Float64{baseAvgFloat64{base}}
if aggFuncDesc.HasDistinct {
return &avgOriginal4Float64{baseAvgFloat64{base}, make(map[float64]bool)}
}
return &avgOriginal4Float64{baseAvgFloat64{base}, nil}
}

// Build avg functions which consume the partial result of other agg
Expand Down
18 changes: 15 additions & 3 deletions executor/aggfuncs/func_avg.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func (e *avgDedup4Decimal) UpdatePartialResult(sctx sessionctx.Context, rowsInGr

type avgOriginal4Decimal struct {
baseAvgDecimal
deDuper map[types.MyDecimal]bool
Copy link
Contributor

Choose a reason for hiding this comment

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

deDuper should be initialized

}

func (e *avgOriginal4Decimal) UpdatePartialResult(sctx sessionctx.Context, rowsInGroup []chunk.Row, partialBytes []byte) error {
Expand All @@ -109,7 +110,7 @@ func (e *avgOriginal4Decimal) UpdatePartialResult(sctx sessionctx.Context, rowsI
input, isNull, err := e.input[0].EvalDecimal(sctx, row)
if err != nil {
return errors.Trace(err)
} else if isNull {
} else if isNull || (e.deDuper != nil && e.deDuper[*input]) {
continue
}
err = types.DecimalAdd(&partialResult.sum, input, newSum)
Expand All @@ -118,6 +119,9 @@ func (e *avgOriginal4Decimal) UpdatePartialResult(sctx sessionctx.Context, rowsI
}
partialResult.sum = *newSum
partialResult.count++
if e.deDuper != nil {
e.deDuper[*input] = true
}
}
return nil
}
Expand Down Expand Up @@ -207,6 +211,7 @@ func (e *avgDedup4Float64) UpdatePartialResult(sctx sessionctx.Context, rowsInGr

type avgOriginal4Float64 struct {
baseAvgFloat64
deDuper map[float64]bool
}

func (e *avgOriginal4Float64) UpdatePartialResult(sctx sessionctx.Context, rowsInGroup []chunk.Row, partialBytes []byte) error {
Expand All @@ -215,11 +220,14 @@ func (e *avgOriginal4Float64) UpdatePartialResult(sctx sessionctx.Context, rowsI
input, isNull, err := e.input[0].EvalReal(sctx, row)
if err != nil {
return errors.Trace(err)
} else if isNull {
} else if isNull || (e.deDuper != nil && e.deDuper[input]) {
continue
}
partialResult.sum += input
partialResult.count++
if e.deDuper != nil {
e.deDuper[input] = true
}
}
return nil
}
Expand Down Expand Up @@ -303,6 +311,7 @@ func (e *avgDedup4Float32) UpdatePartialResult(sctx sessionctx.Context, rowsInGr

type avgOriginal4Float32 struct {
baseAvgFloat32
deDuper map[float32]bool
}

func (e *avgOriginal4Float32) UpdatePartialResult(sctx sessionctx.Context, rowsInGroup []chunk.Row, partialBytes []byte) error {
Expand All @@ -311,11 +320,14 @@ func (e *avgOriginal4Float32) UpdatePartialResult(sctx sessionctx.Context, rowsI
input, isNull, err := e.input[0].EvalReal(sctx, row)
if err != nil {
return errors.Trace(err)
} else if isNull {
} else if isNull || (e.deDuper != nil && e.deDuper[float32(input)]) {
continue
}
partialResult.sum += float32(input)
partialResult.count++
if e.deDuper != nil {
e.deDuper[float32(input)] = true
}
}
return nil
}
Expand Down