Skip to content

fix(runaway): ensure DistSQLContext's checker is synchronized with session variables#61907

Merged
ti-chi-bot[bot] merged 1 commit intopingcap:masterfrom
JmPotato:fix_subquery_ru_runaway
Jun 23, 2025
Merged

fix(runaway): ensure DistSQLContext's checker is synchronized with session variables#61907
ti-chi-bot[bot] merged 1 commit intopingcap:masterfrom
JmPotato:fix_subquery_ru_runaway

Conversation

@JmPotato
Copy link
Member

@JmPotato JmPotato commented Jun 21, 2025

What problem does this PR solve?

Issue Number: close #61899.

What changed and how does it work?

Update GetDistSQLCtx to check and align the RunawayChecker in the cached DistSQL context with the session's current value.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)

Prepare:

create table t1(a int, b int);
insert into t1 value(rand()*1000, rand()*1000); x 44600

mysql> select count(*) from t1;
+----------+
| count(*) |
+----------+
|    44600 |
+----------+
1 row in set (0.01 sec)

mysql> CREATE RESOURCE GROUP IF NOT EXISTS rg1 RU_PER_SEC = 100 QUERY_LIMIT=(RU=10, ACTION=KILL);
Query OK, 0 rows affected (0.06 sec)

mysql> SET RESOURCE GROUP rg1;
Query OK, 0 rows affected (0.00 sec)

Before:

mysql> explain analyze select * from t1 where b > 36;
ERROR 8253 (HY000): Query execution was interrupted, identified as runaway query [RequestUnit = RRU:13.419626, WRU:0.000000, WaitDuration:0s(10)]

mysql> explain analyze select min(a)+10 from t1 where a < 639;
ERROR 8253 (HY000): Query execution was interrupted, identified as runaway query [RequestUnit = RRU:38.330615, WRU:0.000000, WaitDuration:0s(10)]

mysql> explain analyze select * from t1 where b > (select min(a)+3 from t1 where a < 452);
+--------------------------+----------+---------+-----------+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------+----------+------+
| id                       | estRows  | actRows | task      | access object | execution info                                                                                                                                                                                                                                                                                                                                                                                                                            | operator info                                    | memory   | disk |
+--------------------------+----------+---------+-----------+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------+----------+------+
| TableReader_36           | 18466.67 | 44437   | root      |               | time:217.3ms, loops:46, RU:78.809008, cop_task: {num: 9, max: 121.4ms, min: 572.6µs, avg: 24.1ms, p95: 121.4ms, max_proc_keys: 17376, p95_proc_keys: 17376, tot_proc: 25.1ms, tot_wait: 370.2µs, copr_cache_hit_ratio: 0.00, build_task_duration: 8.17µs, max_distsql_concurrency: 1}, rpc_info:{Cop:{num_rpc:9, total_time:217.1ms}}                                                                                                     | data:Selection_35                                | 414.5 KB | N/A  |
| └─Selection_35           | 18466.67 | 44437   | cop[tikv] |               | tikv_task:{proc max:8ms, min:0s, avg: 2.78ms, p80:6ms, p95:8ms, iters:79, tasks:9}, scan_detail: {total_process_keys: 44600, total_process_keys_size: 1906316, total_keys: 44609, get_snapshot_time: 199µs, rocksdb: {key_skipped_count: 44600, block: {cache_hit_count: 93}}}, time_detail: {total_process_time: 25.1ms, total_suspend_time: 45.2µs, total_wait_time: 370.2µs, total_kv_read_wall_time: 25ms, tikv_wall_time: 26.2ms}    | gt(test.t1.b, 3)                                 | N/A      | N/A  |
|   └─TableFullScan_34     | 55400.00 | 44600   | cop[tikv] | table:t1      | tikv_task:{proc max:8ms, min:0s, avg: 2.78ms, p80:6ms, p95:8ms, iters:79, tasks:9}                                                                                                                                                                                                                                                                                                                                                        | keep order:false, stats:partial[b:unInitialized] | N/A      | N/A  |
+--------------------------+----------+---------+-----------+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------+----------+------+
3 rows in set (0.24 sec)

After:

mysql> explain analyze select min(a)+10 from t1 where a < 639;
ERROR 8253 (HY000): Query execution was interrupted, identified as runaway query [RequestUnit = RRU:29.563074, WRU:0.000000, WaitDuration:0s(10)]

mysql> explain analyze select * from t1 where b > 36;
ERROR 8253 (HY000): Query execution was interrupted, identified as runaway query [RequestUnit = RRU:10.572321, WRU:0.000000, WaitDuration:0s(10)]

mysql> explain analyze select * from t1 where b > (select min(a)+3 from t1 where a < 452);
ERROR 8253 (HY000): Query execution was interrupted, identified as runaway query [RequestUnit = RRU:30.184085, WRU:0.000000, WaitDuration:0s(10)]

Release note

Fixed an issue where the evaluating of non-correlated subqueries could cause runaway configuration to become invalid.

…ssion variables

Signed-off-by: JmPotato <github@ipotato.me>
@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 21, 2025
@codecov
Copy link

codecov bot commented Jun 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.7239%. Comparing base (43c7806) to head (ccefab8).
Report is 12 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #61907        +/-   ##
================================================
+ Coverage   73.0244%   73.7239%   +0.6994%     
================================================
  Files          1735       1735                
  Lines        481425     484380      +2955     
================================================
+ Hits         351558     357104      +5546     
+ Misses       108336     105740      -2596     
- Partials      21531      21536         +5     
Flag Coverage Δ
integration 42.5868% <100.0000%> (?)
unit 72.6025% <100.0000%> (+0.3447%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.7804% <ø> (ø)
parser ∅ <ø> (∅)
br 47.0243% <ø> (+0.4774%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ti-chi-bot
Copy link

ti-chi-bot bot commented Jun 23, 2025

@lhy1024: adding LGTM is restricted to approvers and reviewers in OWNERS files.

Details

In response to this:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 23, 2025
@ti-chi-bot
Copy link

ti-chi-bot bot commented Jun 23, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lhy1024, okJiang, xhebox

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jun 23, 2025
@ti-chi-bot
Copy link

ti-chi-bot bot commented Jun 23, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-06-23 03:17:19.029390052 +0000 UTC m=+673691.752569035: ☑️ agreed by okJiang.
  • 2025-06-23 16:06:25.64626348 +0000 UTC m=+719838.369442460: ☑️ agreed by xhebox.

@ti-chi-bot ti-chi-bot bot merged commit 49f4868 into pingcap:master Jun 23, 2025
24 checks passed
morgo added a commit to morgo/tidb that referenced this pull request Jun 24, 2025
* origin/master: (129 commits)
  domain: Fix the issue that the min start ts doesn't correctly block keyspace-level GC (pingcap#61925)
  br: better control pd scheduler pause during log restore with filter (pingcap#61819)
  session: rename circuit breaker sysvar (pingcap#61951)
  dxfservice: create store for SYSTEM keyspace (pingcap#61752)
  docs: fix a dead link in CONTRIBUTORS.md (pingcap#61923)
  metrics/nextgengrafana: display keyspace separately (pingcap#61823)
  lightning: fix length check may be skipped for first line (pingcap#61874)
  planner: support `explain [analyze] <plan_digest>` for `explain explore` (pingcap#61942)
  planner: record explored plans into `tidb_statement_stats` when running `explain explore` (pingcap#61850)
  fix(runaway): ensure DistSQLContext's checker is synchronized with session variables (pingcap#61907)
  expression,planner: reuse the propOuterJoinConstSolver to improve performance (pingcap#61913)
  ddl,planner: remove unused and meaningless code (pingcap#61936)
  planner: remove unused field from physicalTableScan. (pingcap#61935)
  workload-learning: Extract metrics from cluster statements stats (pingcap#61378)
  executor: minor cleanup in builder.go (pingcap#61924)
  session: rename GetDomainInfoSchema to GetLatestInfoSchema (pingcap#61894)
  ingest: retry failed regions when batch scatter regions (pingcap#61722)
  planner: add tpch q1,q2,q3 benchmark (pingcap#61898)
  planner: fix uninit timeout for loading bindings (pingcap#61891)
  executor: report error when admin check on multiple tables (pingcap#61828)
  ...
@JmPotato JmPotato deleted the fix_subquery_ru_runaway branch June 24, 2025 14:42
@JmPotato
Copy link
Member Author

JmPotato commented Jul 4, 2025

/cherry-pick release-8.5

@ti-chi-bot
Copy link
Member

@JmPotato: new pull request created to branch release-8.5: #62220.

Details

In response to this:

/cherry-pick release-8.5

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@JmPotato
Copy link
Member Author

JmPotato commented Jul 9, 2025

/cherry-pick release-7.5

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jul 9, 2025
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

@JmPotato: new pull request created to branch release-7.5: #62319.
But this PR has conflicts, please resolve them!

Details

In response to this:

/cherry-pick release-7.5

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Evaluating a scalar non-correlated subquery will invalidate the RunawayChecker

5 participants