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

Do not need to push down ColumnRef <compare_operator> null which is always false #51446

Open
Lloyd-Pottiger opened this issue Mar 1, 2024 · 2 comments · May be fixed by #53206
Open

Do not need to push down ColumnRef <compare_operator> null which is always false #51446

Lloyd-Pottiger opened this issue Mar 1, 2024 · 2 comments · May be fixed by #53206
Assignees

Comments

@Lloyd-Pottiger
Copy link
Contributor

Enhancement

mysql> create table t (a int, f float);
Query OK, 0 rows affected (0.09 sec)

mysql> insert into t values (1, 0.1), (2, 0.2);
Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> explain select * from t where f != null;
+-------------------------+----------+-----------+---------------+--------------------------------+
| id                      | estRows  | task      | access object | operator info                  |
+-------------------------+----------+-----------+---------------+--------------------------------+
| TableReader_7           | 0.00     | root      |               | data:Selection_6               |
| └─Selection_6           | 0.00     | cop[tikv] |               | ne(test.t.f, NULL)             |
|   └─TableFullScan_5     | 10000.00 | cop[tikv] | table:t       | keep order:false, stats:pseudo |
+-------------------------+----------+-----------+---------------+--------------------------------+
3 rows in set (0.00 sec)

mysql> explain select * from t where f > null;
+-------------------------+----------+-----------+---------------+--------------------------------+
| id                      | estRows  | task      | access object | operator info                  |
+-------------------------+----------+-----------+---------------+--------------------------------+
| TableReader_7           | 0.00     | root      |               | data:Selection_6               |
| └─Selection_6           | 0.00     | cop[tikv] |               | gt(test.t.f, NULL)             |
|   └─TableFullScan_5     | 10000.00 | cop[tikv] | table:t       | keep order:false, stats:pseudo |
+-------------------------+----------+-----------+---------------+--------------------------------+
3 rows in set (0.00 sec)

mysql> explain select * from t where f >= null;
+-------------------------+----------+-----------+---------------+--------------------------------+
| id                      | estRows  | task      | access object | operator info                  |
+-------------------------+----------+-----------+---------------+--------------------------------+
| TableReader_7           | 0.00     | root      |               | data:Selection_6               |
| └─Selection_6           | 0.00     | cop[tikv] |               | ge(test.t.f, NULL)             |
|   └─TableFullScan_5     | 10000.00 | cop[tikv] | table:t       | keep order:false, stats:pseudo |
+-------------------------+----------+-----------+---------------+--------------------------------+
3 rows in set (0.00 sec)

mysql> explain select * from t where f < null;
+-------------------------+----------+-----------+---------------+--------------------------------+
| id                      | estRows  | task      | access object | operator info                  |
+-------------------------+----------+-----------+---------------+--------------------------------+
| TableReader_7           | 0.00     | root      |               | data:Selection_6               |
| └─Selection_6           | 0.00     | cop[tikv] |               | lt(test.t.f, NULL)             |
|   └─TableFullScan_5     | 10000.00 | cop[tikv] | table:t       | keep order:false, stats:pseudo |
+-------------------------+----------+-----------+---------------+--------------------------------+
3 rows in set (0.00 sec)

mysql> explain select * from t where f <= null;
+-------------------------+----------+-----------+---------------+--------------------------------+
| id                      | estRows  | task      | access object | operator info                  |
+-------------------------+----------+-----------+---------------+--------------------------------+
| TableReader_7           | 0.00     | root      |               | data:Selection_6               |
| └─Selection_6           | 0.00     | cop[tikv] |               | le(test.t.f, NULL)             |
|   └─TableFullScan_5     | 10000.00 | cop[tikv] | table:t       | keep order:false, stats:pseudo |
+-------------------------+----------+-----------+---------------+--------------------------------+
3 rows in set (0.00 sec)

mysql> explain select * from t where f = null;
+-------------+---------+------+---------------+---------------+
| id          | estRows | task | access object | operator info |
+-------------+---------+------+---------------+---------------+
| TableDual_5 | 0.00    | root |               | rows:0        |
+-------------+---------+------+---------------+---------------+
1 row in set (0.00 sec)
@Lloyd-Pottiger Lloyd-Pottiger changed the title Do not need to push down ColumnRed <compare_operator> null which is always false Do not need to push down ColumnRef <compare_operator> null which is always false Mar 1, 2024
@elsa0520 elsa0520 added the sig/planner SIG: Planner label Mar 1, 2024
@elsa0520
Copy link
Contributor

elsa0520 commented Mar 1, 2024

Also , we have some predicate evaluate logic when build selection operator.
img_v3_028i_655feb32-2650-49da-93cd-f5bde1f6bacg

But the bad thing is that we cannot evaluate x!=null to false.

By the way, I think maybe the predicate evaluate feature should be a single rewrite rule in the optimizer to handle this kind of predicate (always false).

@King-Dylan
Copy link
Contributor

/assign @King-Dylan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants