{"record":{"id":"5227cfd39188a46f","repo":"vitessio/vitess","slug":"vt13001-5227cf","errorCode":"VT13001","errorMessage":"Unknown SelectStatement type - %T","messagePattern":"Unknown SelectStatement type - %T","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtgate/planbuilder/operators/subquery_planning.go","lineNumber":72,"sourceCode":"\t\t\t// TODO: we could also support the case where all the columns of a multi-column vindex are used in the grouping\n\t\t\treturn slices.ContainsFunc(node.GroupBy.Exprs, validVindex)\n\t\t}\n\n\t\t// if we have grouping, we have already checked that it's safe, and don't need to check for aggregations\n\t\t// but if we don't have groupings, we need to check if there are aggregations that will mess with us\n\t\tif ctx.ContainsAggr(node.SelectExprs) {\n\t\t\treturn false\n\t\t}\n\n\t\tif ctx.ContainsAggr(node.Having) {\n\t\t\treturn false\n\t\t}\n\n\t\treturn true\n\tcase *sqlparser.Union:\n\t\treturn isMergeable(ctx, node.Left, op) && isMergeable(ctx, node.Right, op)\n\tdefault:\n\t\tpanic(vterrors.VT13001(fmt.Sprintf(\"Unknown SelectStatement type - %T\", node)))\n\t}\n}\n\nfunc settleSubqueries(ctx *plancontext.PlanningContext, op Operator) Operator {\n\tvisit := func(op Operator, lhsTables semantics.TableSet, isRoot bool) (Operator, *ApplyResult) {\n\t\tswitch op := op.(type) {\n\t\tcase *SubQueryContainer:\n\t\t\touter := op.Outer\n\t\t\tfor _, subq := range op.Inner {\n\t\t\t\tsubq.Outer = subq.settle(ctx, outer)\n\t\t\t\touter = subq\n\t\t\t}\n\t\t\treturn outer, Rewrote(\"extracted subqueries from subquery container\")\n\t\tcase *Projection:\n\t\t\tap, err := op.GetAliasedProjections()\n\t\t\tif err != nil {\n\t\t\t\tpanic(err)\n\t\t\t}","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtgate/planbuilder/operators/subquery_planning.go#L54-L90","documentation":"VT13001 panic in isMergeable: the planner's switch over sqlparser.SelectStatement types has a default case, meaning an unhandled SelectStatement AST node type was encountered while deciding whether a statement is mergeable. This is an internal completeness check — the parser should never produce a statement type the planner does not know.","triggerScenarios":"isMergeable (via IsMergeable or recursion on Union operands) receives a SelectStatement implementation not covered by the switch cases (Select, Union, etc.), typically after a new AST node type is added to the parser without planner support.","commonSituations":"Seen in Vitess development when new SQL syntax is added to the parser; extremely rare for users, but could be reported when running newly parsed exotic statements (e.g. new table expression types) through the planner.","solutions":["File a bug with the SQL statement and stack trace at the Vitess repository","Upgrade to the latest Vitess release where newer statement types may be handled","Rewrite the query using more standard SELECT/UNION syntax","As a workaround, run the statement directly against MySQL bypassing vtgate planning if applicable"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := doQuery(q)\nif err != nil && strings.Contains(err.Error(), \"VT13001\") && strings.Contains(err.Error(), \"Unknown SelectStatement type\") {\n    // report bug; try a simplified/standard rewrite of the statement\n    return doQuery(simplifyStatement(q))\n}","preventionTips":["Keep Vitess and its SQL parser up to date","Avoid bleeding-edge SQL syntax unsupported by the planner","Test new syntax against vtgate before adoption","Report unhandled statement types upstream with repro SQL"],"tags":["planner","sqlparser","internal-panic","union"],"backgroundTag":"planner-internal-invariant","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}