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

eliminate ifnull projection on not null column #7918

Closed
lysu opened this issue Oct 16, 2018 · 3 comments · Fixed by #7924
Closed

eliminate ifnull projection on not null column #7918

lysu opened this issue Oct 16, 2018 · 3 comments · Fixed by #7924
Assignees
Labels
sig/planner SIG: Planner

Comments

@lysu
Copy link
Contributor

lysu commented Oct 16, 2018

Feature Request

Is your feature request related to a problem? Please describe:

some framework no-brain generate ifnull(col, x) for all return column even column is not null

create table ttt (id int not null);

explain select ifnull(id, 0) from ttt;
+---------------------+----------+------+--------------------------------------------------------------+
| id                  | count    | task | operator info                                                |
+---------------------+----------+------+--------------------------------------------------------------+
| Projection_3        | 10000.00 | root | ifnull(test.ttt.id, 0)                                       |
| └─TableReader_5     | 10000.00 | root | data:TableScan_4                                             |
|   └─TableScan_4     | 10000.00 | cop  | table:ttt, range:[-inf,+inf], keep order:false, stats:pseudo |
+---------------------+----------+------+--------------------------------------------------------------+
3 rows in set (0.00 sec)

Describe the feature you'd like:

eliminate ifnull() for not null column.

+-------------------+----------+------+--------------------------------------------------------------+
| id                | count    | task | operator info                                                |
+-------------------+----------+------+--------------------------------------------------------------+
| TableReader_5     | 10000.00 | root | data:TableScan_4                                             |
| └─TableScan_4     | 10000.00 | cop  | table:ttt, range:[-inf,+inf], keep order:false, stats:pseudo |
+-------------------+----------+------+--------------------------------------------------------------+

Describe alternatives you've considered:

it's better eliminate impl can reduce plan node allocation- -?

Teachability, Documentation, Adoption, Migration Strategy:

mainly useful for some no-brain generate code framework's user.

@lysu lysu added the sig/planner SIG: Planner label Oct 16, 2018
@winoros
Copy link
Member

winoros commented Oct 16, 2018

Actually, the thing you described contains two step:

  • Simplify ifnull function since it's arg is always not null.
  • Eliminate project since it's arg is all column.

@zz-jason
Copy link
Member

@lzmhhh123 PTAL

@zhexuany
Copy link
Contributor

zhexuany commented Oct 17, 2018

@lysu I believe the correct plan should be the following:

mysql> explain select ifnull(id, 0), ifnull(id, 1) from ttt;
+---------------------+----------+------+--------------------------------------------------------------+
| id                  | count    | task | operator info                                                |
+---------------------+----------+------+--------------------------------------------------------------+
| Projection_3        | 10000.00 | root | test.ttt.id                                   |
| └─TableReader_5     | 10000.00 | root | data:TableScan_4                                             |
|   └─TableScan_4     | 10000.00 | cop  | table:ttt, range:[-inf,+inf], keep order:false, stats:pseudo |
+---------------------+----------+------+--------------------------------------------------------------+
3 rows in set (0.00 sec)

Proj can be eliminated later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/planner SIG: Planner
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants