-
Notifications
You must be signed in to change notification settings - Fork 489
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
parser: fix STATS_AUTO_RECALC syntax #483
Conversation
Codecov Report
@@ Coverage Diff @@
## master #483 +/- ##
=========================================
Coverage ? 71.56%
=========================================
Files ? 32
Lines ? 7703
Branches ? 0
=========================================
Hits ? 5513
Misses ? 1668
Partials ? 522
Continue to review full report at Codecov.
|
bfca65b
to
ef5c8ae
Compare
@leoppro PTAL |
@leoppro PTAL |
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
@tangenta PTAL |
parser.y
Outdated
} | ||
| "STATS_AUTO_RECALC" EqOpt "DEFAULT" | ||
{ | ||
$$ = &ast.TableOption{Tp: ast.TableOptionStatsAutoRecalc, UintValue: 0} |
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.
@leoppro @lauhg I don't think DEFAULT
is the same as 0.
Here is the MySQL 8.0 documentation:
- STATS_AUTO_RECALC
Specifies whether to automatically recalculate persistent statistics for an InnoDB table. The value DEFAULT causes the persistent statistics setting for the table to be determined by the innodb_stats_auto_recalc configuration option. The value 1 causes statistics to be recalculated when 10% of the data in the table has changed. The value 0 prevents automatic recalculation for this table;
TiDB needs the information to decide whether using innodb_stats_auto_recalc
(or something similar) or not.
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.
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.
fine, I think we should add a feild named default
to TableOption
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.
could fix "STATS_SAMPLE_PAGES" EqOpt "DEFAULT"
by the way?
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.
Could this be parsed into a nil
option?
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.
fine, I think we should add a feild named
default
to TableOption
I think this is a good way to solve this problem.
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.
@lauhg Since STATS_SAMPLE_PAGES = DEFAULT
is the default the option could just be entirely removed from the AST, so changing this branch to $$ = nil
should be possible.
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.
@kennytm As far as I know, this parser is not only part of TiDB, it will also be used by other projects. In order to be more compatible with mysql, I think it is necessary to know if the default value is explicitly set.
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.
@lauhg What project would benefit from knowing that the DEFAULT is explicitly set? In MySQL (8.0.17) even if you explicit write STATS_AUTO_RECALC = DEFAULT
it will disappear in SHOW CREATE TABLE
, showing these are semantically equivalent.
mysql> create table t (a int) stats_auto_recalc = 0;
Query OK, 0 rows affected (0.06 sec)
mysql> show create table t;
+-------+--------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+--------------------------------------------------------------------------------------------------------------------------------------+
| t | CREATE TABLE `t` (
`a` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci STATS_AUTO_RECALC=0 |
+-------+--------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> drop table t;
Query OK, 0 rows affected (0.02 sec)
mysql> create table t (a int) stats_auto_recalc = default;
Query OK, 0 rows affected (0.01 sec)
mysql> show create table t;
+-------+------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+------------------------------------------------------------------------------------------------------------------+
| t | CREATE TABLE `t` (
`a` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci |
+-------+------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql> drop table t;
Query OK, 0 rows affected (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.
@kennytm
In create table
case, these are semantically equivalent.
But in alter table
case, these are not equivalent.
For example:
create table t (a int) stats_auto_recalc = 1;
alter table t stats_auto_recalc = default;
If parser parses stats_auto_recalc = default
to nil
, it would be equivalent to
alter table t
.
Apparently, it changes semantics.
9852eaa
to
f03b252
Compare
Adding a field this way could lead to every TableOption increases 4 bytes memory usage.
|
Or just assign |
@lauhg It's unnecessary to compare a whole string when checking the |
I don't think we should reduce the readability of code for save 4 bytes(or 4*n bytes) |
What's the conclusion? |
Fine, keep the current changes is ok. Please resolve the conflicts. |
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
f03b252
to
9294ba9
Compare
Resolved. |
What problem does this PR solve?
Fix compatibility problem about
STATS_AUTO_RECALC
syntaxIssue: #472
MySQL Syntax:
Bad SQL Case:
Check List
Tests