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

planner: fix nil pointer at expression.(*CorrelatedColumn).Eval (#42789) #48978

Merged
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions pkg/planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,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 @@ -434,6 +435,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
27 changes: 24 additions & 3 deletions tests/integrationtest/r/planner/core/tests/prepare/issue.result
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ COL1 COL2 COL3 COL4
set @a=-27225, @b='-836:46:08';
execute stmt using @a,@b;
COL1 COL2 COL3 COL4
O۠�Bٙ�0���LJ���F �t -836:46:08 735655453
O۠�Bٙ�0���LJ���F �t -836:46:08 735655453
CbcWestwolf marked this conversation as resolved.
Show resolved Hide resolved
select @@last_plan_from_cache;
@@last_plan_from_cache
0
execute stmt using @a,@b;
COL1 COL2 COL3 COL4
O۠�Bٙ�0���LJ���F �t -836:46:08 735655453
O۠�Bٙ�0���LJ���F �t -836:46:08 735655453
select @@last_plan_from_cache;
@@last_plan_from_cache
1
select * from UK_MU15569 where col2 >= -27225 and col1 is not null and col3 = '-836:46:08';
COL1 COL2 COL3 COL4
O۠�Bٙ�0���LJ���F �t -836:46:08 735655453
O۠�Bٙ�0���LJ���F �t -836:46:08 735655453
set tidb_enable_prepared_plan_cache=1;
drop table if exists IDT_MULTI15844STROBJSTROBJ;
CREATE TABLE `IDT_MULTI15844STROBJSTROBJ` (`COL1` enum('bb','aa') DEFAULT NULL,`COL2` smallint(41) DEFAULT NULL,`COL3` year(4) DEFAULT NULL,KEY `U_M_COL4` (`COL1`,`COL2`),KEY `U_M_COL5` (`COL3`,`COL2`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
Expand Down Expand Up @@ -425,3 +425,24 @@ execute st1 using @t;
select count(*) from t4;
count(*)
2
use test;
drop table if exists t0;
CREATE TABLE t0 (c1 double, c2 double);
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;
c10
0
21 changes: 21 additions & 0 deletions tests/integrationtest/t/planner/core/tests/prepare/issue.test
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,24 @@ set @t='2022-01-01 00:00:00.000000';
execute st1 using @t;
select count(*) from t4;

# TestIssue42739

use test;
drop table if exists t0;
CREATE TABLE t0 (c1 double, c2 double);
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;