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

parser: fix STATS_AUTO_RECALC syntax #483

Merged
merged 6 commits into from
Aug 20, 2019

Conversation

lauhg
Copy link
Contributor

@lauhg lauhg commented Aug 15, 2019

What problem does this PR solve?

Fix compatibility problem about STATS_AUTO_RECALC syntax

Issue: #472

MySQL Syntax:

type:
...
  | STATS_AUTO_RECALC_SYM opt_equal ternary_option

Bad SQL Case:

create table t (a int) stats_auto_recalc = 0
create table t (a int) stats_persistent = 1, stats_auto_recalc = 1
create table t (a int) stats_auto_recalc = 1, stats_sample_pages = 25
alter table t modify a bigint, ENGINE=InnoDB, stats_auto_recalc = 0

Check List

Tests

  • Unit test

@codecov
Copy link

codecov bot commented Aug 15, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@0c51dce). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #483   +/-   ##
=========================================
  Coverage          ?   71.56%           
=========================================
  Files             ?       32           
  Lines             ?     7703           
  Branches          ?        0           
=========================================
  Hits              ?     5513           
  Misses            ?     1668           
  Partials          ?      522
Impacted Files Coverage Δ
parser.go 70.58% <ø> (ø)
misc.go 96.42% <ø> (ø)
ast/ddl.go 80.18% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0c51dce...9294ba9. Read the comment docs.

parser.y Outdated Show resolved Hide resolved
parser.y Outdated Show resolved Hide resolved
@lauhg
Copy link
Contributor Author

lauhg commented Aug 15, 2019

@leoppro PTAL

ast/ddl.go Show resolved Hide resolved
@lauhg
Copy link
Contributor Author

lauhg commented Aug 15, 2019

@leoppro PTAL

Copy link
Contributor

@zier-one zier-one left a comment

Choose a reason for hiding this comment

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

LGTM

@zier-one
Copy link
Contributor

@tangenta PTAL

@zier-one zier-one added the status/LGT1 LGT1 label Aug 16, 2019
parser.y Outdated
}
| "STATS_AUTO_RECALC" EqOpt "DEFAULT"
{
$$ = &ast.TableOption{Tp: ast.TableOptionStatsAutoRecalc, UintValue: 0}
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tangenta I agree with you.
@leoppro What do you think?

Copy link
Contributor

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

Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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)

Copy link
Contributor Author

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.

ast/ddl.go Outdated Show resolved Hide resolved
@lauhg
Copy link
Contributor Author

lauhg commented Aug 16, 2019

I add a feild named Default to TableOption.
@leoppro @tangenta PTAL

@tangenta
Copy link
Contributor

Adding a field this way could lead to every TableOption increases 4 bytes memory usage.
Here are two options:

  1. Add a TableOption type named TableOptionStatsAutoRecalcDefault
  2. Assign a special value to UIntValue(i.e. math.MaxUint64) in TableOption, which represents default.

How do you think? @leoppro @lauhg

@lauhg
Copy link
Contributor Author

lauhg commented Aug 16, 2019

Or just assign DEFAULT to StrValue?

@tangenta
Copy link
Contributor

@lauhg It's unnecessary to compare a whole string when checking the default property.

@lauhg
Copy link
Contributor Author

lauhg commented Aug 16, 2019

@tangenta ok, I'd like to choose option 2.
@leoppro How do you think?

@zier-one
Copy link
Contributor

Adding a field this way could lead to every TableOption increases 4 bytes memory usage.
Here are two options:

  1. Add a TableOption type named TableOptionStatsAutoRecalcDefault
  2. Assign a special value to UIntValue(i.e. math.MaxUint64) in TableOption, which represents default.

How do you think? @leoppro @lauhg

I don't think we should reduce the readability of code for save 4 bytes(or 4*n bytes)

@lauhg
Copy link
Contributor Author

lauhg commented Aug 20, 2019

What's the conclusion?

@tangenta
Copy link
Contributor

Fine, keep the current changes is ok. Please resolve the conflicts.

Copy link
Contributor

@tangenta tangenta left a comment

Choose a reason for hiding this comment

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

LGTM

@lauhg
Copy link
Contributor Author

lauhg commented Aug 20, 2019

Resolved.
PTAL @tangenta

@zier-one zier-one removed the status/LGT1 LGT1 label Aug 20, 2019
@zier-one zier-one added the status/LGT2 LGT2 label Aug 20, 2019
@zier-one zier-one merged commit d21ba7f into pingcap:master Aug 20, 2019
tiancaiamao pushed a commit to tiancaiamao/parser that referenced this pull request Apr 27, 2021
lyonzhi pushed a commit to lyonzhi/parser that referenced this pull request Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants