{"record":{"id":"9331d301a7bed9ed","repo":"vitessio/vitess","slug":"err-9331d3","errorCode":null,"errorMessage":"err","messagePattern":"err","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtgate/planbuilder/operators/expressions.go","lineNumber":128,"sourceCode":"\t}\n\tpost := func(cursor *sqlparser.CopyOnWriteCursor) {\n\t\tif replace != nil {\n\t\t\tcursor.Replace(replace)\n\t\t\treplace = nil\n\t\t}\n\t}\n\toutput := sqlparser.CopyOnRewrite(in, pre, post, ctx.SemTable.CopySemanticInfo).(sqlparser.Expr)\n\tif in != output {\n\t\t// we need to do this, since one simplification might lead to another\n\t\treturn simplifyPredicates(ctx, output)\n\t}\n\treturn output\n}\n\nfunc getFirstSelect(selStmt sqlparser.TableStatement) *sqlparser.Select {\n\tfirstSelect, err := sqlparser.GetFirstSelect(selStmt)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn firstSelect\n}\n","sourceCodeStart":110,"sourceCodeEnd":132,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtgate/planbuilder/operators/expressions.go#L110-L132","documentation":"This is an internal planner panic: getFirstSelect calls sqlparser.GetFirstSelect on a table statement (SELECT/UNION) and, if that helper returns an error, re-panics with the raw error. GetFirstSelect only fails for statement kinds it cannot extract a *sqlparser.Select from (e.g. non-Select table statements such as certain parenthesized or non-select statements passed where a SELECT is expected), so in practice this surfaces as an unexpected internal error rather than a user-facing code.","triggerScenarios":"Passing a sqlparser.TableStatement that is not (or does not contain) a *sqlparser.Select into planner helpers such as pushUnionInsideDerived, checkUnionColumnByName, FindCol, GetSelectExprs, columnMismatch, or planQuery.","commonSituations":"Developers extending planbuilder who feed a UNION/parenthesized node or new AST statement type into helpers expecting a Select; planner bugs where an unsupported statement shape reaches derived-table planning.","solutions":["Check the error message to see which statement type failed to yield a Select; inspect the query for constructs the planner mishandles","Simplify or rewrite the query (e.g. avoid exotic nesting of derived tables/unions) so a plain SELECT reaches the planner","If reproducible with a normal query, file a Vitess bug with the query and stack trace - this path should not fail for valid SELECTs"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func isSelect(stmt sqlparser.TableStatement) bool {\n\t_, ok := stmt.(*sqlparser.Select)\n\treturn ok\n}","tryCatchPattern":"defer func() {\n\tif r := recover(); r != nil {\n\t\tlog.Error(\"planner internal panic in getFirstSelect\", slog.Any(\"panic\", r))\n\t\treturn vterrors.Errorf(vtrpcpb.Code_INTERNAL, \"planning failed: %v\", r)\n\t}\n}()","preventionTips":["Only pass *sqlparser.Select statements (or verified select-containing statements) into planner helpers","Recover panics at the planner boundary and map them to INTERNAL gRPC errors","Add unit tests for derived-table/union planning with varied statement shapes"],"tags":["vitess","planbuilder","internal-error","sqlparser"],"backgroundTag":"internal-planner-panic","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}