diff --git a/pkg/planner/funcdep/extract_fd_test.go b/pkg/planner/funcdep/extract_fd_test.go index cf2fc10f9496b..8f3ceb2a5db6a 100644 --- a/pkg/planner/funcdep/extract_fd_test.go +++ b/pkg/planner/funcdep/extract_fd_test.go @@ -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", @@ -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() @@ -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) diff --git a/pkg/planner/util/funcdep_misc.go b/pkg/planner/util/funcdep_misc.go index 7aec43d199bcc..6cfefd3c4e8b1 100644 --- a/pkg/planner/util/funcdep_misc.go +++ b/pkg/planner/util/funcdep_misc.go @@ -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)) } } diff --git a/tests/integrationtest/r/executor/aggregate.result b/tests/integrationtest/r/executor/aggregate.result index 721460031fd99..717fe68bd3194 100644 --- a/tests/integrationtest/r/executor/aggregate.result +++ b/tests/integrationtest/r/executor/aggregate.result @@ -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; diff --git a/tests/integrationtest/t/executor/aggregate.test b/tests/integrationtest/t/executor/aggregate.test index 49279268d4546..1997be0dd3a2a 100644 --- a/tests/integrationtest/t/executor/aggregate.test +++ b/tests/integrationtest/t/executor/aggregate.test @@ -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;