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
…) (#48974)

close #42739
  • Loading branch information
ti-chi-bot authored Nov 29, 2023
1 parent 7eb094b commit 9c074a2
Show file tree
Hide file tree
Showing 2 changed files with 41 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 @@ -243,6 +243,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 @@ -264,6 +265,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
39 changes: 39 additions & 0 deletions planner/core/prepare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2331,6 +2331,45 @@ func (s *testPrepareSerialSuite) TestIssue28246(c *C) {
tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1"))
}

func (s *testPrepareSerialSuite) TestIssue42739(c *C) {
defer testleak.AfterTest(c)()
store, dom, err := newStoreWithBootstrap()
c.Assert(err, IsNil)
tk := testkit.NewTestKit(c, store)
orgEnable := core.PreparedPlanCacheEnabled()
defer func() {
dom.Close()
err = store.Close()
c.Assert(err, IsNil)
core.SetPreparedPlanCache(orgEnable)
}()
core.SetPreparedPlanCache(true)
tk.Se, err = session.CreateSession4TestWithOpt(store, &session.Opt{
PreparedPlanCache: kvcache.NewSimpleLRUCache(100, 0.1, math.MaxUint64),
})
c.Assert(err, IsNil)

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;`)
}

func (s *testPrepareSerialSuite) TestIssue29805(c *C) {
defer testleak.AfterTest(c)()
store, dom, err := newStoreWithBootstrap()
Expand Down

0 comments on commit 9c074a2

Please sign in to comment.