-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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: support "show create table" for View #8865
Conversation
@AndrewDi Is this PR still work in progress? Can we begin to review it? |
@zz-jason main code is complete, you can review now. |
Codecov Report
@@ Coverage Diff @@
## master #8865 +/- ##
==========================================
- Coverage 67.26% 67.25% -0.01%
==========================================
Files 371 371
Lines 76195 76223 +28
==========================================
+ Hits 51252 51266 +14
- Misses 20412 20422 +10
- Partials 4531 4535 +4
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some test cases for this commit.
@XuHuaiyu Let's review the main code logic firstly. |
executor/show.go
Outdated
} | ||
fmt.Fprintf(&buf, ") AS %s", tb.Meta().View.SelectStmt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the output of MySQL:
mysql> show create table v_test;
+--------+-------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| View | Create View | character_set_client | collation_connection |
+--------+-------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| v_test | CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v_test` AS select `t`.`a` AS `a`,`t`.`b` AS `b` from `t` | utf8 | utf8_general_ci |
+--------+-------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
1 row in set (0.00 sec)
mysql> show create table t;
+-------+------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+------------------------------------------------------------------------------------------------------------------+
| t | CREATE TABLE `t` (
`a` int(11) DEFAULT NULL,
`b` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
+-------+------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
seems the number of columns and column names are different between normal table and view.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AndrewDi Please take a look at this comment.
@AndrewDi any update? |
@zz-jason You advise to exact method to |
Yes. |
bdb41af
to
0f7158f
Compare
/run-all-tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
e.appendRow([]interface{}{tb.Meta().Name.O, buf.String()}) | ||
return nil | ||
} | ||
|
||
func (e *ShowExec) fetchShowCreateTable4View(tb *model.TableInfo, buf *bytes.Buffer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @eurekaka mentioned in the earlier code reviews. MySQL behaves different between normal table and view on show create table
. For a normal table, the output has two columns, namely Table
and Create Table
:
MySQL(root@localhost:test) > create table t(a bigint, b bigint);
Query OK, 0 rows affected (0.11 sec)
MySQL(root@localhost:test) > show create table t;
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| t | CREATE TABLE `t` (
`a` bigint(20) DEFAULT NULL,
`b` bigint(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
But for View, the output contains 4 columns, namely View
, Create View
, character_set_client
and collation_connection
:
MySQL(root@localhost:test) > create view v as select * from t;
Query OK, 0 rows affected (0.11 sec)
MySQL(root@localhost:test) > show create table v;
+------+---------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| View | Create View | character_set_client | collation_connection |
+------+---------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| v | CREATE ALGORITHM=UNDEFINED DEFINER=`skip-grants user`@`skip-grants host` SQL SECURITY DEFINER VIEW `v` AS select `t`.`a` AS `a`,`t`.`b` AS `b` from `t` | utf8mb4 | utf8mb4_0900_ai_ci |
+------+---------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
1 row in set (0.00 sec)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
…w/show_create_table # Conflicts: # executor/show_test.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/run-all-tests |
What problem does this PR solve?
Modify
SHOW CREATE TABLE
to show view definitionWhat is changed and how it works?
ref proposal Proposal: Implement View
Check List
Tests
This change is![Reviewable](https://camo.githubusercontent.com/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)