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 missing error of only full group by check for folded nature join cols #53228

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 6 additions & 1 deletion pkg/planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3801,7 +3801,12 @@ func (*colNameResolver) Enter(inNode ast.Node) (ast.Node, bool) {

func (c *colNameResolver) Leave(inNode ast.Node) (ast.Node, bool) {
if v, ok := inNode.(*ast.ColumnNameExpr); ok {
idx, err := expression.FindFieldName(c.p.OutputNames(), v.Name)
// if p is join, try to use join full schema, cause same column may be folded by nature join.
names := c.p.OutputNames()
if join, ok := c.p.(*LogicalJoin); ok {
names = join.fullNames
}
idx, err := expression.FindFieldName(names, v.Name)
if err == nil && idx >= 0 {
c.names[c.p.OutputNames()[idx]] = struct{}{}
}
Expand Down
11 changes: 11 additions & 0 deletions tests/integrationtest/r/executor/aggregate.result
Original file line number Diff line number Diff line change
Expand Up @@ -2060,3 +2060,14 @@ Projection 1.00 root Column#9, Column#12, Column#15, Column#18
└─TableFullScan 1000.00 cop[tikv] table:test keep order:false, stats:pseudo
delete from mysql.opt_rule_blacklist where name = "decorrelate";
admin reload opt_rule_blacklist;
drop table if exists t0, t1;
CREATE TABLE t0 (
c0 double unsigned zerofill NULL
);
INSERT INTO t0 VALUES (0.1251773127435537), (NULL), (0), (0.6665588482250941);
CREATE TABLE t1(c0 BOOL);
INSERT INTO t1 VALUES (NULL), (NULL), (0), (0);
explain format="brief" SELECT t0.c0 FROM t0 NATURAL RIGHT JOIN t1 GROUP BY NULL;
Error 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'executor__aggregate.t0._tidb_rowid' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
SELECT t0.c0 FROM t0 NATURAL RIGHT JOIN t1 GROUP BY NULL;
Error 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'executor__aggregate.t0._tidb_rowid' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
12 changes: 12 additions & 0 deletions tests/integrationtest/t/executor/aggregate.test
Original file line number Diff line number Diff line change
Expand Up @@ -1067,3 +1067,15 @@ explain format = 'brief' select /*+ hash_agg() */ sum(a), (select NULL from test
delete from mysql.opt_rule_blacklist where name = "decorrelate";
admin reload opt_rule_blacklist;

# TestIssue52935
drop table if exists t0, t1;
CREATE TABLE t0 (
c0 double unsigned zerofill NULL
);
INSERT INTO t0 VALUES (0.1251773127435537), (NULL), (0), (0.6665588482250941);
CREATE TABLE t1(c0 BOOL);
INSERT INTO t1 VALUES (NULL), (NULL), (0), (0);
--error 1055
explain format="brief" SELECT t0.c0 FROM t0 NATURAL RIGHT JOIN t1 GROUP BY NULL;
--error 1055
SELECT t0.c0 FROM t0 NATURAL RIGHT JOIN t1 GROUP BY NULL;