Repository navigation
Description
Description
system.statement_info.result_count is recorded as 1 for a scalar SELECT canceled by KILL QUERY, even though the client receives an error and zero result rows.
Environment
- Branch:
main - Commit:
8e616a693458652cc26b3c4be45c6602dff298d4 - Deployment: local two-CN cluster,
./mo-service -launch etc/launch-multi-cn/launch.toml - Date: 2026-08-26
Steps to reproduce
Session 1:
SET disable_agg_statement = 1;
/*stmt_cancel_result_count*/ SELECT SLEEP(20);While the query is running, obtain its connection ID from SHOW FULL PROCESSLIST and cancel it from Session 2:
KILL QUERY <connection_id>;Then query the final statement record:
SELECT status, err_code, error, result_count, connection_id
FROM system.statement_info
WHERE statement LIKE '/*stmt_cancel_result_count%';Actual behavior
The client exits with code 1, prints ERROR 1105 (HY000): context canceled, and writes zero bytes to stdout. The final record is:
status err_code error result_count
Failed 100 context canceled 1
Expected behavior
result_count should be 0 because no result row was sent to the client.
Stability and controls
- Reproducer: 3/3; all three canceled queries recorded
Failed,context canceled, andresult_count=1, while each client result file was empty. - Additional minimal run: client exit code
1, stdout0bytes, same incorrectresult_count=1. - Passing control: a successful scalar
SELECTrecordsresult_count=1. - Failing controls: duplicate-key, missing-table, and syntax failures record
result_count=0. - The database remains usable after every cancellation; no panic, hang, or data mutation is involved.
Evidence
round 1: Failed | 100 | context canceled | result_count=1 | client stdout=0 bytes
round 2: Failed | 100 | context canceled | result_count=1 | client stdout=0 bytes
round 3: Failed | 100 | context canceled | result_count=1 | client stdout=0 bytes
Code analysis
pkg/frontend/session.go defines sentRows as the number of rows sent to the client. pkg/frontend/mysql_cmd_executor.go:getDataFromPipeline increments it with bat.RowCount() after RespResult, and pkg/frontend/util.go:finishStatementAccounting passes the value to StatementInfo.EndStatement even when the statement ends with an error.
The observed behavior suggests that the canceled scalar expression contributes a one-row pipeline batch before the cancellation error reaches terminal statement accounting, although no row is delivered to the client. The fix should make result_count follow successfully delivered protocol rows, including cancellation/error paths.
Regression coverage
Add a multi-session motr scenario: run a blocking scalar SELECT, cancel it through a second connection, assert the client receives an error with zero rows, then assert the final statement_info row is Failed with result_count=0.
Related
- No matching open or closed issue was found using
statement_info,result_count,KILL QUERY, andcontext canceledsearches.
Activity
XuPeng-SH commentedon Oct 23, 2026
The
result_countfailure is now tracked under #30913 with the server-side cursor accounting case. Both violate the contract that statement output statistics reflect protocol rows actually delivered: cursor FETCH undercounts delivered rows, while a canceled scalar SELECT counts an internal row that never reached the client.The parent now has separate reproductions and independent regression criteria for each path. Closing this issue records tracking consolidation only; its original evidence remains here and no fix is claimed.