{"record":{"id":"c08eae35054f209c","repo":"vitessio/vitess","slug":"errunsupportedquery","errorCode":"ErrUnsupportedQuery","errorMessage":"%w: %s","messagePattern":"%w: %s","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtctl/workflow/vexec/query_planner.go","lineNumber":134,"sourceCode":"//\n// For DELETE queries, USING, PARTITION, ORDER BY, and LIMIT clauses are not\n// supported.\nfunc (planner *VReplicationQueryPlanner) PlanQuery(stmt sqlparser.Statement) (plan QueryPlan, err error) {\n\tswitch stmt := stmt.(type) {\n\tcase *sqlparser.Select:\n\t\tplan, err = planner.planSelect(stmt)\n\tcase *sqlparser.Insert:\n\t\terr = ErrUnsupportedQuery\n\tcase *sqlparser.Update:\n\t\tplan, err = planner.planUpdate(stmt)\n\tcase *sqlparser.Delete:\n\t\tplan, err = planner.planDelete(stmt)\n\tdefault:\n\t\terr = ErrUnsupportedQuery\n\t}\n\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"%w: %s\", err, sqlparser.String(stmt))\n\t}\n\n\treturn plan, nil\n}\n\n// QueryParams is part of the QueryPlanner interface. A VReplicationQueryPlanner\n// will attach the following WHERE clauses iff (a) DBName, Workflow are set,\n// respectively, and (b) db_name and workflow do not appear in the original\n// query's WHERE clause:\n//\n//\tWHERE (db_name = {{ .DBName }} AND)? (workflow = {{ .Workflow }} AND)? {{ .OriginalWhere }}\nfunc (planner *VReplicationQueryPlanner) QueryParams() QueryParams {\n\treturn QueryParams{\n\t\tDBName:         planner.dbname,\n\t\tDBNameColumn:   \"db_name\",\n\t\tWorkflow:       planner.workflow,\n\t\tWorkflowColumn: \"workflow\",\n\t}","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/workflow/vexec/query_planner.go#L116-L152","documentation":"VReplicationQueryPlanner.PlanQuery only supports a fixed set of statement types (SELECT, UPDATE, DELETE etc.); any other statement (INSERT, DDL, SET, SHOW, etc.) results in ErrUnsupportedQuery. The planner then wraps the error with the offending statement's SQL text so the developer can see exactly which query was rejected.","triggerScenarios":"Calling PlanQuery with a parsed statement that hits the planner's default case — any statement type other than the supported SELECT/UPDATE/DELETE forms (e.g. INSERT, CREATE/ALTER TABLE, SET, SHOW).","commonSituations":"Passing user-supplied or migration SQL that includes INSERTs or DDL to a VReplication workflow query path; automating workflows over arbitrary SQL scripts; typos routing the wrong statement to the planner.","solutions":["Only pass SELECT/UPDATE/DELETE statements supported by VReplicationQueryPlanner to PlanQuery","Rewrite INSERT or DDL work using the appropriate Vitess APIs (e.g. vtctld commands) instead of this planner","Check the wrapped SQL in the error and route unsupported statements elsewhere in your tooling"],"exampleFix":"// before\nplan, err := planner.PlanQuery(ctx, insertStmt) // unsupported\n// after\nswitch stmt.(type) {\ncase *sqlparser.Select, *sqlparser.Update, *sqlparser.Delete:\n    plan, err = planner.PlanQuery(ctx, stmt)\ndefault:\n    return fmt.Errorf(\"statement type not supported by VReplicationQueryPlanner\")\n}","handlingStrategy":"validation","validationCode":"switch stmt.(type) {\ncase *sqlparser.Select, *sqlparser.Update, *sqlparser.Delete:\n    // supported\ndefault:\n    return fmt.Errorf(\"statement type %T unsupported by VReplicationQueryPlanner\", stmt)\n}","typeGuard":"func isPlannableStatement(stmt sqlparser.Statement) bool {\n    switch stmt.(type) {\n    case *sqlparser.Select, *sqlparser.Update, *sqlparser.Delete:\n        return true\n    }\n    return false\n}","tryCatchPattern":"plan, err := planner.PlanQuery(ctx, stmt)\nif errors.Is(err, vexec.ErrUnsupportedQuery) {\n    log.Warnf(\"skipping unsupported statement: %v\", err)\n    return nil\n}","preventionTips":["Filter or whitelist statement types before handing SQL to PlanQuery","Parse and inspect statements with sqlparser before planning","Route DDL/INSERT work to the appropriate Vitess tooling (vtctld, vtgate) instead"],"tags":["go","vreplication","sql","unsupported-query"],"backgroundTag":"unsupported-sql-statement","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}