Skip to content

Commit

Permalink
planner: fix nil pointer at expression.(*CorrelatedColumn).Eval (#42789
Browse files Browse the repository at this point in the history
…) (#48975)

close #42739
  • Loading branch information
ti-chi-bot authored Nov 29, 2023
1 parent 2e29174 commit de6e2ba
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ func (b *PlanBuilder) buildAggregation(ctx context.Context, p LogicalPlan, aggFu
if _, ok = b.correlatedAggMapper[aggFuncList[j]]; !ok {
b.correlatedAggMapper[aggFuncList[j]] = &expression.CorrelatedColumn{
Column: *schema4Agg.Columns[aggIndexMap[j]],
Data: new(types.Datum),
}
}
b.correlatedAggMapper[aggFunc] = b.correlatedAggMapper[aggFuncList[j]]
Expand All @@ -270,6 +271,7 @@ func (b *PlanBuilder) buildAggregation(ctx context.Context, p LogicalPlan, aggFu
if _, ok := correlatedAggMap[aggFunc]; ok {
b.correlatedAggMapper[aggFunc] = &expression.CorrelatedColumn{
Column: column,
Data: new(types.Datum),
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions planner/core/prepare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3065,3 +3065,28 @@ func TestIssue42150(t *testing.T) {
tk.MustExec("execute st")
tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1"))
}

func TestIssue42739(t *testing.T) {
store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec(`use test`)
tk.MustExec("drop table if exists t0;")
tk.MustExec("CREATE TABLE t0 (c1 double, c2 double);")
tk.MustExec(`select
exists (
select
subq_2.c0 as c8
from
(select
ref_153.c1 as c0
from
t0 as ref_153
group by ref_153.c1 having 0 <> (
select 1
from
t0 as ref_173
where count(ref_153.c2) = avg(ref_153.c2)
order by c1 desc limit 1)) as subq_2
) as c10;`)
}

0 comments on commit de6e2ba

Please sign in to comment.