Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions pkg/planner/funcdep/extract_fd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ func TestFDSet_ExtractFD(t *testing.T) {
tk.MustExec("create table t2(m int key, n int, p int, unique(m,n))")
tk.MustExec("create table x1(a int not null primary key, b int not null, c int default null, d int not null, unique key I_b_c (b,c), unique key I_b_d (b,d))")
tk.MustExec("create table x2(a int not null primary key, b int not null, c int default null, d int not null, unique key I_b_c (b,c), unique key I_b_d (b,d))")
tk.MustExec("create table x3(a int not null primary key, b int not null, c int default null, d int not null, unique key I_b_c (b,c))")

tests := []struct {
sql string
best string
fd string
err string
}{
{
sql: "select a from t1",
Expand Down Expand Up @@ -213,6 +215,10 @@ func TestFDSet_ExtractFD(t *testing.T) {
best: "Apply{DataScan(t1)->DataScan(t2)->Projection->MaxOneRow}->Projection",
fd: "{(1)-->(2-4,13), (2,3)~~>(1,4), (13)~~>(1)} >>> {}",
},
{
sql: "select a from x3 where c = 1 or d = 1 group by b, c",
err: "contains nonaggregated column 'test.x3.a'",
},
}

ctx := context.TODO()
Expand All @@ -233,6 +239,10 @@ func TestFDSet_ExtractFD(t *testing.T) {
builder, _ := plannercore.NewPlanBuilder().Init(tk.Session().GetPlanCtx(), is, hint.NewQBHintHandler(nil))
// extract FD to every OP
p, err := builder.Build(ctx, nodeW)
if tt.err != "" {
require.ErrorContains(t, err, tt.err, comment)
continue
}
require.NoError(t, err)
p, err = plannercore.LogicalOptimizeTest(ctx, builder.GetOptFlag(), p.(base.LogicalPlan))
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/planner/util/funcdep_misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func ExtractNotNullFromConds(conditions []expression.Expression, p base.LogicalP
if len(cols) == 0 {
continue
}
if IsNullRejected(p.SCtx(), p.Schema(), condition) {
for _, col := range cols {
for _, col := range cols {
if IsNullRejected(p.SCtx(), expression.NewSchema(col), condition) {
notnullColsUniqueIDs.Insert(int(col.UniqueID))
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/integrationtest/r/executor/aggregate.result
Original file line number Diff line number Diff line change
Expand Up @@ -1483,6 +1483,8 @@ select * from t group by b,c;
Error 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'executor__aggregate.t.a' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
select * from t where c = d group by b, c;
a b c d
select /* issue:68026 */ a from t where c = 1 or d = 1 group by b, c;
Error 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'executor__aggregate.t.a' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
select t.*, x.* from t, x where t.a = x.a group by t.a;
a b c d a b c d
select t.*, x.* from t, x where t.b = x.b and t.d = x.d group by t.b, t.d;
Expand Down
2 changes: 2 additions & 0 deletions tests/integrationtest/t/executor/aggregate.test
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,8 @@ select * from t group by b,d;
--error 1055
select * from t group by b,c;
select * from t where c = d group by b, c;
--error 1055
select /* issue:68026 */ a from t where c = 1 or d = 1 group by b, c;
select t.*, x.* from t, x where t.a = x.a group by t.a;
select t.*, x.* from t, x where t.b = x.b and t.d = x.d group by t.b, t.d;
select t.*, x.* from t, x where t.b = x.a group by t.b, t.d;
Expand Down
Loading