set_var在子查询中失效

如题,在测试SET_VAR时候,发现子查询中使用该Hint时,并不会生效。

mysql> SELECT /*+ SET_VAR(MAX_EXECUTION_TIME=1234) */ @@MAX_EXECUTION_TIME;
+----------------------+
| @@MAX_EXECUTION_TIME |
+----------------------+
|                 1234 |
+----------------------+
1 row in set (0.01 sec)

mysql> 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 (0.00 sec)

mysql> SELECT a.inner_time from (select /*+ SET_VAR(MAX_EXECUTION_TIME=12345) */ @@MAX_EXECUTION_TIME as inner_time) a;
+------------+
| inner_time |
+------------+
|     600000 |
+------------+
1 row in set (0.00 sec)


看描述,SET_VAR是查询块范围的Hint,而不是后续的查询范围生效的 Hint,所以应该是个BUG

提了个 issue
https://github.com/pingcap/tidb/issues/53102

此话题已在最后回复的 60 天后被自动关闭。不再允许新回复。