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: buildWindow cannot call typeInfer twice (#30773) #30865

Merged
merged 44 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
cbfbfc2
cherry pick #30773 to release-5.3
fzhedu Dec 20, 2021
6e8e743
fix conflict
guo-shaoge Feb 23, 2022
3b16f8b
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
guo-shaoge Feb 23, 2022
66d57a2
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Feb 23, 2022
a127aeb
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
guo-shaoge Feb 23, 2022
6280277
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
guo-shaoge Feb 23, 2022
d27401d
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
guo-shaoge Feb 23, 2022
6a217c5
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Feb 23, 2022
c612316
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Feb 23, 2022
1aa3eb7
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Feb 24, 2022
0d2d0b6
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
hawkingrei Apr 21, 2022
44a9909
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot May 23, 2022
cc3a800
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 14, 2022
8ccfe39
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 14, 2022
565fb56
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 14, 2022
07560ce
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 14, 2022
4d0f6f0
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 16, 2022
bf429a1
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 16, 2022
e8517db
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 16, 2022
3797521
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 16, 2022
2e07647
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 16, 2022
c7b2a00
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 16, 2022
6a0bdc4
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 16, 2022
7686b78
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 17, 2022
6e3d1c0
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 17, 2022
9249c04
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 17, 2022
3b50cb6
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 17, 2022
e5cead9
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 17, 2022
aa0d676
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 17, 2022
88811b9
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 17, 2022
d6e6ae9
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 17, 2022
5523ca5
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 17, 2022
e5944e1
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 17, 2022
abeb558
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 17, 2022
706b417
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 17, 2022
4719715
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 17, 2022
bcfbe7d
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 17, 2022
40abd23
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 17, 2022
f14377a
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 17, 2022
84db268
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 17, 2022
805c75b
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 17, 2022
acef08f
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 17, 2022
5b6f256
Merge branch 'release-5.3' into release-5.3-e3c56b75eaeb
ti-chi-bot Jun 20, 2022
61096bb
Update tiflash_test.go
fzhedu Jun 22, 2022
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
20 changes: 20 additions & 0 deletions executor/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,26 @@ func (s *testSuiteAgg) TestIssue23277(c *C) {
tk.MustExec("drop table t;")
}

func (s *testSuiteAgg) TestAvgDecimal(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test;")
tk.MustExec("drop table if exists td;")
tk.MustExec("create table td (col_bigint bigint(20), col_smallint smallint(6));")
tk.MustExec("insert into td values (null, 22876);")
tk.MustExec("insert into td values (9220557287087669248, 32767);")
tk.MustExec("insert into td values (28030, 32767);")
tk.MustExec("insert into td values (-3309864251140603904,32767);")
tk.MustExec("insert into td values (4,0);")
tk.MustExec("insert into td values (null,0);")
tk.MustExec("insert into td values (4,-23828);")
tk.MustExec("insert into td values (54720,32767);")
tk.MustExec("insert into td values (0,29815);")
tk.MustExec("insert into td values (10017,-32661);")
tk.MustQuery(" SELECT AVG( col_bigint / col_smallint) AS field1 FROM td;").Sort().Check(testkit.Rows("25769363061037.62077260"))
tk.MustQuery(" SELECT AVG(col_bigint) OVER (PARTITION BY col_smallint) as field2 FROM td where col_smallint = -23828;").Sort().Check(testkit.Rows("4.0000"))
tk.MustExec("drop table td;")
}

// https://github.com/pingcap/tidb/issues/23314
func (s *testSuiteAgg) TestIssue23314(c *C) {
tk := testkit.NewTestKit(c, s.store)
Expand Down
2 changes: 1 addition & 1 deletion executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4158,7 +4158,7 @@ func (b *executorBuilder) buildWindow(v *plannercore.PhysicalWindow) Executor {
partialResults := make([]aggfuncs.PartialResult, 0, len(v.WindowFuncDescs))
resultColIdx := v.Schema().Len() - len(v.WindowFuncDescs)
for _, desc := range v.WindowFuncDescs {
aggDesc, err := aggregation.NewAggFuncDesc(b.ctx, desc.Name, desc.Args, false)
aggDesc, err := aggregation.NewAggFuncDescForWindowFunc(b.ctx, desc, false)
if err != nil {
b.err = err
return nil
Expand Down
28 changes: 28 additions & 0 deletions executor/tiflash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,34 @@ func (s *tiflashTestSuite) TestUnionWithEmptyDualTable(c *C) {
tk.MustQuery("select count(*) from (select a , b from t union all select a , c from t1 where false) tt").Check(testkit.Rows("1"))
}

func (s *tiflashTestSuite) TestAvgOverflow(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")

// avg decimal
tk.MustExec("drop table if exists td;")
tk.MustExec("create table td (col_bigint bigint(20), col_smallint smallint(6));")
tk.MustExec("alter table td set tiflash replica 1")
tb := testGetTableByName(c, tk.Se, "test", "td")
err := domain.GetDomain(tk.Se).DDL().UpdateTableReplicaInfo(tk.Se, tb.Meta().ID, true)
c.Assert(err, IsNil)
tk.MustExec("insert into td values (null, 22876);")
tk.MustExec("insert into td values (9220557287087669248, 32767);")
tk.MustExec("insert into td values (28030, 32767);")
tk.MustExec("insert into td values (-3309864251140603904,32767);")
tk.MustExec("insert into td values (4,0);")
tk.MustExec("insert into td values (null,0);")
tk.MustExec("insert into td values (4,-23828);")
tk.MustExec("insert into td values (54720,32767);")
tk.MustExec("insert into td values (0,29815);")
tk.MustExec("insert into td values (10017,-32661);")
tk.MustExec("set @@session.tidb_isolation_read_engines=\"tiflash\"")
tk.MustExec("set @@session.tidb_enforce_mpp=ON")
tk.MustQuery(" SELECT AVG( col_bigint / col_smallint) AS field1 FROM td;").Sort().Check(testkit.Rows("25769363061037.62077260"))
tk.MustQuery(" SELECT AVG(col_bigint) OVER (PARTITION BY col_smallint) as field2 FROM td where col_smallint = -23828;").Sort().Check(testkit.Rows("4.0000"))
tk.MustExec("drop table if exists td;")
}

func (s *tiflashTestSuite) TestMppApply(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down
9 changes: 9 additions & 0 deletions expression/aggregation/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type AggFuncDesc struct {
}

// NewAggFuncDesc creates an aggregation function signature descriptor.
// this func cannot be called twice as the TypeInfer has changed the type of args in the first time.
func NewAggFuncDesc(ctx sessionctx.Context, name string, args []expression.Expression, hasDistinct bool) (*AggFuncDesc, error) {
b, err := newBaseFuncDesc(ctx, name, args)
if err != nil {
Expand All @@ -50,6 +51,14 @@ func NewAggFuncDesc(ctx sessionctx.Context, name string, args []expression.Expre
return &AggFuncDesc{baseFuncDesc: b, HasDistinct: hasDistinct}, nil
}

// NewAggFuncDescForWindowFunc creates an aggregation function from window functions, where baseFuncDesc may be ready.
func NewAggFuncDescForWindowFunc(ctx sessionctx.Context, Desc *WindowFuncDesc, hasDistinct bool) (*AggFuncDesc, error) {
if Desc.RetTp == nil { // safety check
return NewAggFuncDesc(ctx, Desc.Name, Desc.Args, hasDistinct)
}
return &AggFuncDesc{baseFuncDesc: baseFuncDesc{Desc.Name, Desc.Args, Desc.RetTp}, HasDistinct: hasDistinct}, nil
}

// String implements the fmt.Stringer interface.
func (a *AggFuncDesc) String() string {
buffer := bytes.NewBufferString(a.Name)
Expand Down