Skip to content

fix: make tenant SHOW TABLE STATUS rows consistent for system statement_info#23774

Merged
mergify[bot] merged 11 commits intomatrixorigin:mainfrom
robll-v1:issue/10163
Mar 9, 2026
Merged

fix: make tenant SHOW TABLE STATUS rows consistent for system statement_info#23774
mergify[bot] merged 11 commits intomatrixorigin:mainfrom
robll-v1:issue/10163

Conversation

@robll-v1
Copy link
Collaborator

What type of PR is this?

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

Which issue(s) this PR fixes:

issue #10163

What this PR does / why we need it:

Background / Root Cause
This PR fixes issue #10163: under a tenant account, SHOW TABLE STATUS for system.statement_info could show Rows = 0 (or otherwise inconsistent values) even when tenant-visible rows existed.

Root cause:

SHOW TABLE STATUS originally used mo_table_rows(db, tbl) for Rows.
For special system tables (for example system.statement_info), tenant queries are rewritten to run under the sys account with tenant-level filtering.
mo_table_rows does not always reflect that rewritten tenant-visible result set, so Rows could be inaccurate.
Solution
In handleShowTableStatus, add a targeted fallback path:

For non-sys accounts, and only for tables where ShouldSwitchToSysAccount(db, tbl) is true, run select count() on that table.
Use this count(
) result to override the Rows column in SHOW TABLE STATUS.
Keep existing behavior for all other tables (mo_table_rows/mo_table_size).
Route internal SQL execution through ExeSqlInBgSes (wrapper) to make stubbing in unit tests straightforward.
Test Coverage
Unit Tests (mysql_cmd_executor_test.go)
Added/covered boundary cases:

Fallback success path: mo_table_rows=0, count()>0, Rows is correctly overridden.
Non-special table: fallback is not triggered.
Sys account: fallback is not triggered.
Empty count(
) result: keep mo_table_rows.
count() execution error path.
count(
) decode (GetInt64) error path.
BVT (test/distributed/cases/dml/show/show7.sql/.result)
Added issue regression case with stabilization:

Tenant-session warm-up statements + wait (sleep) to avoid async log timing flakiness.
Pre-check count() > 0 on system.statement_info.
Validate SHOW TABLE STATUS ... LIKE 'statement_info' returns positive Rows (regex-based assertion).
Scope / Risk
Behavior change is limited to: non-sys account + special system tables requiring sys-account switch.
Adds one extra count(
) query only in that narrow path.
All other SHOW TABLE STATUS behavior remains unchanged.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes incorrect Rows output in SHOW TABLE STATUS for certain system tables (notably system.statement_info) when executed under non-sys tenant accounts, where queries are rewritten to sys with tenant filtering.

Changes:

  • Add a targeted count(*) fallback for Rows in handleShowTableStatus for tables requiring ShouldSwitchToSysAccount (non-sys tenants only).
  • Route background SQL execution in this path through ExeSqlInBgSes to simplify unit-test stubbing.
  • Add unit + distributed regression coverage for the tenant statement_info Rows inconsistency.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
pkg/frontend/mysql_cmd_executor.go Adds special-table count(*) fallback and switches stats SQL execution to ExeSqlInBgSes.
pkg/frontend/mysql_cmd_executor_test.go Adds unit tests covering fallback behavior, non-trigger cases, and error paths.
test/distributed/cases/dml/show/show7.sql Adds distributed regression scenario for tenant SHOW TABLE STATUS ... LIKE 'statement_info'.
test/distributed/cases/dml/show/show7.result Captures expected output for the new distributed regression case.
Comments suppressed due to low confidence (1)

pkg/frontend/mysql_cmd_executor.go:621

  • When specialRows overrides the Rows column, Avg_row_length is still computed using rows[tblName] (from mo_table_rows). If mo_table_rows returns 0 but count(*) returns >0 (the bug scenario), SHOW TABLE STATUS will report Rows > 0 but Avg_row_length = 0, which is internally inconsistent. Consider computing an effectiveRows value (use the overridden count when present) and use that consistently for both the Rows assignment and the Avg_row_length division guard/denominator.
		if cnt, ok := specialRows[tblName]; ok {
			ses.data[idx][3] = cnt
		} else {
			ses.data[idx][3] = rows[tblName]
		}
		if rows[tblName] > 0 {
			ses.data[idx][4] = sizes[tblName] / rows[tblName]
		} else {
			ses.data[idx][4] = int64(0)
		}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mergify
Copy link
Contributor

mergify bot commented Mar 9, 2026

Merge Queue Status

  • Entered queue2026-03-09 15:48 UTC · Rule: main
  • Checks passed · in-place
  • Merged2026-03-09 16:43 UTC · at 87ce7fa2d47b66ca10bae0f0acd28ce341d4b98f

This pull request spent 55 minutes 36 seconds in the queue, including 55 minutes 9 seconds running CI.

Required conditions to merge
  • #approved-reviews-by >= 1 [🛡 GitHub branch protection]
  • #changes-requested-reviews-by = 0 [🛡 GitHub branch protection]
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • branch-protection-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-neutral = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
    • check-skipped = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Ubuntu/x86
    • check-neutral = Matrixone CI / SCA Test on Ubuntu/x86
    • check-skipped = Matrixone CI / SCA Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(Optimistic/PUSH)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH,Optimistic)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-neutral = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
    • check-skipped = Matrixone Upgrade CI / Compatibility Test With Target on Linux/x64(LAUNCH)
  • any of [🛡 GitHub branch protection]:
    • check-skipped = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage

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.

6 participants