running validation for session variables affects performance
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Enhancement
in https://github.com/pingcap/tidb/pull/29594 , we already know that there's an optimization when access session variables
> We also currently always re-run validation for session variables, which is a larger opportunity for optimization.
Now we meet a real use case that need this optimization. If the table has a DEFAULT CURRENT_TIMESTAMP column, each insertion will run validation because CURRENT_TIMESTAMP need to acess [session variable "TIMESTAMP"](https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_timestamp)
```
create table t (c tinyint, d timestamp default current_timestamp);
...
MySQL [test]> insert into t (c) select c+1 from t;
Query OK, 65536 rows affected, 65535 warnings (2.111 sec)
Records: 65536 Duplicates: 0 Warnings: 65535
```
```
create table t (c tinyint, d timestamp default current_timestamp);
...
MySQL [test]> insert into t (c,d) select c+1, d from t;
Query OK, 65536 rows affected, 65535 warnings (1.776 sec)
Records: 65536 Duplicates: 0 Warnings: 65535
```
if column `d` is inserted with default value CURRENT_TIMESTAMP, we need extra 19% time.
A more severe case is lightning's encoding component, if we comment the validation, the time will reduce from 1m10s to 9s
Contributor guide
Assessment
This issue has not been assessed yet.