pingcap / pingcap/tidb

set_var not works for the subquery

Open
#53,102 3 comments 0 reactions 1 assignee Claimed by @qw4990 View on GitHub
affects-7.5 affects-8.1 report/community severity/minor sig/planner type/bug
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

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.