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

Selection on merge join could not find column #32160

Closed
tangenta opened this issue Feb 8, 2022 · 3 comments
Closed

Selection on merge join could not find column #32160

tangenta opened this issue Feb 8, 2022 · 3 comments
Assignees
Labels
affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 affects-6.2 affects-6.3 affects-6.4 affects-6.5 affects-6.6 affects-7.0 may-affects-4.0 This bug maybe affects 4.0.x versions. severity/major sig/planner SIG: Planner type/bug This issue is a bug.

Comments

@tangenta
Copy link
Contributor

tangenta commented Feb 8, 2022

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

drop table if exists t1, t2;
create table t1 ( id bigint primary key, a datetime);
create table t2 (id bigint primary key, b datetime);
insert into t1 values(1,'2022-02-06 00:03:35');
insert into t2 values(1,'2021-02-06 00:03:35');
insert into t2 values(3,'2021-02-07 00:03:35');
select * from( select ifnull(t2.b,t1.a) abc from t1 left join t2 on t2.id=t1.id) a where a.abc >='2022-02-07 00:00:00';

2. What did you expect to see? (Required)

Empty set.

3. What did you see instead (Required)

ERROR 1105 (HY000): Can't find column Column#5 in schema Column: [test.t1.a,test.t2.b] Unique key: []

4. What is your TiDB version? (Required)

16cd0e2

@tangenta tangenta added the type/bug This issue is a bug. label Feb 8, 2022
@ti-chi-bot ti-chi-bot added may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. labels Feb 8, 2022
@tangenta
Copy link
Contributor Author

tangenta commented Feb 8, 2022

The problem happens when PDD(predicate-push-down) optimizer trying to substitute a.abc in where clause with ifnull(t2.b,t1.a), for example:

select * from (select ifnull(t2.b,t1.a) abc from t1 left join t2 on t2.id=t1.id) a where a.abc >='2022-02-07 00:00:00';

is optimized to

select * from (select ifnull(t2.b,t1.a) from t1 left join t2 on t2.id=t1.id where ifnull(t2.b,t1.a) >= '2022-02-07 00:00:00') tmp;

When the new collation is enabled, the strictness of the collation should be also considered before the substitution(See checkCollationStrictness). Because the derived charset of ifnull([datetime], [datetime]) is utf8mb4 instead of binary, this check does not passed. Thus, the substitution is failed. However, this failure is not aware by PDD optimizer, the predicate is still pushed down.

#30967 solves this problem.

@jebter jebter added affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. and removed may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. labels Feb 10, 2022
@River2000i
Copy link
Contributor

River2000i commented Apr 11, 2022

maybe found a similar case

CREATE TABLE t (a MEDIUMINT NOT NULL AUTO_INCREMENT primary key,b varbinary(20));
select a from t  group by a having not ifnull(min(null) = max(null), min(b));

sql exec

mysql> CREATE TABLE t (a MEDIUMINT NOT NULL AUTO_INCREMENT primary key,b varbinary(20));
Query OK, 0 rows affected (0.60 sec)

mysql> select a from t  group by a having not ifnull(min(null) = max(null), min(b));
ERROR 1105 (HY000): Can't find column Column#3 in schema Column: [aggregation1.t.a,aggregation1.t.b] Unique key: [[aggregation1.t.a]]

when i change column b type varbinary(20), such as varbinary(20) ->double or int
there is no error

mysql> CREATE TABLE t1 (a MEDIUMINT NOT NULL AUTO_INCREMENT primary key,b int);
Query OK, 0 rows affected (0.58 sec)

mysql> select a from t1  group by a having not ifnull(min(null) = max(null), min(b));
Empty set (0.05 sec)

@qw4990
Copy link
Contributor

qw4990 commented Nov 9, 2023

Fixed by #37992

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects 5.4.x versions. affects-6.0 affects-6.1 affects-6.2 affects-6.3 affects-6.4 affects-6.5 affects-6.6 affects-7.0 may-affects-4.0 This bug maybe affects 4.0.x versions. severity/major sig/planner SIG: Planner type/bug This issue is a bug.
Projects
None yet
7 participants