Skip to content

fix(frontend): support ANALYZE/CHECK/SHOW PROFILE and statement-scoped rewrites - #24659

Merged
XuPeng-SH merged 60 commits into
matrixorigin:mainfrom
ULookup:fix/issue-23122-analyze-check-show-profile
Jul 17, 2026
Merged

XuPeng-SH merged 60 commits into
matrixorigin:mainfrom
ULookup:fix/issue-23122-analyze-check-show-profile

Conversation

@ULookup

@ULookup ULookup commented May 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 #23122

What this PR does / why we need it:

MatrixOne currently returns generic parser error 1064 for several MySQL-compatible statements, including multi-table ANALYZE TABLE, CHECK TABLE, and SHOW PROFILE. Supporting these statements also requires preserving session, transaction, snapshot, result, and SQL-rewrite state when ANALYZE TABLE executes derived queries.

This PR adds:

Statement support

  • Extends ANALYZE TABLE to accept multiple tables, with or without explicit column lists.
  • Adds AST and grammar support for CHECK TABLE, including EXTENDED and FOR UPGRADE.
  • Adds AST and grammar support for SHOW PROFILE, including FOR QUERY and LIMIT.
  • Returns explicit NotSupported errors for CHECK TABLE and SHOW PROFILE instead of generic parser errors.

ANALYZE execution

  • Resolves visible columns from the selected table snapshot when no column list is supplied.
  • Quotes table and column identifiers when generating derived queries.
  • Executes multiple table entries sequentially and returns their result sets in statement order.
  • Preserves the outer execution context, responder properties, protocol state, multi-result status, and error behavior.
  • Applies privilege and transaction classification for the new statements.

SQL rewrite and database remapping

  • Keeps rewrite/remap policy scoped to each statement in multi-statement COM_QUERY requests and cached plans.
  • Preserves the effective policy across prepared statement creation, execution, and rebuilds.
  • Splits policies using parser-aware statement boundaries and preserves parser errors.
  • Propagates the effective rewrite/remap policy into ANALYZE TABLE derived queries.

Tests

  • Adds parser and AST structural coverage.
  • Adds frontend unit tests for execution context, snapshot resolution, result collection, responder/protocol isolation, and rewrite behavior.
  • Adds BVT coverage for supported and unsupported statement forms.

ULookup added 2 commits May 27, 2026 20:07
- Refactor AnalyzeStmt to support multi-table entries
- Add CheckTableStmt and ShowProfileStmt AST nodes
- Update grammar (mysql_sql.y) for all three statement types
- Add frontend handlers returning "not supported" for CHECK/SHOW PROFILE
- Handle ANALYZE multi-table by iterating entries

WIP: still need to wire up new handlers in self_handle.go dispatch and regenerate mysql_sql.go
…arser (matrixorigin#23122)

- Add dispatch cases in self_handle.go for CheckTableStmt and ShowProfileStmt
- Add FPrint constants (FPCheckTableStmt, FPShowProfileStmt, etc.) in types.go
- Add "profile" keyword mapping to keywords.go for lexer recognition
- Regenerate mysql_sql.go from updated grammar (goyacc)
- Add StmtKind() methods to CheckTableStmt and ShowProfileStmt AST nodes
- Add analysis and design documents

All parser and AST unit tests pass.
@ULookup
ULookup requested a review from a user May 28, 2026 03:25
@ULookup
ULookup requested a review from fengttt as a code owner May 28, 2026 03:25
@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 →

@mergify mergify Bot added the kind/bug Something isn't working label May 28, 2026

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

Requesting changes on the latest head 032b824447. The previous result ownership, quoted identifier, snapshot, and rewrite-chain findings are addressed, but the latest per-statement policy change is not closed through the execution layer.

[High] Multi-statement database remaps are still collapsed to the first statement. rewriteSQL now materializes a separate merged hint for every statement (pkg/frontend/rewrite_rule.go:201-218), so inline remap overrides can legitimately differ by statement. However, GetComputationWrapper still calls extractInlineRemapDb(execCtx.input.getSql()) once on the complete command, applies that one map to every parsed AST, and stores it in the single execCtx.remapDb (pkg/frontend/mysql_cmd_executor.go:2751-2763). extractInlineRemapDb only reads the first leading hint.

Concrete failure: with statement 1 carrying src -> first_db and statement 2 carrying src -> second_db, e.g. SELECT 1; ANALYZE TABLE src.t(id), the second Analyze AST is rewritten to first_db.t, not second_db.t. If the first statement has no remap, a remap present only on the second statement is ignored. The same mismatch affects later SELECT/DML statements and unqualified-name resolution through TxnCompilerContext.DefaultDatabase, so this can read or modify the wrong database and can violate the intended rewrite/remap policy boundary.

I reproduced this with the exact parser/execution preprocessing sequence: Parse + AddRewriteHints produces two statement-specific options, but extractInlineRemapDb(fullSQL) returns the first map and applyRemapDb(stmts, map) rewrites both statements with it. The existing tests only verify that the rewritten SQL text contains a policy on later statements; they do not pass those statements through the consumer that collapses the maps.

Please carry remap metadata per parsed statement/computation wrapper, apply each map only to its matching AST, and install the matching map on the ExecCtx before authorization/planning/execution (including cached/prepared paths). Add end-to-end unit coverage for: first statement without remap + second with remap; distinct inline overrides on consecutive statements; session remap restored after a one-statement inline override; qualified and unqualified targets; and ANALYZE followed/preceded by SELECT.

Focused frontend/parser/tree tests pass, so this is a missing cross-layer invariant rather than a test failure.

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

Blocking: per-statement policy materialization uses lexical semicolons rather than parser-level statement boundaries.

rewriteSQL calls SplitSqlBySemicolon at pkg/frontend/rewrite_rule.go:201, and that helper splits every scanner-visible ;. However, MatrixOne accepts compound statements whose body contains semicolons as one AST, for example the existing parser case:

create task task_quotes when ('gate' = 'gate') as begin
  insert into gate_sink select 'gate-ok';
  select case when 1 = 1 then 'PASS' else 'FAIL' end;
end

When enable_remap_hint is on and any role/session rewrite policy is non-empty, rewriteSQL prepends a materialized hint to each body fragment. Parsing still returns one CreateSQLTask, while extractLeadingHints returns three statement-bearing fragments; AddRewriteHints then fails at pkg/sql/parsers/sqlparse.go:463 with SQL parser error: parse hints bug. I reproduced this on head 4772b88a645ef3a8566be4b90bed1d0ff543a44f with a frontend regression test exercising rewriteSQL -> parsers.Parse -> parsers.AddRewriteHints.

Please derive policy boundaries from top-level SQL statement boundaries compatible with the grammar (so semicolons inside BEGIN ... END remain inside one statement), and add a regression covering a compound CREATE TASK under a non-empty rewrite/remap policy.

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

Approved on latest head 1cfd2748ef after re-reviewing the complete functional chain.

The previous blocker is closed at the correct abstraction boundary: statement policy splitting now uses grammar-level top-level semicolon positions, so semicolons inside compound bodies remain within one AST, while malformed input is still surfaced as the standard parser error class. I also rechecked the broader changes: ANALYZE result ownership and multi-result flags, responder/context restoration on success and error, quoted identifiers, snapshot-aware implicit columns, per-statement remap propagation across normal/cache/prepared paths, mid-list failure atomicity, and transaction/privilege routing. No new confirmed correctness, compatibility, leak, hang, or unbounded-growth issue was found.

Local evidence on this exact head:

  • go test -count=1 -timeout=180s ./pkg/sql/parsers/... passed with the repository CGo runtime setup.
  • go test -count=1 -timeout=300s ./pkg/frontend passed.
  • go vet ./pkg/sql/parsers/... ./pkg/frontend passed.
  • git diff --check origin/main...HEAD passed.

The parser-aware boundary scan is measurably more expensive than the former lexical splitter, but the measured absolute cost is only a few microseconds per invocation and is gated by enable_remap_hint; this is a reasonable correctness tradeoff, with parse-result reuse available as a future optimization. CI is still running and the branch is behind main, so normal CI/rebase gates should still apply.

@mergify

mergify Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-16 13:15 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ❌ Checks failed · in-place
  • 🚫 Left the queue — 2026-07-16 13:48 UTC · at fd354d5dd8c5290fcdf2aa15e9e68400a4fb45af

This pull request spent 33 minutes 46 seconds in the queue, with no time running CI.

Waiting for
  • any of: [🛡 GitHub branch protection]
    • 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)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of: [🛡 GitHub branch protection]
    • 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)
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of: [🛡 GitHub branch protection]
    • 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)
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
All conditions
  • any of [🛡 GitHub branch protection]:
    • 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)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • 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)
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • 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)
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • github-review-decision = APPROVED [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64

Reason

The merge conditions cannot be satisfied due to failing checks

Failing checks:

Hint

You may have to fix your CI before adding the pull request to the queue again.
If you update this pull request, to fix the CI, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Requeued — the merge queue status continues in this comment ↓.

@mergify

mergify Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-17 03:55 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue — 2026-07-17 04:54 UTC · at 165e23073f7b1a058c40abd3a15bf00814c0a9b4

This pull request spent 58 minutes 24 seconds in the queue, with no time running CI.

Reason

Pull request #24659 has been dequeued

Queue conditions are not satisfied:

  • -conflict [📌 queue requirement]

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Requeued — the merge queue status continues in this comment ↓.

@mergify

mergify Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-17 08:35 UTC · Rule: main · triggered by @ULookup with the merge queue checkbox
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-07-17 10:47 UTC · at 2c1fc3f5332e5b15be629a4b3d3f604b4a42c220

This pull request spent 2 hours 12 minutes 32 seconds in the queue, with no time running CI.

Waiting for
  • any of: [🛡 GitHub branch protection]
    • 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)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of: [🛡 GitHub branch protection]
    • 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)
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of: [🛡 GitHub branch protection]
    • 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)
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
All conditions
  • any of [🛡 GitHub branch protection]:
    • 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)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • 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)
    • check-success = Matrixone Standlone CI / Multi-CN e2e BVT Test on Linux/x64(LAUNCH, PROXY)
  • any of [🛡 GitHub branch protection]:
    • 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)
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection] (documentation)
  • github-review-decision = APPROVED [🛡 GitHub branch protection] (documentation)

Reason

Pull request #24659 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Failing checks:

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

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

  • Requeue this pull request

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/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Gap: ANALYZE/CHECK/SHOW PROFILE statements unsupported

4 participants