sqlparser: nil pointer panic on WITH followed by a parenthesized query expression without ORDER BY or LIMIT
Not looking for external contributions on this one. We're already working in this area and intend to fix it ourselves. Please don't open a PR against this issue — it's filed to track the problem and record the analysis, not as an invitation. Comments and additional repro cases are very welcome.
Overview of the Issue
The SQL parser panics with a nil pointer dereference on a statement that starts with a WITH clause and continues with a parenthesized query expression that has no trailing ORDER BY or LIMIT:
WITH t AS (SELECT 1) (SELECT 2)
WITH t AS (SELECT 1) (SELECT * FROM t)MySQL 8.0.46 accepts both statements. The same shapes with a trailing LIMIT 1 parse fine in Vitess, and so does the WITH placed inside the parentheses, (WITH t AS (SELECT 1) SELECT * FROM t).
The panic happens inside the generated parser, in the grammar action that combines a WITH clause with a parenthesized query expression, so it is reachable from any client that can send SQL. vtgate recovers panics at the RPC layer, so the client sees an internal error rather than a crash, but the parser should return a syntax error or a parsed statement, never panic.
Reproduction Steps
func TestWithParenPanic(t *testing.T) {
_, err := sqlparser.NewTestParser().Parse("with t as (select 1) (select 2)")
require.NoError(t, err)
}Binary Version
main at b805b51ec8 (2026-09-14).
Operating System and Environment details
Any; reproduced with the Go test above on linux/arm64.
Log Fragments
panic: runtime error: invalid memory address or nil pointer dereference
vitess.io/vitess/go/vt/sqlparser.(*yyParserImpl).Parse(...)
sql.y:736
vitess.io/vitess/go/vt/sqlparser.yyParsePooled(...)
go/vt/sqlparser/parser.go:57
vitess.io/vitess/go/vt/sqlparser.(*Parser).Parse2(...)
go/vt/sqlparser/parser.go:79Source: vitessio/vitess