set_var not works for the subquery
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
Please answer these questions before submitting your issue. Thanks!
### 1. Minimal reproduce step (Required)
```sql
SELECT /*+ SET_VAR(MAX_EXECUTION_TIME=1234) */ @@MAX_EXECUTION_TIME;
SELECT /*+ SET_VAR(MAX_EXECUTION_TIME=1234) */ @@MAX_EXECUTION_TIME, a.inner_time from (select /*+ SET_VAR(MAX_EXECUTION_TIME=12345) */ @@MAX_EXECUTION_TIME as inner_time) a;
SELECT a.inner_time from (select /*+ SET_VAR(MAX_EXECUTION_TIME=12345) */ @@MAX_EXECUTION_TIME as inner_time) a;
```
### 2. What did you expect to see? (Required)
set_var affect the subquery
### 3. What did you see instead (Required)
set_var not works for the subquery
```sql
[14:55:54]TiDB root:test> SELECT /*+ SET_VAR(MAX_EXECUTION_TIME=1234) */ @@MAX_EXECUTION_TIME;
+----------------------+
| @@MAX_EXECUTION_TIME |
+----------------------+
| 1234 |
+----------------------+
1 row in set
Time: 0.003s
[14:56:04]TiDB root:test> SELECT /*+ SET_VAR(MAX_EXECUTION_TIME=1234) */ @@MAX_EXECUTION_TIME, a.inner_time from (select /*+ SET_VAR(MAX_EXECUTION_TIME=12345) */ @@MAX_EXECUTION_TIME as inner_time) a;
+----------------------+------------+
| @@MAX_EXECUTION_TIME | inner_time |
+----------------------+------------+
| 1234 | 1234 |
+----------------------+------------+
1 row in set
Time: 0.003s
[14:56:12]TiDB root:test> SELECT a.inner_time from (select /*+ SET_VAR(MAX_EXECUTION_TIME=12345) */ @@MAX_EXECUTION_TIME as inner_time) a;
+------------+
| inner_time |
+------------+
| 0 |
+------------+
1 row in set
Time: 0.004s
```
### 4. What is your TiDB version? (Required)
```sql
[14:58:09]TiDB root:test> select tidb_version();
+-----------------------------------------------------------+
| tidb_version() |
+-----------------------------------------------------------+
| Release Version: v8.1.0 |
| Edition: Community |
| Git Commit Hash: da39e1ca55c6051a1cbcd84dc230b8ba42f8075f |
| Git Branch: HEAD |
| UTC Build Time: 2024-05-06 05:55:37 |
| GoVersion: go1.21.6 |
| Race Enabled: false |
| Check Table Before Drop: false |
| Store: tikv |
+-----------------------------------------------------------+
1 row in set
```
Contributor guide
Assessment
This issue has not been assessed yet.