Thanks to visit codestin.com
Credit goes to github.com

Skip to content

planner: plan cache wrongly skipped when outer-join null-reject inference involves parameters #65583

@Reminiscent

Description

@Reminiscent

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(a int, b int);
create table t2(a int, b int);
explain select * from t1 left join t2 on t1.a = t2.b where t2.a > 1; -- this can optimize outer to inner join
explain select * from t1 left join t2 on t1.a = t2.b where t2.a > 1 or t2.a is null; -- this can not optimize outer to inner join
prepare stmt from 'select * from t1 left join t2 on t1.a = t2.b where t2.a > ? or t2.a is null;';
set @v = 1;
execute stmt using @v;
show warnings;

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

Regardless of the given parameters, the current SQL cannot convert the outer join into an inner join due to the presence of t2.a is null. Therefore, this SQL should theoretically be cacheable. However, it currently fails to be cached because the validation check is overly strict.

3. What did you see instead (Required)

mysql> prepare stmt from 'select * from t1 left join t2 on t1.a = t2.b where t2.a > ? or t2.a is null;';
Query OK, 0 rows affected (0.00 sec)

mysql> set @v = 1;
Query OK, 0 rows affected (0.00 sec)

mysql> execute stmt using @v;
Empty set, 1 warning (0.01 sec)

mysql> show warnings;
+---------+------+------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                  |
+---------+------+------------------------------------------------------------------------------------------+
| Warning | 1105 | skip prepared plan-cache: or(gt(oa_doc.t2.a, 1), isnull(oa_doc.t2.a)) affects null check |
+---------+------+------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

4. What is your TiDB version? (Required)

lastest master

Metadata

Metadata

Assignees

Labels

sig/plannerSIG: Plannertype/bugThe issue is confirmed as a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions