Skip to content

fix(plan): let EXPLAIN format sequence functions in group keys - #30386

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
aptend:fix/explain-seq-30366
Oct 16, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
aptend:fix/explain-seq-30366

Conversation

@aptend

@aptend aptend commented Oct 16, 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:

fixes #30366

What this PR does / why we need it:

EXPLAIN rejected valid queries when a sequence function appeared as a DISTINCT or GROUP BY key, failing with invalid input: explain contains UNKNOW_KIND_FUNCTION, while the queries themselves executed correctly.

Root cause: the four sequence functions (nextval, setval, currval, lastval) register with the UNKNOW_KIND_FUNCTION explain layout, and funcExprExplain returned an error unconditionally for that layout. A plain projection never prints the call the same way, but DISTINCT / GROUP BY exposes it as an aggregate group key that the explain formatter visits, hitting the error branch.

Fix: format UNKNOW_KIND_FUNCTION calls as ordinary name(args...) text instead of failing. No evaluation or sequence-state change is involved — EXPLAIN only renders the plan.

Tests: new TestExplainSequenceFunctionAsGroupKey covers all four sequence functions through the real registered overloads (function.GetFunctionByName), asserting describeExpr succeeds and emits nextval(/currval(/setval(/lastval. Full pkg/sql/plan/explain package tests pass.

Special notes for your reviewer:

  • [Bug]: Native Unicode UNIQUE conflicts truncate 1062 duplicate-entry diagnostics #30339 (Unicode UNIQUE 1062 diagnostic truncation) was picked up together with this one but is not included here: native-Unicode unique indexes store lossy physical collation keys (UCA weights), and the diagnostic path sees the transformed bytes rather than the logical value. Recovering printable logical text needs the original column expression plumbed alongside the physical key through the DML plan builders — larger than this PR, tracked separately in the issue.

The four sequence functions (NEXTVAL/SETVAL/CURRVAL/LASTVAL) register
with the UNKNOW_KIND_FUNCTION layout, and funcExprExplain rejected that
layout outright. EXPLAIN therefore failed with 'explain contains
UNKNOW_KIND_FUNCTION' whenever a sequence function surfaced as a
DISTINCT or GROUP BY aggregate group key, while the query itself
executed correctly. Format them as ordinary name(args) calls instead
(fixes matrixorigin#30366).
@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 16, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 419c1963f464b577fd56f67eb246912742b8e993

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: 419c1963f464b577fd56f67eb246912742b8e993

Assessment: approve

Reviewed the complete two-file delta and affected callers. The fix belongs in the existing EXPLAIN formatter, reuses recursive argument rendering and error propagation, and removes the incorrect rejection without evaluating sequence functions. No actionable correctness, design, compatibility, or performance issue remains.

Model: gpt-6-astra / xhigh

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

Validation:

  • Full EXPLAIN package passed with additive reviewer tests: all eight sequence overloads, nesting, complete output, JSON labels, error propagation, and ten DISTINCT/GROUP BY planner cases.

  • All ten planner reproductions failed with the exact base formatter's original error, confirming regression sensitivity.

  • Embedded frontend validation passed 36 text/JSON EXPLAIN calls across two rounds on one instance, including view-bound calls, unchanged sequence state, execution controls, and verified cleanup. An initial reviewer assertion about view projection display was corrected; both logs are retained.

  • Preflight passed; native inputs and artifacts were hash-verified through the repository build workflow. Source remained unchanged. Commands, source fingerprints, exit receipts, and logs were reconciled in /home/xupeng/.local/state/mo-bot/jobs/092b8235e3366ae05b993ae3/attempt-1/review-evidence.json.

Limitations:

  • Issue #30366's standalone body and raw CI logs were absent; its behavioral contract was evaluated from the frozen PR description and independently reproduced.

  • Public validation used an embedded single-CN frontend. No performance benchmark was run: added work is proportional to rendered sequence arguments, with no changes to per-row execution.

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

mergify Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-16 09:06 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-10-16 09:15 UTC · at b263d164a4352c4ea3e91b676c0b7ea5c1fee7c6

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

Reason

Pull request #30386 has been merged manually at 14a8d85

Hint

You were too fast!

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
ci — b263d164 Deployed Oct 16, 2026 by mergify[bot]
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/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: EXPLAIN fails for DISTINCT/GROUP BY sequence functions

3 participants