{"record":{"id":"92acdb0670a5a075","repo":"vitessio/vitess","slug":"vt13001-92acdb","errorCode":"VT13001","errorMessage":"unexpected statement type %T","messagePattern":"unexpected statement type %T","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtgate/planbuilder/operators/horizon_expanding.go","lineNumber":39,"sourceCode":"\t\"fmt\"\n\t\"strings\"\n\n\t\"vitess.io/vitess/go/slice\"\n\t\"vitess.io/vitess/go/vt/sqlparser\"\n\t\"vitess.io/vitess/go/vt/vterrors\"\n\t\"vitess.io/vitess/go/vt/vtgate/planbuilder/plancontext\"\n\t\"vitess.io/vitess/go/vt/vtgate/semantics\"\n)\n\nfunc expandHorizon(ctx *plancontext.PlanningContext, horizon *Horizon) (Operator, *ApplyResult) {\n\tstatement := horizon.selectStatement()\n\tswitch sel := statement.(type) {\n\tcase *sqlparser.Select:\n\t\treturn expandSelectHorizon(ctx, horizon, sel)\n\tcase *sqlparser.Union:\n\t\treturn expandUnionHorizon(ctx, horizon, sel)\n\t}\n\tpanic(vterrors.VT13001(fmt.Sprintf(\"unexpected statement type %T\", statement)))\n}\n\nfunc expandUnionHorizon(ctx *plancontext.PlanningContext, horizon *Horizon, union *sqlparser.Union) (Operator, *ApplyResult) {\n\top := horizon.Source\n\n\tqp := horizon.getQP(ctx)\n\n\tif len(qp.OrderExprs) > 0 {\n\t\top = newOrdering(op, qp.OrderExprs)\n\t}\n\n\tif union.Limit != nil {\n\t\top = newLimit(op, union.Limit, false)\n\t}\n\n\tif horizon.TableId != nil {\n\t\tproj := newAliasedProjection(op)\n\t\tproj.DT = &DerivedTable{","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtgate/planbuilder/operators/horizon_expanding.go#L21-L57","documentation":"expandHorizon dispatches horizon expansion based on the statement type, supporting only *sqlparser.Select and *sqlparser.Union. Any other sqlparser.TableStatement reaching it panics with VT13001 'unexpected statement type %T' — an unimplemented planning path.","triggerScenarios":"pushOrExpandHorizon (or mergeCTE) handing expandHorizon a statement type other than Select/Union — e.g. an unexpected AST node produced by an upstream rewrite or a CTE merged into a non-standard statement.","commonSituations":"Bugs in CTE handling or query rewrites leaking unexpected AST nodes into horizon expansion; effectively never user-caused directly, but triggered by specific query shapes (WITH clauses, unusual nesting).","solutions":["Identify the %T type printed in the message to see which statement leaked in","Simplify the query (remove/restructure WITH clauses, subquery nesting)","Check Vitess issue tracker / upgrade — VT13001 marks unimplemented functionality; file a bug with the query"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-check the statement kind before horizon expansion\nswitch stmt.(type) {\ncase *sqlparser.Select, *sqlparser.Union:\n    // supported\ndefault:\n    // bail out to a generic plan path\n}","typeGuard":"func isExpandableStatement(s sqlparser.TableStatement) bool {\n    switch s.(type) {\n    case *sqlparser.Select, *sqlparser.Union:\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Keep CTE merging rewrites constrained to Select/Union statements","Cover WITH-clause queries in planner tests","Read the %T in the panic message to identify the offending AST node"],"tags":["planner","vt13001","cte","unimplemented"],"backgroundTag":"unsupported-sql-feature","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}