Skip to content

fix(frontend): honor column signedness when saving query results (#31498) - #31559

Merged
XuPeng-SH merged 2 commits into
mainfrom
fix/astra-meow-31498
Oct 28, 2026
Merged

XuPeng-SH merged 2 commits into
mainfrom
fix/astra-meow-31498

Conversation

@aptend

@aptend aptend commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

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

Which issue(s) this PR fixes:

issue #31498 (Fixes #31498)

What this PR does / why we need it:

Problem

With save_query_result=ON, mysqlColDef2PlanResultColDef ignored IsSigned() and mapped every integer column to a signed T_int*, so convertRowsIntoBatch hit interface conversion: interface {} is uint64, not int64:

  • SHOW COUNT(*) WARNINGS / ERRORS publishes MYSQL_TYPE_LONGLONG with IsSigned()==false and uint64 row values; the frontend only survived through the recovered-20101 path.
  • As reported in the follow-up comment on [Bug]: save_query_result makes SHOW COUNT(*) WARNINGS/ERRORS panic on unsigned count #31498, DATA BRANCH DIFF on a SET('a','b') column (engine type T_uint64, published as unsigned LONGLONG) with save_query_result=ON raised the same panic inside diffMergeAgency/satisfyDiffOutputOpt - an unsupervised goroutine - and the whole service exited with exit code 2, while the same statement worked with saving OFF.

Fix

  1. pkg/frontend/util.go: mysqlColDef2PlanResultColDef is now signedness-aware - TINY/SHORT/LONG/LONGLONG map to T_uint8/16/32/64 when !col.IsSigned(), so saved result metadata matches the wire protocol.
  2. convertRowsIntoBatch handles T_uint8/16/32/64: uint64 values are appended exactly; non-negative int64 is accepted; negative values, out-of-range widths and foreign types return clean errors (values above math.MaxInt64 are never truncated); NULL rows keep their null slot. The new helper getUnsignedRowValue follows the existing getDecimal*FromRowValue convention.
  3. Regressions:
    • pkg/frontend/util_test.go: sign-aware mapping matrix; unsigned round-trip over 0, 1, MaxInt64, MaxInt64+1, MaxUint64 plus NULL rows; rejection matrix (negative / out-of-range / wrong type).
    • pkg/frontend/mysql_cmd_executor_test.go: contract-level test asserting SHOW COUNT(*) publishes MYSQL_TYPE_LONGLONG with IsSigned()==false and uint64 row values for both variants.
    • BVT: test/distributed/cases/save_query_result/save_query_result_show_count.{sql,result} (SHOW COUNT path, including the corrupt-input warning boundary) and test/distributed/cases/git4data/branch/diff/diff_18.{sql,result} (DATA BRANCH DIFF over a SET column with saving ON, asserting the diff row and an int-safe column projection of the result_scan readback).

Verification (isolated external mo-service with a private port config; no shared clusters)

  • RED on unfixed upstream main at da0c931aa7 (baseline binary built from that source): DIFF+SET with saving ON -> client lost connection (2013), server-side unrecovered panic (uint64, not int64 in convertRowsIntoBatch via satisfyDiffOutputOpt/diffMergeAgency) and service exit code 2; the saving OFF path worked on the same instance.
  • FIXED on da0c931aa7 + this change: DIFF/SET rows identical with saving OFF vs ON (set_branch | UPDATE | 1 | 3), v published as unsigned LONGLONG (type 8, flags 0x20, length 64), result_scan readback identical, and both the statement connection and a second concurrent connection stayed alive; SHOW COUNT(*) returned 0/0 and then 0/1 across a corrupt-input warning with proper @@session.warning_count metadata; server stopped cleanly and all TCP/UDP listeners were released.
  • Unit: focused pkg/frontend selections - 14 runs, all PASS, exit code 0.
  • Static: make static-check-selected STATIC_CHECK_PACKAGES=./pkg/frontend/... - 0 issues., exit code 0.
  • BVT in the repository's actual CI mode (optools/bvt_ut/entrypoint.sh: ./run.sh -n -g -o -p <cases> -e optimistic, plus exact case selection -i diff_18,save_query_result_show_count and the repo resource path): both case files executed, TOTAL 20 / SUCCESS 20, 100% success rate, original exit code 0. The CI -n flag skips result-metadata comparison; the same two cases additionally passed in the default full-comparison mode (20/20, exit code 0), and real-protocol consumers separately verified types, values and metadata as described above.
  • Note: mo-tester cannot parse column lengths >= 2^31 (Integer.parseInt overflow on the saved VARCHAR length 4294967295); therefore the result_scan assertion in diff_18.sql projects the int-safe columns (id, v) instead of select *.

Limitations (deliberately not overclaimed)

)

