Skip to content

fix(sql): honor LoopJoin and LIKE cancellation on 4.2 - #30863

Merged
XuPeng-SH merged 3 commits into
4.2-devfrom
fix/30836-loopjoin-cancellation-42-20261022
Oct 22, 2026
Merged

XuPeng-SH merged 3 commits into
4.2-devfrom
fix/30836-loopjoin-cancellation-42-20261022

Conversation

@LeftHandCold

@LeftHandCold LeftHandCold commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Related to #30836. This is the affected 4.2 branch fix; the Main fix is submitted separately.

What this PR does / why we need it:

A no-output LoopJoin can keep scanning inside one Call, and text LIKE can evaluate a large vector without observing cancellation. Even after cancellation reaches the frontend, the worker and transaction can remain active. Observe the existing context at LoopJoin work boundaries and between LIKE matches; existing optimized LIKE loops check every 256 rows. Preserve the independent cleanup owner for temporary condition windows on error.

Also initialize the reused session Process at the actual request boundary. After replacing its top context, doComQuery calls the existing ResetQueryContext. Previously, a completed request canceled its context, and the following frontend SHOW evaluated WHERE using that stale proc.Ctx. The added LIKE checks exposed this as spurious context canceled errors. Fresh/current canceled requests must remain canceled; refreshing the context must not revive them.

This adds one reset call per request. No new state, goroutines, timers, matching algorithm, cache policy, or per-row work in the follow-up correction. Do not change low-level ReplaceTopCtx, since compiler callers also use it with active pipeline contexts. Keep 4.2's existing SQL, Unicode/escape and error-code behavior.

Current validation

Follow-up revision: aa160a4d3fa382aa3707c81d069e3a0114e6fe57.

Base/merge-base: 4b11cd642008a0fd86ee3087d788f9c057b8a11a. The follow-up repairs 31b29045d5ea2c1c82432b0c71a521aee4eae0ab without a rebase.

  • Before fix: actual MySQL protocol on one pinned connection reproduces the CI failures after a completed SELECT: SHOW VARIABLES WHERE LIKE/ILIKE and SHOW COLLATION WHERE LIKE return 1105/HY000: context canceled. Same-request multi-statement control passes. The final request-boundary regression also fails with the unfixed source overlay.
  • After fix: seven public SQL cases pass normally and under race, asserting actual result sets: LIKE, ILIKE, collation, empty results, mixed engine/frontend multi-statements, nested SET, and staged SQL_MODE.
  • Frontend: all 1,600 top-level tests pass normally and under race. The new boundary test covers live/canceled/expired current requests with live/canceled previous contexts, including parse failure and subsequent cancellation propagation; exact race x100 passes.
  • Original owning packages: LoopJoin 31 tests pass normally and under race; function 1,277 normal / 1,276 race pass (one existing allocation-only test has a !race build tag). All four exact LoopJoin and three exact LIKE cancellation tests independently pass race x100. These sources were unchanged by the follow-up.
  • Incremental SCA over frontend, embed, LoopJoin and function: gofmt/diff checks, explicit Go vet, configured golangci-lint v2.6.2 pass with 0 issues. Molint has 0 new diagnostics against the verified base; both have the same existing routine.go checkrecover diagnostic.
  • Matching native libraries built through top-level make cgo; service built with make build-with-prebuilt-native and native-loader/version smoke passes. Platform: macOS arm64, Go 1.26.4.

Required gpt-6.1-sol / xhigh gates (actual CLI turn_context independently verified):

  • Design GO: session 01a163ec-16a4-7691-a430-7ba50634337b, reviewed parent 31b29045d5ea2c1c82432b0c71a521aee4eae0ab and the request-boundary correction.
  • Final overall review: GO, no unresolved material blockers; session 01a163f9-245e-7952-b6b0-6c352fda55a9, complete nine-file diff SHA-256 81d522a1341c903eaa7b82c7b7a0fca5b1621426de7f6f08b2f33ebfa30ef2d7..

Validation limits

Original public cancellation acceptance on the 4.2 baseline/candidate showed KILL QUERY, KILL CONNECTION and confirmed disconnect release the worker and transaction, with connection reuse where applicable. Those remote acceptance runs are historical evidence from the original patch, not rerun measurements for this follow-up. Current tests revalidate request cancellation ancestry plus the real LoopJoin/LIKE cancellation and cleanup paths.

Current public regression uses one CN. Full proxy/pessimistic BVT and remote CI remain pending; local checks are not a claim that remote CI passed. A single in-progress Go regexp match is still not asynchronously preemptible, so this does not promise a fixed cancellation SLA for arbitrary single-row text. The original expensive query is not made intrinsically faster by this cancellation fix.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@LeftHandCold LeftHandCold left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审结论:基于最新 aa160a4d3fa382aa3707c81d069e3a0114e6fe57,代码层面无未解决的阻断项,建议 Approve。当前账户与作者相同,不能提交正式自我 APPROVE,因此以 COMMENT 记录结论;不等同于 required CI 已通过。

本轮先发现并核实了旧 HEAD 31b29045 的真实回归:已有 BVT 中 SHOW VARIABLES WHERE ILIKE 和 SHOW COLLATION WHERE LIKE 返回 context canceled。随后 PR 在复审期间更新,新增请求入口的 ReplaceTopCtx → ResetQueryContext 正好关闭了该问题:刷新的是复用 Process 的当前请求执行 context,未修改所有调用者共享的 ReplaceTopCtx 语义,也没有在 LIKE 中忽略真正的取消。新测试固定同一 SQL 连接检查连续请求、多语句、nested SET、SQL_MODE 分段及精确结果;frontend 测试覆盖当前请求 live/canceled/deadline、旧 context 状态与解析失败边界。

完整覆盖九个变更文件。按 mo-self-review / mo-dev / unhappy-path-audit 核对了 LoopJoin 错误返回、临时 window 的独立清理指针、Reset/Free、LIKE 的匹配/NULL/selection 及 4.2 特有语义;未发现新增状态机、无界资源或明显性能回归。没有将 Main 的 PairCondition/Unicode 变化夹带到 4.2。

验证范围说明:

  • 独立检查了原修复的原始 owning normal/race、exact race x100、真实 KILL/断连 worker+txn 退出和 LIKE benchmark 记录,并比对六个文件内容哈希;这些文件在新提交中未变化。
  • 本轮对新增 frontend 修正完成调用链和全部测试代码复查、diff/格式检查;PR 描述报告的新一轮 frontend/embed normal/race 结果未在本轮重复执行,未冒充独立重跑。
  • 新 HEAD 的远端 CI 仍在排队/运行;旧 HEAD 的红灯不能作为新 HEAD 已失败或已通过的结论。合并前仍须按仓库规则完成门禁。
  • 仍是协作式取消,不保证中断单次正在执行的超大文本 regexp,也不声称让原 SQL 本身变快。

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve for aa160a4d3fa382aa3707c81d069e3a0114e6fe57 after reviewing all nine changed files and the request → Process → compiler/pipeline → LoopJoin/LIKE ownership paths. No blocking code finding.

  • The implementation reuses the existing cancellation source, vm.CancelCheck, query-context reset, and operator cleanup. It closes the non-yielding LoopJoin/LIKE polling gaps without another state machine or compatibility path. The temporary condition window now has explicit ownership independent of named return values.
  • The earlier SHOW cancellation regression is resolved at the request boundary. Independent same-connection SQL probes cover binary prepared LIKE execution, subsequent SHOW, parse failure, and reuse. Removing only the new reset reproduces context canceled; the reviewed head passes. A separate live-context Eval-error probe detects the old window-cleanup defect and passes with the new ownership code.
  • Local targeted cancellation/context tests and the public SQL regression passed on macOS arm64 / Go 1.26.4. Independently inspected current-head CI shows all four changed owning packages passing race UT, non-race coverage UT passing, SCA reporting 0 issues, and both Compose PROXY and Pessimistic BVT passing, including the historical SHOW/LIKE regression cases. No unresolved technical review thread remains.

CI is still red: race UT fails TestGlobalCheckpoint2 at AllFlushExpected(now, 4000), while a catalog flush takes about 5.25 seconds. Later checkpoint cancellation is teardown after the assertion. There is no evidence tying this to the changed SQL paths, but I did not establish a preexisting failure through a controlled baseline reproduction. This approval does not bypass required CI.

Limits: cancellation remains cooperative and cannot interrupt one in-progress regexp match. Local alternating base/head LIKE benchmarks were too noisy under host contention to quantify performance changes. The original public KILL/disconnect worker-and-transaction acceptance was inspected and reused for the unchanged LoopJoin/LIKE files, not independently rerun here.

@XuPeng-SH
XuPeng-SH merged commit 17f4f87 into 4.2-dev Oct 22, 2026
@XuPeng-SH
XuPeng-SH deleted the fix/30836-loopjoin-cancellation-42-20261022 branch October 22, 2026 17:15

This branch was previously deployed

1 inactive deployment
ci — aa160a4d Deployed Oct 22, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants