Skip to content

feat(parser): fix MySQL replication/admin statement kinds and TABLE value constructor - #59

Merged
sjincho merged 1 commit into
mainfrom
sjcho/parser/mysql-command-fidelity
Aug 4, 2026
Merged

feat(parser): fix MySQL replication/admin statement kinds and TABLE value constructor#59
sjincho merged 1 commit into
mainfrom
sjcho/parser/mysql-command-fidelity

Conversation

@sjincho

@sjincho sjincho commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Four MySQL same-dialect parser correctness fixes where pinned upstream (v30.12.0) mis-parses a statement into an expression or the wrong statement node. All are DEVIATIONS §1 entries verified against real MySQL 8.0.46. Requested by the proxy-monster analyzer, which dispatches enforcement on root.Kind().

Statement Was (= upstream) Now Why
START REPLICA / SLAVE / GROUP_REPLICATION TransactionBEGIN REPLICA Command Security: looked like a session transaction, so a connect-only principal could start replication. Upstream's BEGIN REPLICA output is itself ERROR 1064 in MySQL.
STOP/FLUSH/UNLOCK INSTANCE/XA/BINLOG/HELP/RESTART/SHUTDOWN Alias/Column Command Fail-closed by design, not luck.
TABLE t (8.0.19+) Alias Select (= SELECT * FROM t) Real read — AST identical to the SELECT form, so lineage sees every column.

Key trap (why the gate matters): all three dispatches fire only at a top-level statement (statementDepth == 1). parseStatement is re-entered for nested values — a SET assignment RHS, a CTE body — so an ungated dispatch would mis-parse SET x = stop, y = 1 (swallowing the second assignment) or SET x = TABLE t (a bogus nested Select). The command leaders and TABLE stay ordinary identifiers/values there.

Scope limits (documented in §1.15): only the bare TABLE tbl_name is modeled; a non-identifier operand (TABLE f(), TABLE ?) is rejected, and trailers / set-ops / subquery / INSERT … TABLE are unmodeled and fail closed. The schema-qualified TABLE db.users is grammar beyond pinned upstream (it parse-errors at the dot) and carries a tripwire (testdata/upstream_extensions.jsonl); the unqualified form is the §1.15 correctness fix.

Verification: go test ./... green; 1847-case round-trip corpus intact; oracle-checked on MySQL 8.0.46 (TABLE u returns the same rows as SELECT * FROM u). Reviewed by Codex + Sol + Grok — Grok caught the nested-statement gate, now fixed and regression-tested.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Bi9bXQhVpzEYuHoZrie9NF

…alue constructor

Four same-dialect correctness fixes where pinned upstream mis-parses a MySQL
statement into an expression or the wrong statement node. All are DEVIATIONS §1
entries verified against real MySQL 8.0.46; each dispatch is gated to a top-level
statement so a bare identifier in a nested position (a SET assignment RHS, a CTE
body) is never mis-diverted.

- START REPLICA / START SLAVE / START GROUP_REPLICATION now degrade to a raw
  Command instead of a transaction. Upstream maps START to BEGIN and eats the
  verb as a transaction mode, so these looked identical to START TRANSACTION and
  a session-passthrough consumer would let a connect-only principal start
  replication. Upstream's round-trip output for these is itself a MySQL syntax
  error. MySQL-only; START TRANSACTION / BEGIN and their real modes are untouched.

- The admin statement leaders STOP, FLUSH, UNLOCK INSTANCE, XA, BINLOG, HELP,
  RESTART and SHUTDOWN now degrade to Command via a single statement-start
  dispatch table, instead of upstream's Alias/Column mis-coercion. The words stay
  usable as identifiers and as nested values. LOCK/UNLOCK TABLES are unaffected;
  the XA family is unified under Command.

- MySQL 8.0.19+ TABLE tbl now parses to a real Select whose AST is identical to
  SELECT * FROM tbl, so a lineage consumer sees the full-table read. The operand
  must be a plain table identifier; trailers, set operations, subquery and INSERT
  positions are unmodeled and fail closed. The schema-qualified TABLE db.users is
  grammar beyond pinned upstream and is tracked with a tripwire.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Bi9bXQhVpzEYuHoZrie9NF
@sjincho
sjincho merged commit 9a0f61f into main Aug 4, 2026
4 checks passed
@sjincho
sjincho deleted the sjcho/parser/mysql-command-fidelity branch August 4, 2026 03:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant