Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: fix the issue that statement-level hints in sub-queries of Insert/Replace can not take effect #54083

Merged
merged 3 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/bindinfo/session_handle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,13 @@ func TestIssue53834(t *testing.T) {
defer func() {
tk.MustExec(fmt.Sprintf(`set global tidb_mem_oom_action='%v'`, oomAction))
}()

tk.MustExec(`set global tidb_mem_oom_action='cancel'`)
err := tk.ExecToErr(`replace into t select /*+ memory_quota(1 mb) */ * from t`)
require.ErrorContains(t, err, "cancelled due to exceeding the allowed memory limit")

tk.MustExec(`create binding using replace into t select /*+ memory_quota(1 mb) */ * from t`)
err := tk.ExecToErr(`replace into t select * from t`)
err = tk.ExecToErr(`replace into t select * from t`)
require.ErrorContains(t, err, "cancelled due to exceeding the allowed memory limit")
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/session/test/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,11 @@ func TestStmtHints(t *testing.T) {
val = int64(1) * 1024 * 1024
require.True(t, tk.Session().GetSessionVars().MemTracker.CheckBytesLimit(val))

tk.MustExec("insert /*+ MEMORY_QUOTA(1 MB) */ into t1 select /*+ MEMORY_QUOTA(3 MB) */ * from t1;")
tk.MustExec("insert /*+ MEMORY_QUOTA(1 MB) */ into t1 select /*+ MEMORY_QUOTA(1 MB) */ * from t1;")
val = int64(1) * 1024 * 1024
require.True(t, tk.Session().GetSessionVars().MemTracker.CheckBytesLimit(val))
require.Len(t, tk.Session().GetSessionVars().StmtCtx.GetWarnings(), 1)
require.EqualError(t, tk.Session().GetSessionVars().StmtCtx.GetWarnings()[0].Err, "[planner:3126]Hint MEMORY_QUOTA(`3145728`) is ignored as conflicting/duplicated.")
require.Len(t, tk.Session().GetSessionVars().StmtCtx.GetWarnings(), 2)
require.EqualError(t, tk.Session().GetSessionVars().StmtCtx.GetWarnings()[0].Err, "[planner:3126]Hint MEMORY_QUOTA(`1048576`) is ignored as conflicting/duplicated.")

// Test NO_INDEX_MERGE hint
tk.Session().GetSessionVars().SetEnableIndexMerge(true)
Expand Down
13 changes: 12 additions & 1 deletion pkg/util/hint/hint_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,18 @@ func ExtractTableHintsFromStmtNode(node ast.Node, warnHandler hintWarnHandler) [
case *ast.InsertStmt:
// check duplicated hints
checkInsertStmtHintDuplicated(node, warnHandler)
return x.TableHints
result := make([]*ast.TableOptimizerHint, 0, len(x.TableHints))
result = append(result, x.TableHints...)
if x.Select != nil {
// support statement-level hint in sub-select: "insert into t select /* ... */ ..."
// TODO: support this for Update and Delete as well
for _, h := range ExtractTableHintsFromStmtNode(x.Select, warnHandler) {
if isStmtHint(h) {
result = append(result, h)
}
}
}
return result
case *ast.SetOprStmt:
var result []*ast.TableOptimizerHint
if x.SelectList == nil {
Expand Down