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

planner, executor: adjustOverlongColName for CreateView #14850

Merged
merged 5 commits into from
Feb 20, 2020

Conversation

XuHuaiyu
Copy link
Contributor

@XuHuaiyu XuHuaiyu commented Feb 19, 2020

What problem does this PR solve?

Fix the bug:

On TiDB:
mysql root@127.0.0.1:test> create view v0 as select 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
(1059, "Identifier name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' is too long")

On MySQL:
mysql root@127.0.0.1:test> create view v0 as select 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
Query OK, 0 rows affected
Time: 0.008s
mysql root@127.0.0.1:test> select * from v0
+-------------------------------------------------------------------+
| Name_exp_1 |
+-------------------------------------------------------------------+
| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
+-------------------------------------------------------------------+
1 row in set
Time: 0.015s

What is changed and how it works?

Rename the output column name for view if the column name is too long (>64).

Check List

Tests

  • Integration test

Code changes

  • Has exported function/method change

Side effects

  • There are still some compatible problems exist. But I think the behavior of TiDB is more reasonable than MySQL, and there is no official MySQL manual taking about this behavior.
  1. case 1:
    In MySQL, use the sql shown in the result of show create view to create a view will fail. It is really strange. In TiDB, this case will fail for the first time. MySQL bug issue link: https://bugs.mysql.com/bug.php?id=98676
mysql> create view v(`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa`) as select a from t; -- TiDB will fail here.
Query OK, 0 rows affected (0.01 sec)

mysql> show create view v;
+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| View | Create View                                                                                                                                                                                                                                                    | character_set_client | collation_connection |
+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| v    | CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` AS select `t`.`a` AS `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` from `t` | utf8                 | utf8_general_ci      |
+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
1 row in set (0.00 sec)

mysql> drop view v;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` AS select `t`.`a` AS `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` from `t`;
ERROR 1166 (42000): Incorrect column name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'

case 2:

In MySQL, the following case will fail. But it will execute successfully in TiDB.

create view v as select 'a' as 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' from t;

Related changes

  • Need to cherry-pick to the release branch

Release note

  • Adjust the colName to name_exp_$off if a column name is overlong when creating the view.

@XuHuaiyu XuHuaiyu requested a review from a team as a code owner February 19, 2020 11:01
@ghost ghost requested review from francis0407 and alivxxx and removed request for a team February 19, 2020 11:02
@XuHuaiyu XuHuaiyu added the type/bugfix This PR fixes a bug. label Feb 19, 2020
@XuHuaiyu XuHuaiyu requested review from qw4990 and removed request for francis0407 and alivxxx February 19, 2020 11:04
@XuHuaiyu
Copy link
Contributor Author

/run-unit-test

Copy link
Contributor

@crazycs520 crazycs520 left a comment

Choose a reason for hiding this comment

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

In this PR:

test> create view v0 as select 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' as aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
Query OK, 0 rows affected

In mysql

test> create view v0 as select 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' as aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
(1166, u"Incorrect column name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'")

Is this expect?

@XuHuaiyu
Copy link
Contributor Author

@crazycs520 As I mentioned in the description. It's expected.

Copy link
Contributor

@crazycs520 crazycs520 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@qw4990 qw4990 left a comment

Choose a reason for hiding this comment

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

LGTM

@qw4990 qw4990 added status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. labels Feb 20, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Feb 20, 2020

/run-all-tests

@sre-bot sre-bot merged commit fe05ed5 into pingcap:master Feb 20, 2020
@sre-bot
Copy link
Contributor

sre-bot commented Feb 20, 2020

cherry pick to release-3.0 failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/planner SIG: Planner status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants