From 580eb2543d8722dae46cfc9c26855d5c52cea6ca Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Thu, 4 Jan 2024 22:00:34 +0800 Subject: [PATCH] bindinfo: extract the table hint from the union statement (#50070) close pingcap/tidb#50068 --- pkg/server/conn_test.go | 3 ++- pkg/util/hint/hint_processor.go | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/server/conn_test.go b/pkg/server/conn_test.go index 67dd9da420c97..de06081e291a6 100644 --- a/pkg/server/conn_test.go +++ b/pkg/server/conn_test.go @@ -735,7 +735,8 @@ func TestConnExecutionTimeout(t *testing.T) { err = cc.handleQuery(context.Background(), "select /*+ MAX_EXECUTION_TIME(100)*/ * FROM testTable2 WHERE SLEEP(1);") require.Equal(t, "[executor:3024]Query execution was interrupted, maximum statement execution time exceeded", err.Error()) - + err = cc.handleQuery(context.Background(), "select /*+ set_var(max_execution_time=100) */ age, sleep(1) from testTable2 union all select age, 1 from testTable2") + require.Equal(t, "[executor:3024]Query execution was interrupted, maximum statement execution time exceeded", err.Error()) // Killed because of max execution time, reset Killed to 0. tk.Session().GetSessionVars().SQLKiller.SendKillSignal(sqlkiller.MaxExecTimeExceeded) tk.MustExec("set @@max_execution_time = 500;") diff --git a/pkg/util/hint/hint_processor.go b/pkg/util/hint/hint_processor.go index 14b286bde5bcc..7a296e74ad943 100644 --- a/pkg/util/hint/hint_processor.go +++ b/pkg/util/hint/hint_processor.go @@ -88,6 +88,18 @@ func ExtractTableHintsFromStmtNode(node ast.Node, sctx sessionctx.Context) []*as // check duplicated hints checkInsertStmtHintDuplicated(node, sctx) return x.TableHints + case *ast.SetOprStmt: + var result []*ast.TableOptimizerHint + if x.SelectList == nil { + return nil + } + for _, s := range x.SelectList.Selects { + tmp := ExtractTableHintsFromStmtNode(s, sctx) + if len(tmp) != 0 { + result = append(result, tmp...) + } + } + return result default: return nil }