Repository navigation
Description
Is there an existing issue for the same bug?
Checked the repository issue search for ParseOne/Free; no existing matching issue found. Discovered during #29249 / #29627 resource ownership QA.
Branch Name
main
Commit ID
ce2a22a. The affected mysql_lexer.go is byte-identical at follow-up checkpoint 1f547a5.
Other Environment Information
Local Go 1.26.4; GOMAXPROCS=2, package/test parallelism 1. Minimum two DDL statements; no database or large dataset is needed.
Actual Behavior
ParseOneWithSQLMode parses multiple statements into lexer.stmts, then returns nil plus a parse error when len != 1 without calling Free on those statements. Error/SELECT-INTO validation rejection paths already free their parsed statements. For pooled DDL nodes, the count-rejection path loses the opportunity to reset and return objects (and owned children) to their pools. This is a lifecycle/pooling defect; no SQL result corruption or quantified RSS/throughput regression is claimed.
Expected Behavior
The parser remains owner of every statement on rejection and frees all of them before returning nil/error. On success, the caller remains owner of the single returned statement.
Steps to Reproduce
Call mysql.ParseOne(context.Background(), "create database a; create database b", 1). It returns nil/error as expected. Observe the two pooled CreateDatabase nodes at the count-rejection boundary: both still retain their Name after the call. An instrumented private overlay captures these nodes immediately before rejection and checks the existing pool reset contract, without relying on GC, sync.Pool reuse order, sleep or SELECT's no-op Free.
The original source fails that cleanup assertion (terminal exit 1; names remain a/b). Adding the existing Free loop in the count-rejection branch makes exactly the same probe pass (terminal exit 0; both names reset). Removing the loop reproduces the failure. The baseline source was verified byte-identical to main for this file.
Additional information
First owner: pkg/sql/parsers/dialect/mysql/mysql_lexer.go, ParseOneWithSQLMode. The fix belongs at this common parser rejection boundary; callers receive no AST on error and cannot perform this cleanup. Also validate empty-input rejection, nearest single-DDL success with caller Free, SQL-mode and SELECT-INTO paths. The fix is being accumulated in existing PR #29629 with the wider ownership cleanup, rather than opening a small standalone PR.
Activity
test: make process fixture resource ownership explicit (#29629)