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

Use --comments when calling MySQL Client to avoid stripping of TiDB comments #58

Merged
merged 1 commit into from
Aug 19, 2021

Conversation

dveeden
Copy link
Contributor

@dveeden dveeden commented Aug 12, 2021

Without this this happens:

mysql> SELECT /*T 'ti', */ 'db';
+----+
| db |
+----+
| db |
+----+
1 row in set (0.00 sec)

The /*T ... */ syntax is use in the output of SHOW CREATE TABLE...
and other locations.

comments.

Without this this happens:
```
mysql> SELECT /*T 'ti', */ 'db';
+----+
| db |
+----+
| db |
+----+
1 row in set (0.00 sec)
```

The `/*T ... */` syntax is use in the output of `SHOW CREATE TABLE...`
and other locations.
@CLAassistant
Copy link

CLAassistant commented Aug 12, 2021

CLA assistant check
All committers have signed the CLA.

@baurine
Copy link
Collaborator

baurine commented Aug 13, 2021

Thanks @dveeden , let me have a try.

@baurine
Copy link
Collaborator

baurine commented Aug 19, 2021

hi @dveeden , I found it has the same output for SELECT /*T 'ti', */ 'db'; between with --comments and without --comments, can you add some more explanation or ref docs for this option, thanks!

btw, I found in the output of tiup playground command, it says To connect TiDB: mysql --host 127.0.0.1 --port 4000 -u root -p (no password) --comments.

@dveeden
Copy link
Contributor Author

dveeden commented Aug 19, 2021

@baurine sorry, my mistake. It is /*T! instead of /*T:

[dvaneeden@dve-carbon ~]$ mysql -h 127.0.0.1 -u root -P 4000 --comments -Ne "SELECT /*T! 'ti', */ 'db'"
+----+----+
| ti | db |
+----+----+
[dvaneeden@dve-carbon ~]$ mysql -h 127.0.0.1 -u root -P 4000 -Ne "SELECT /*T! 'ti', */ 'db'"
+----+
| db |
+----+

Here is an example:

Take a table that is created with clustered index enabled:

mysql> create table t (id int primary key);
Query OK, 0 rows affected (0.01 sec)

mysql> show create table t\G
*************************** 1. row ***************************
       Table: t
Create Table: CREATE TABLE `t` (
  `id` int(11) NOT NULL,
  PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
1 row in set (0.00 sec)

Now drop the table and create it again copying the output from the SHOW CREATE TABLE:

Without --comments:

mysql> SET tidb_enable_clustered_index=OFF;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TABLE `t` (
    ->   `id` int(11) NOT NULL,
    ->   PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
Query OK, 0 rows affected (0.00 sec)

mysql> show create table t\G
*************************** 1. row ***************************
       Table: t
Create Table: CREATE TABLE `t` (
  `id` int(11) NOT NULL,
  PRIMARY KEY (`id`) /*T![clustered_index] NONCLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
1 row in set (0.00 sec)

With --comments:

mysql> SET tidb_enable_clustered_index=OFF;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TABLE `t` (
    ->   `id` int(11) NOT NULL,
    ->   PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
Query OK, 0 rows affected (0.00 sec)

mysql> show create table t\G
*************************** 1. row ***************************
       Table: t
Create Table: CREATE TABLE `t` (
  `id` int(11) NOT NULL,
  PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
1 row in set (0.00 sec)

The docs:
https://dev.mysql.com/doc/refman/8.0/en/mysql-command-options.html#option_mysql_comments

The code:
https://github.com/mysql/mysql-server/blob/beb865a960b9a8a16cf999c323e46c5b0c67f21f/client/mysql.cc#L2447-L2670

MySQL has whitelisted some comments: /*! (version specific comment) and /*+ (optimizer hints) but not /*T

@baurine baurine merged commit cb532a7 into tidb-incubator:master Aug 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants