Skip to content

[Bug]: KILL QUERY / KILL CONNECTION does not cancel long-running Window+UNION query (session stays COM_QUERY for 40h+) #26067

Closed

Description

Is there an existing issue for the same bug?

  • I have checked existing issues. Related themes exist around session/txn cleanup, but not this Window pipeline cancel failure.

Branch Name

main

Commit ID

826a3e3d294ba62c7c4da217d1445f3c568ce4d9

Image: registry.cn-shanghai.aliyuncs.com/matrixorigin/matrixone:nightly-826a3e3d

Other Environment Information

- Hardware: single-node MO (docker, host port 16001), rootless docker on Linux
- OS: Linux
- Dataset: jinpan_001
- Suite: cases/jinpan_001/join_adv @q1004_adv_window_frame_running
- Client: mo-regression-test run.py --sql-timeout 1200 (func_timeout + side-connection KILL)

Actual Behavior

  1. Start a heavy Window + UNION ALL + outer LIMIT 200 query over large dwd_s4_acdoca (see q1004.sql).
  2. Client hits 20-minute SQL timeout and issues cleanup:
Timeout cleanup: KILL QUERY <conn_id>
Timeout cleanup: KILL CONNECTION <conn_id>
  1. KILL statements return without error.
  2. information_schema.processlist still shows the same conn_id as COM_QUERY with the original SQL.
  3. In our run, the statement stayed active for 40+ hours (run_sec ≈ 146700+), CPU still busy (~200%+ on the container), memory ~13GiB — no panic/OOM in CN logs.
  4. Regression runner cannot advance to the next SQL because the server query / connection never finishes after the client-side timeout.

Manual retry also fails to stop it:

KILL QUERY 2208;      -- no error
KILL 2208;            -- no error
-- processlist still: conn_id=2208, command=COM_QUERY, same query_start

Only docker restart of the MO container clears the session.

Expected Behavior

  • KILL QUERY <id> cancels the running statement promptly.
  • KILL CONNECTION <id> / KILL <id> disconnects the session and aborts the pipeline.
  • After a successful KILL, the conn_id must disappear from processlist (or move out of COM_QUERY) within a short time.
  • Client timeout paths that issue KILL must be able to reclaim the CN and continue other work.

Steps to Reproduce

  1. Use nightly image matrixone:nightly-826a3e3d with jinpan_001 loaded (or any large table reproducing a multi-minute Window query).
  2. In session A, run q1004.sql (Window over ~16M filtered rows, duplicated under UNION ALL, outer LIMIT 200).
  3. Note conn_id from SHOW PROCESSLIST / information_schema.processlist.
  4. In session B:
KILL QUERY <conn_id>;
-- and/or
KILL CONNECTION <conn_id>;
KILL <conn_id>;
  1. Re-check processlist: query is still COM_QUERY with the same query_start.
  2. Observe it continues for a long time (in our case >40h until container restart).

Repro SQL

Same as join_adv q1004 (full text in q1004.sql). Shape:

SELECT u.* FROM (
  SELECT * FROM ( /* window over acdoca ~16M rows */ ) a
  UNION ALL
  SELECT * FROM ( /* identical window query */ ) a
) u
LIMIT 200;

Additional Context / Evidence

Time (CST) Event
2026-07-21 18:36:20 Query start (conn 2208)
2026-07-21 18:56:20 Client timeout; KILL QUERY/CONNECTION 2208 logged
2026-07-23 11:21+ Same conn 2208 still COM_QUERY, run_sec≈146700
  • Plan type: AP QUERY PLAN ON ONE CN with nested Window + Partition under Union All (see companion enhancement issue on LIMIT/UNION short-circuit).
  • No matching panic/fatal for this statement_id in docker logs during the hang window.
  • Separate enhancement issue covers optimizer/efficiency; this issue is specifically about cancel not working.

Impact

  • Makes per-SQL timeouts useless for this class of query.
  • Blocks entire join_adv / long-running regression suites (one uncancellable SQL freezes the worker).
  • Requires container restart to recover — unacceptable for shared CI clusters.

Suggested direction (for implementers)

  • Ensure Window / Partition / merge pipeline operators periodically check cancel context.
  • Make KILL QUERY mark the session aborted even if an operator is inside a long sort/spill.
  • Add a regression test: start a long Window query, KILL it, assert processlist clears within N seconds.

Activity

  1. ghost added
    severity/s0
    on Jul 23, 2026
  2. ghost added
    kind/bug
    on Jul 23, 2026
  3. ghost added theissue type on Jul 23, 2026
  4. ghost added this to the MO-202607 milestone on Jul 23, 2026
  5. XuPeng-SH commented on Jul 24, 2026

    @XuPeng-SH
    Contributor

    Additional independent reproduction on 2026-07-24, local standalone MatrixOne commit 9c2e84ad5c, TPCH SF10:

    While exploring a single-evaluation rewrite for TPCH Q15, this valid Window+CTE shape became CPU-bound for more than 30 seconds despite the canonical Q15 finishing in about 0.55 s hot:

    WITH revenue AS (
      SELECT l_suppkey AS supplier_no,
             SUM(l_extendedprice * (1-l_discount)) AS total_revenue
      FROM lineitem
      WHERE l_shipdate >= DATE '1995-12-01'
        AND l_shipdate < DATE '1996-03-01'
      GROUP BY l_suppkey
    ), ranked AS (
      SELECT supplier_no, total_revenue,
             MAX(total_revenue) OVER () AS max_revenue
      FROM revenue
    )
    SELECT s_suppkey, s_name, s_address, s_phone, total_revenue
    FROM supplier JOIN ranked ON s_suppkey = supplier_no
    WHERE total_revenue = max_revenue
    ORDER BY s_suppkey;

    I reproduced it twice, once through EXPLAIN ANALYZE and once as a plain query. After the clients disconnected/timed out, both connection IDs remained active in information_schema.processlist and continued consuming about 200% CPU. KILL QUERY followed by KILL CONNECTION returned but did not stop either pipeline. Restarting the standalone service was required to recover.

    This is consistent with the Window pipeline cancellation defect described here and shows it does not require UNION ALL or the jinpan dataset. I filed the separate CTE recomputation opportunity as #26131; the cancellation failure belongs here.

  6. jiangxinmeng1 commented on Jul 24, 2026

    @jiangxinmeng1
    Contributor

    fixed by #26080

  7. ghost closed this as completedon Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugseverity/s0

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions