{"record":{"id":"ac7444c5da36ea3e","repo":"vitessio/vitess","slug":"error-generating-onlineddl-query-v","errorCode":null,"errorMessage":"Error generating OnlineDDL query: %+v","messagePattern":"Error generating OnlineDDL query: %\\+v","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtctl/grpcvtctldserver/server.go","lineNumber":1870,"sourceCode":"\t\tcondition, err = sqlparser.ParseAndBind(\"migration_context=%a\", sqltypes.StringBindVariable(req.MigrationContext))\n\tcase req.Status != vtctldatapb.SchemaMigration_UNKNOWN:\n\t\tspan.Annotate(\"migration_status\", schematools.SchemaMigrationStatusName(req.Status))\n\t\tcondition, err = sqlparser.ParseAndBind(\"migration_status=%a\", sqltypes.StringBindVariable(schematools.SchemaMigrationStatusName(req.Status)))\n\tcase req.Recent != nil:\n\t\tvar d time.Duration\n\t\td, _, err = protoutil.DurationFromProto(req.Recent)\n\t\tif err != nil {\n\t\t\treturn nil, vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, \"error parsing duration: %s\", err)\n\t\t}\n\n\t\tspan.Annotate(\"recent\", d.String())\n\t\tcondition = fmt.Sprintf(\"requested_timestamp > now() - interval %0.f second\", d.Seconds())\n\tdefault:\n\t\tcondition = \"migration_uuid like '%'\"\n\t}\n\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"Error generating OnlineDDL query: %+v\", err)\n\t}\n\n\torder := \" order by `id` \"\n\tswitch req.Order {\n\tcase vtctldatapb.QueryOrdering_DESCENDING:\n\t\torder += \"DESC\"\n\tdefault:\n\t\torder += \"ASC\"\n\t}\n\n\tvar skipLimit string\n\tif req.Limit > 0 {\n\t\tskipLimit = fmt.Sprintf(\"LIMIT %v,%v\", req.Skip, req.Limit)\n\t\tspan.Annotate(\"skip_limit\", skipLimit)\n\t}\n\n\tquery := selectSchemaMigrationsQuery(condition, order, skipLimit)\n","sourceCodeStart":1852,"sourceCodeEnd":1888,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/grpcvtctldserver/server.go#L1852-L1888","documentation":"GetSchemaMigrations builds a SQL WHERE condition against the _vt.schema_migrations table based on the request's time-range filter. The query construction logic tracks an err variable, and if any step of generating the OnlineDDL query condition failed, the RPC returns this wrapped error before issuing the query.","triggerScenarios":"Calling GetSchemaMigrations where the condition-building switch leaves err set (e.g. a malformed duration in the time-range filter producing an invalid interval, per the request's TimeRange/limit settings).","commonSituations":"Passing a zero or negative migration interval/duration that yields a nonsensical SQL interval; client/server proto version mismatch on QueryOrdering/TimeRange fields; programmatic clients constructing odd filter combinations.","solutions":["Check the underlying error detail (%+v) printed in the message","Validate the requested time range/duration before calling (positive, finite duration)","Simplify the request: drop the time filter or use an explicit migration_uuid list","Ensure client protos match the server Vitess version"],"exampleFix":"// before\nreq.TimeRange = durationpb.New(-5 * time.Minute)\n// after\nreq.TimeRange = durationpb.New(24 * time.Hour)","handlingStrategy":"validation","validationCode":"if req.TimeRange != nil && req.TimeRange.AsDuration() <= 0 {\n    return fmt.Errorf(\"TimeRange must be a positive duration\")\n}","typeGuard":"func validTimeRange(tr *durationpb.Duration) bool { return tr == nil || tr.AsDuration() > 0 }","tryCatchPattern":"resp, err := client.GetSchemaMigrations(ctx, req)\nif err != nil && strings.Contains(err.Error(), \"Error generating OnlineDDL query\") {\n    // drop/fix the time filter and retry with a uuid list\n}","preventionTips":["Always pass positive, finite durations for time-range filters","Prefer filtering by explicit migration_uuid lists","Keep client protos matched to the server version","Test query-filter combinations against a staging cell before production"],"tags":["vitess","onlineddl","schema-migrations","query-generation"],"backgroundTag":"online-ddl-query-generation-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}