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

executor, plan: eliminate projection if the schema len is 0 #6318

Merged
merged 4 commits into from
Apr 20, 2018

Conversation

XuHuaiyu
Copy link
Contributor

Before this commit:

tidb(127.0.0.1)> create table t(a int);
Query OK, 0 rows affected (0.11 sec)

tidb(127.0.0.1)> insert into t value(0),(0);
Query OK, 2 rows affected (0.00 sec)

tidb(127.0.0.1)> select 1 from (select a from t union all select a from t) tmp;
0 rows in set (0.00 sec)

tidb(127.0.0.1)> explain select 1 from (select a from t union all select a from t) tmp;
+----------------+---------------+----------------------------+------+----------------------------------------------+----------+
| id             | parents       | children                   | task | operator info                                | count    |
+----------------+---------------+----------------------------+------+----------------------------------------------+----------+
| TableScan_10   |               |                            | cop  | table:t, range:[-inf,+inf], keep order:false | 10000.00 |
| TableReader_11 | Projection_9  |                            | root | data:TableScan_10                            | 10000.00 |
| Projection_9   | Union_8       | TableReader_11             | root |                                              | 10000.00 |
| TableScan_13   |               |                            | cop  | table:t, range:[-inf,+inf], keep order:false | 10000.00 |
| TableReader_14 | Projection_12 |                            | root | data:TableScan_13                            | 10000.00 |
| Projection_12  | Union_8       | TableReader_14             | root |                                              | 10000.00 |
| Union_8        | Projection_7  | Projection_9,Projection_12 | root |                                              | 20000.00 |
| Projection_7   |               | Union_8                    | root | 1                                            | 20000.00 |
+----------------+---------------+----------------------------+------+----------------------------------------------+----------+
8 rows in set (0.00 sec)

Which is caused by the columnPruner pruning all the columns of Projection,
thus there is no data returned from Projection.

After this commit,

tidb(127.0.0.1)> select 1 from (select a from t union all select a from t) tmp;

+---+
| 1 |
+---+
| 1 |
| 1 |
| 1 |
| 1 |
+---+

tidb(127.0.0.1)> explain select 1 from (select a from t union all select a from t) tmp;
+----------------+--------------+-------------------------------+------+----------------------------------------------+----------+
| id             | parents      | children                      | task | operator info                                | count    |
+----------------+--------------+-------------------------------+------+----------------------------------------------+----------+
| TableScan_10   |              |                               | cop  | table:t, range:[-inf,+inf], keep order:false | 10000.00 |
| TableReader_11 | Union_8      |                               | root | data:TableScan_10                            | 10000.00 |
| TableScan_13   |              |                               | cop  | table:t, range:[-inf,+inf], keep order:false | 10000.00 |
| TableReader_14 | Union_8      |                               | root | data:TableScan_13                            | 10000.00 |
| Union_8        | Projection_7 | TableReader_11,TableReader_14 | root |                                              | 20000.00 |
| Projection_7   |              | Union_8                       | root | 1                                            | 20000.00 |
+----------------+--------------+-------------------------------+------+----------------------------------------------+----------+
6 rows in set (0.01 sec)

PTAL @zz-jason @winoros

@zz-jason
Copy link
Member

/run-all-tests

@XuHuaiyu
Copy link
Contributor Author

/run-common-test
/run-integration-common-tests

@XuHuaiyu
Copy link
Contributor Author

/run-common-test tidb-test=pr/504
/run-integration-common-tests tidb-test=pr/504

@XuHuaiyu XuHuaiyu added the type/bugfix This PR fixes a bug. label Apr 19, 2018
@zz-jason zz-jason added status/LGT1 Indicates that a PR has LGTM 1. all-tests-passed labels Apr 19, 2018
@zz-jason
Copy link
Member

LGTM

Copy link
Member

@winoros winoros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
though i think it should handled more elegantly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT1 Indicates that a PR has LGTM 1. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants