[BugFix] Avoid optimization time exceeding the limit in ApplyRuleTask (backport #50795) #50838
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why I'm doing:
MultiJoinBinder
will cause slow locks sometimes:What I'm doing:
Fixes #issue
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check:
This is an automatic backport of pull request #50795 done by [Mergify](https://mergify.com). ## Why I'm doing: - `MultiJoinBinder` will cause slow locks sometimes: ``` 024 - 09 - 03 06 : 59 : 49.641Z WARN(starrocks - mysql - nio - pool - 3278 | 15273792)[LockManager.logSlowLockTrace() : 398] LockManager detects slow lock: { "owners": [{ "id": 15246789, "name": "thrift-server-pool-14973570", "heldFor": 2133813, "waitTime": 0, "stack": ["app//com.starrocks.sql.optimizer.rule.Binder$MultiJoinBinder.enumerate(Binder.java:202)", "app//com.starrocks.sql.optimizer.rule.Binder$MultiJoinBinder.match(Binder.java:190)", "app//com.starrocks.sql.optimizer.rule.Binder.match(Binder.java:109)", "app//com.starrocks.sql.optimizer.rule.Binder.next(Binder.java:96)", "app//com.starrocks.sql.optimizer.task.ApplyRuleTask.execute(ApplyRuleTask.java:104)", "app//com.starrocks.sql.optimizer.task.SeriallyTaskScheduler.executeTasks(SeriallyTaskScheduler.java:65)", "app//com.starrocks.sql.optimizer.Optimizer.memoOptimize(Optimizer.java:803)", "app//com.starrocks.sql.optimizer.Optimizer.optimizeByCost(Optimizer.java:260)", "app//com.starrocks.sql.optimizer.Optimizer.optimize(Optimizer.java:184)", "app//com.starrocks.sql.StatementPlanner.createQueryPlan(StatementPlanner.java:219)", "app//com.starrocks.sql.StatementPlanner.plan(StatementPlanner.java:130)", "app//com.starrocks.sql.StatementPlanner.plan(StatementPlanner.java:92)", "app//com.starrocks.qe.StmtExecutor.execute(StmtExecutor.java:533)", "app//com.starrocks.qe.ConnectProcessor.proxyExecute(ConnectProcessor.java:811)", "app//com.starrocks.service.FrontendServiceImpl.forward(FrontendServiceImpl.java:1207)", "app//com.starrocks.thrift.FrontendService$Processor$forward.getResult(FrontendService.java:4481)", "app//com.starrocks.thrift.FrontendService$Processor$forward.getResult(FrontendService.java:4461)", "app//org.apache.thrift.ProcessFunction.process(ProcessFunction.java:40)", "app//org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:40)", "app//com.starrocks.common.SRTThreadPoolServer$WorkerProcess.run(SRTThreadPoolServer.java:311)"] },
2024 - 09 - 03 07 : 02 : 39.354Z WARN(thrift - server - pool - 15005392 | 15278893)[LockManager.logSlowLockTrace() : 398] LockManager detects slow lock: {
"owners": [{
"id": 15246789,
"name": "thrift-server-pool-14973570",
"heldFor": 2303527,
"waitTime": 0,
"stack": ["app//com.starrocks.sql.optimizer.rule.Binder$MultiJoinBinder.enumerate(Binder.java:202)", "app//com.starrocks.sql.optimizer.rule.Binder$MultiJoinBinder.match(Binder.java:190)", "app//com.starrocks.sql.optimizer.rule.Binder.match(Binder.java:109)", "app//com.starrocks.sql.optimizer.rule.Binder.next(Binder.java:96)", "app//com.starrocks.sql.optimizer.task.ApplyRuleTask.execute(ApplyRuleTask.java:104)", "app//com.starrocks.sql.optimizer.task.SeriallyTaskScheduler.executeTasks(SeriallyTaskScheduler.java:65)", "app//com.starrocks.sql.optimizer.Optimizer.memoOptimize(Optimizer.java:803)", "app//com.starrocks.sql.optimizer.Optimizer.optimizeByCost(Optimizer.java:260)", "app//com.starrocks.sql.optimizer.Optimizer.optimize(Optimizer.java:184)", "app//com.starrocks.sql.StatementPlanner.createQueryPlan(StatementPlanner.java:219)", "app//com.starrocks.sql.StatementPlanner.plan(StatementPlanner.java:130)", "app//com.starrocks.sql.StatementPlanner.plan(StatementPlanner.java:92)", "app//com.starrocks.qe.StmtExecutor.execute(StmtExecutor.java:533)", "app//com.starrocks.qe.ConnectProcessor.proxyExecute(ConnectProcessor.java:811)", "app//com.starrocks.service.FrontendServiceImpl.forward(FrontendServiceImpl.java:1207)", "app//com.starrocks.thrift.FrontendService$Processor$forward.getResult(FrontendService.java:4481)", "app//com.starrocks.thrift.FrontendService$Processor$forward.getResult(FrontendService.java:4461)", "app//org.apache.thrift.ProcessFunction.process(ProcessFunction.java:40)", "app//org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:40)", "app//com.starrocks.common.SRTThreadPoolServer$WorkerProcess.run(SRTThreadPoolServer.java:311)"]
},