Fixes #31498.

mysqlColDef2PlanResultColDef ignored col.IsSigned() and mapped every
integer column to a signed T_int*, so convertRowsIntoBatch hit
'interface conversion: interface {} is uint64, not int64' while saving
query results: SHOW COUNT(*) WARNINGS/ERRORS publish unsigned
LONG LONG rows, and per the follow-up report DATA BRANCH DIFF on a
SET('a','b') column (engine T_uint64) with save_query_result=ON
crashed an unsupervised diffMergeAgency goroutine and exited the
whole service.

- publish unsigned wire metadata (TINY/SHORT/LONG/LONGLONG ->
  T_uint8/16/32/64 when !IsSigned()); convertRowsIntoBatch accepts
  unsigned rows (uint64 exact, non-negative int64 accepted, clean
  errors for negative/out-of-range/foreign types, NULLs preserved)
- unit + contract-level tests, and two BVT regressions (SHOW COUNT
  and DATA BRANCH DIFF over SET with saving ON) added
@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 →

@XuPeng-SH

XuPeng-SH commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: ddd215ad6b772f16f5290b0e69b088396df6cfca

Review completed. Read the assessment.

@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.

mo-bot review · mo-bot-local · review

Commit: ddd215ad6b772f16f5290b0e69b088396df6cfca

Assessment: approve

Approve the fix for the reported uint64 SHOW-count and SET-diff failures. Signedness, exact values, NULL handling and saved-result readback align across the affected paths. No actionable regression was found.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1586-7a01-9000-d45e20995cf8 · slot 1 · generation 1

Validation:

  • Reviewed the complete seven-file delta, affected producers and consumers, linked issues and both discussion entries. Saved review-plan.md and discussion-assessment.json.

  • Frozen evidence reports successful UT, SCA, coverage and both BVT-group workflows at this head. Source selection includes the changed frontend tests and both new BVT files.

  • Local source audit passed: patch/head agreement, clean source, git diff --check, gofmt, BVT pair consistency and complete discussion coverage. Receipt: checks/1793186558699883326-3.json; retained output: review-audit.log and review-audit.json.

Limitations:

  • No runtime tests were rerun locally. Author-reported standalone and full-metadata checks had no attached receipts; individual CI test logs were not supplied.

  • Native uint8/uint16/uint32 row values remain unsupported by the helper, and partial-conversion error cleanup remains incomplete. Both failure paths predate this change; this approval does not claim they are fixed.

  • The separately tracked JSON/BIT/BLOB and DATETIME/TIME failures remain outside this fix.

@mergify mergify Bot added the queued label Oct 28, 2026
@mergify

mergify Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue

2 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Wed 28 Oct, 11:23 · rule main · triggered by rule Automatic queue on approval for main
  • ⏹️ Testing stopped · in place
  • 🚫 Left the queue 11:25 · 000c54f

Reason

Pull request #31559 has been merged manually at 6ff8881

Hint

You were too fast!

Merge conditions: 2 of 3 met

This pull request

Condition Required by
✅ #review-threads-unresolved = 0 GitHub branch protection
✅ github-review-approved GitHub branch protection

The batch, tested in place

Condition Required by
❌ any of: check-neutral = CI Required, check-skipped = CI Required, check-success = CI Required GitHub branch protection

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

Times in UTC · dashboard · how the merge queue works

This branch was previously deployed

1 inactive deployment
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/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants