Skip to content

[Bug]: save_query_result makes SHOW COUNT(*) WARNINGS/ERRORS panic on unsigned count #31498

Closed

Description

@Ariznawlll

Description

With save_query_result=ON, both supported SHOW COUNT(*) WARNINGS and SHOW COUNT(*) ERRORS fail with an internal Go type-assertion panic instead of returning their diagnostic counts. The same statements return 0 with result saving off; ordinary SHOW WARNINGS still works with it on.

Environment

  • Branch: main
  • Commit: f847803802289b2b2d0df4f0a2f842c2804b823a (git_version() = f847803802)
  • Deployment: isolated local standalone, one CN, MySQL port 49301, macOS arm64, 2026-10-28; synthetic data only.

Steps to reproduce

SET save_query_result=OFF;
SHOW COUNT(*) WARNINGS; -- 0
SHOW COUNT(*) ERRORS;   -- 0

SET save_query_result=ON;
/* save_result */ SELECT 1;
SHOW WARNINGS;          -- succeeds, empty
SHOW COUNT(*) WARNINGS; -- 20101 internal error
SHOW COUNT(*) ERRORS;   -- same 20101 internal error
SELECT 2;               -- succeeds: session remains usable

SET save_query_result=OFF;
SHOW COUNT(*) WARNINGS; -- 0 again

Actual behavior

Both count statements return ERROR 20101 internal error: panic interface conversion: interface {} is uint64, not int64. The stack begins in pkg/frontend.convertRowsIntoBatch (util.go:1686), called by trySaveQueryResult from doShowDiagnosticCount. This occurs even when the count is 0 and no warning/error has been generated.

Expected behavior

Result saving should not change the validity or values of the diagnostic-count statements. Both should return an unsigned count (here 0) without an internal panic; saving the result, if supported, should preserve the same value and metadata.

Stability and controls

  • Reproducer: 3/3 fresh databases and sessions (qshowcount_02/03/04) on the pinned SHA; both count statements failed in every round.
  • Normal controls: with saving off, both returned ((0,),) in all three rounds. With saving on, SHOW WARNINGS returned an empty result normally; SELECT 2 succeeded after each failure; switching saving off restored the count query.
  • Failure atomicity/data check: no user data was changed; the SQL session remained usable. The problem is a frontend statement failure and exposed internal panic stack, not an observed service crash.

Evidence

Exact isolated reproducer and per-round output: /private/tmp/mo-explore-run-20261028/show_count_saved_panic.py. Source anchors at this SHA: doShowDiagnosticCount publishes an unsigned MYSQL_TYPE_LONGLONG result and calls trySaveQueryResult; convertRowsIntoBatch asserts row[colIndex].(int64) for the destination vector. The observed uint64 value reaches that assertion.

Code analysis

Confirmed from the returned stack and source: doShowDiagnosticCount's unsigned result enters result-saving conversion as uint64, while the converter assumes int64. The mismatch triggers the panic, which is recovered as SQL error 20101. The repair should align the result metadata/vector type and value conversion without truncating counts above MaxInt64.

Regression coverage

Add frontend integration tests for SHOW COUNT(*) WARNINGS and SHOW COUNT(*) ERRORS with save_query_result on/off, with zero and nonzero counts, followed by result scan and a subsequent query; assert exact values, unsigned metadata, absence of panic and session health.

Related

Activity

  1. added this to the MO-202610 milestone on Oct 28, 2026
  2. added
    kind/bug
    on Oct 28, 2026
  3. added theissue type on Oct 28, 2026
  4. Ariznawlll commented on Oct 28, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充:DATA BRANCH DIFF 可导致服务进程退出

    在同一 main commit f847803802289b2b2d0df4f0a2f842c2804b823a 上,结果保存的同一处 uint64 → int64 断言错误还可以通过 DATA BRANCH DIFF 触发;与 SHOW COUNT 返回 SQL 错误不同,这条路径中的 panic 没有被恢复,导致服务进程退出、客户端连接中断。

    最小复现

    CREATE DATABASE branch_set_repro;
    USE branch_set_repro;
    CREATE TABLE b (id INT PRIMARY KEY, v SET('a','b'));
    INSERT INTO b VALUES (1, 'a');
    DATA BRANCH CREATE TABLE c FROM b;
    UPDATE c SET v = 'a,b' WHERE id = 1;
    
    SET save_query_result = OFF;
    DATA BRANCH DIFF c AGAINST b; -- 正常返回 UPDATE,v 的数值为 3
    
    SET save_query_result = ON;
    DATA BRANCH DIFF c AGAINST b; -- 连接中断,服务进程退出

    实际结果与范围

    • 三个新建数据库复现 3/3;其中两次在独立重启后抓到相同 panic 栈,服务进程退出码为 2。
    • 服务端报 panic: interface conversion: interface {} is uint64, not int64;调用链为 convertRowsIntoBatch → trySaveQueryResult → satisfyDiffOutputOpt → diffMergeAgency.func6。
    • 关闭结果保存时相同 DIFF 正常返回;这是本地隔离单 CN 环境中的结果,尚未验证多 CN。

    建议回归时除了检查返回值,还检查后台路径 panic 恢复、服务进程和其他连接的可用性,以及 SET/无符号值的边界。

  5. XuPeng-SH commented on Oct 28, 2026

    @XuPeng-SH
    Contributor

    QA handoff for merged main 6c7813b588f5122aaacdeca7ce17cd898949acdd (#31559): this environment did not run the affected frontend package or current-head service. The existing resource guard leaves insufficient headroom for a safe large link or service build. git diff --check passed and native/module/proto inputs are unchanged; these do not validate saved-result behavior.

    The PR author reports separate single-CN SHOW COUNT and DATA BRANCH DIFF/SET result-save tests, including saved-result readback and other-connection liveness. Those are not local results here. Please verify both original paths, unsigned boundary values, NULL/type errors, saved metadata and service/connection recovery. Separate JSON/BIT/BLOB and DATETIME reports #31534 and #31547 are not claimed fixed by this PR.

  6. Ariznawlll commented on Oct 28, 2026

    @Ariznawlll
    CollaboratorAuthor

    结论

    测试通过。结果保存开启时的诊断计数和 SET 列 DATA BRANCH DIFF 均正常,原先会终止服务的分支未再触发进程退出。

    关键证据

    • 版本:官方 main@9eb05ce0f5ac5ddce36024aaa21c4c79d3e4334c,包含 修复 PR #31559;隔离 1 Log + 1 TN + 2 CN,测试连接一个 CN 并以第二连接确认存活。
    • 新增 MOTR 回归 定向 3/3:结果保存 on/off 时 SHOW COUNT(*) WARNINGS/ERRORS 返回 0,制造告警后分别返回 1/0;线协议列类型为无符号 LONGLONG。SET 分支 DIFF 在保存开关两种状态下均为 UPDATE, id=1, v=3,result_scan 回读 (1,3);另一个连接继续执行 SELECT 42,基表数据仍为 (1,'a')。
    • 同 SHA 的 pkg/frontend 定向 Go 测试 -count=3 通过:覆盖 0、1、MaxInt64、MaxInt64+1、MaxUint64、NULL 的内部 unsigned 向量及负数、溢出、错误类型拒绝;没有把内部夹具冒充 SQL 线协议结果。

    待解决点

    • 本轮未运行完整 frontend/MOTR suite;MOTR PR Dev/api updates #287 的最新提交 CI 尚在运行。相关 JSON/BIT/BLOB 与 DATETIME 问题不属于本次验收。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions