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

Digester produces invalid sql for selecting global variables #798

Closed
wjhuang2016 opened this issue Nov 16, 2020 · 3 comments · Fixed by #802 or #805
Closed

Digester produces invalid sql for selecting global variables #798

wjhuang2016 opened this issue Nov 16, 2020 · 3 comments · Fixed by #802 or #805
Labels
Milestone

Comments

@wjhuang2016
Copy link
Member

Bug Report

1. Minimal reproduce step (Required)

Linked issue.

The digester produces an invalid SQL for the following statement:

SELECT @@global.tidb_stmt_summary_refresh_interval AS value

This statement is generated by the tidb-dashboard.

I have another digester bug in pingcap/tidb#14241 - it is annoying when the syntax generated back is invalid.

2. What did you expect to see? (Required)

SELECT @@global.tidb_stmt_summary_refresh_interval AS value

3. What did you see instead (Required)

There is a space between the two @ symbols:

SELECT @ @global.tidb_stmt_summary_refresh_interval AS value

4. Affected version (Required)

mysql> select tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v4.0.0-beta.2-684-gf590d74e1
Edition: Community
Git Commit Hash: f590d74e158cf4e33555bfeb8f88971af5956697
Git Branch: master
UTC Build Time: 2020-06-27 02:29:48
GoVersion: go1.13.8
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.00 sec)

5. Root Cause Analysis

@breezewish breezewish added this to the 4.0.9 milestone Nov 20, 2020
@baurine
Copy link
Collaborator

baurine commented Nov 20, 2020

I suggest to fix this issue in 2 steps:

  1. Copy original content instead of formatted content when clicking the "Copy" button
  2. Fix the incorrect format behavior for sql-formatter-plus-plus lib

For step 1, some reasons (personal opinion):

  1. It seems most people report the formatted SQL is incorrect because they copy and paste to run it in the SQL client, found it doesn't work, else they can't notice the incorrectness. So I think people (especially the DBAs) care the correctness more than style.
  2. Formatting the SQL belongs view layer staff, it is just for easy reading, but when copying and pasting to SQL client, the style is not that important.
  3. We can't confirm the sql-formatter-plus-plus lib won't format some others incorrectly, we need to fix them case by case.
  4. Copying the formatted content makes locate the problem more complex a bit. If people report the formatted SQL doesn't work, we need to find out whether it happened in the TiDB layer or dashboard layer.

hi @breeswish , how do you think about it?

@breezewish
Copy link
Member

According to my OnCall experience formatting SQL is very frequently used, even for copied content, since an unformatted SQL is usually not readable, for example, too long, or all in one line, which makes people hard to know what is it and what's inside (is it a join? does it contain sub queries? etc) .

How about introducing "Copy Original" and "Copy Formatted"? This may be good for all cases.

@baurine
Copy link
Collaborator

baurine commented Nov 23, 2020

Ok, we can do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants