pingcap / pingcap/tidb

Inconsistent compatibility in non strict sql_mode with wrong argument in NAME_CONST(name, value)

Open
#32,218 0 comments 0 reactions 0 assignees View on GitHub
severity/moderate sig/execution type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report
The arguments in NAME_CONST(name, value) should be constants.

### 1. Minimal reproduce step
```sql
SET sql_mode = 'NO_ENGINE_SUBSTITUTION';
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1),(2),(3);
SELECT NAME_CONST('flag', SQRT(4)) * MAX(a) FROM t1;
SELECT NAME_CONST('flag',-SQRT(4)) * MAX(a) FROM t1;
SELECT NAME_CONST('a', -(1 OR 2));
DROP TABLE t1;
SET sql_mode = default;
```
### 2. What did you expect to see?
```sql
mysql> SELECT NAME_CONST('flag', SQRT(4)) * MAX(a) FROM t1;
ERROR 1210 (HY000): Incorrect arguments to NAME_CONST

mysql> SELECT NAME_CONST('flag',-SQRT(4)) * MAX(a) FROM t1;
ERROR 1210 (HY000): Incorrect arguments to NAME_CONST

mysql> SELECT NAME_CONST('a', -(1 OR 2));
ERROR 1210 (HY000): Incorrect arguments to NAME_CONST
```
### 3. What did you see instead
```sql
tidb> SELECT NAME_CONST('flag', SQRT(4)) * MAX(a) FROM t1;
ERROR 1210 (HY000): Incorrect arguments to NAME_CONST

tidb>SELECT NAME_CONST('flag',-SQRT(4)) * MAX(a) FROM t1;
+--------------------------------------+
| NAME_CONST('flag',-SQRT(4)) * MAX(a) |
+--------------------------------------+
| -6 |
+--------------------------------------+
1 row in set (0.03 sec)

tidb> SELECT NAME_CONST('a', -(1 OR 2));
+----+
| a |
+----+
| -1 |
+----+
1 row in set (0.01 sec)
```
### 4. What is your TiDB version?
```
tidb_version(): Release Version: v5.5.0-alpha-210-g11f4ca802
Edition: Community
Git Commit Hash: 11f4ca802083ee38d5972730ba8f9b72395316fb
Git Branch: master
UTC Build Time: 2022-02-09 22:07:29
GoVersion: go1.17.2
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.