{"record":{"id":"b8d7480842e2e02e","repo":"vitessio/vitess","slug":"error-getting-select-s","errorCode":null,"errorMessage":"error getting select: %s","messagePattern":"error getting select: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"go/vt/vtctl/workflow/utils.go","lineNumber":873,"sourceCode":"\tcase querypb.Type_INT64:\n\t\t_, err := strconv.Atoi(vrOptions.TenantId)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"tenant id is not a valid int: %s\", vrOptions.TenantId)\n\t\t}\n\t\ttenantId = vrOptions.TenantId\n\tcase querypb.Type_VARCHAR:\n\t\ttenantId = sqltypes.EncodeStringSQL(vrOptions.TenantId)\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unsupported tenant column type: %s\", tenantColumnType)\n\t}\n\n\tstmt, err := parser.Parse(fmt.Sprintf(\"select * from t where %s = %s\", sqlescape.EscapeID(tenantColumnName), tenantId))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tsel, ok := stmt.(*sqlparser.Select)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"error getting select: %s\", tenantId)\n\t}\n\treturn &sel.Where.Expr, nil\n}\n\nfunc changeKeyspaceRouting(ctx context.Context, ts *topo.Server, tabletTypes []topodatapb.TabletType,\n\tsourceKeyspace, targetKeyspace, reason string,\n) error {\n\troutes := make(map[string]string)\n\tfor _, tabletType := range tabletTypes {\n\t\tsuffix := getTabletTypeSuffix(tabletType)\n\t\troutes[sourceKeyspace+suffix] = targetKeyspace\n\t}\n\tif err := updateKeyspaceRoutingRules(ctx, ts, reason, routes); err != nil {\n\t\treturn err\n\t}\n\treturn ts.RebuildSrvVSchema(ctx, nil)\n}\n","sourceCodeStart":855,"sourceCodeEnd":891,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtctl/workflow/utils.go#L855-L891","documentation":"After parsing the synthetic tenant query ('select * from t where <col> = <lit>'), getTenantClause asserts the AST node is a *sqlparser.Select. A successfully parsed statement that is not a Select indicates the constructed SQL was not a plain SELECT (unexpected, given the fixed template), so the function bails with this error, reporting the tenant id value in the message.","triggerScenarios":"Practically only when the parsed statement is something other than a Select — e.g. the generated WHERE text leads the parser to produce a non-Select AST (set/other statement) — an internal invariant failure in the tenant clause builder.","commonSituations":"Rarely seen in the field; would surface as an internal error while building tenant-filtered MoveTables streams, typically after unusual tenant column names or values edge their way into the generated SQL.","solutions":["Verify the tenant column name is a plain identifier; quote with backticks if it contains special characters (sqlescape.EscapeID handles this).","Retry with a simple alphanumeric tenant column name to isolate the problem.","If reproducible, file a Vitess bug with the tenant column name/type and tenant id used.","Check the wrapped parser error (returned first) for the root cause of the unexpected parse."],"exampleFix":"// before\ntenant_column: \"select *\" // odd column name confuses generated SQL\n// after\n--tenant-column tenant_id","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"expr, err := getTenantClause(...)\nif err != nil {\n\tif strings.Contains(err.Error(), \"error getting select\") {\n\t\tlog.Errorf(\"tenant clause builder produced non-SELECT AST (tenantId=%v): %v\", tenantID, err)\n\t}\n\treturn err\n}","preventionTips":["Keep tenant column names as simple identifiers; escape special names with sqlescape.EscapeID","Treat this as an internal invariant failure — capture inputs and file a Vitess issue if seen","Check the underlying parser error returned before this branch for the real cause"],"tags":["sqlparser","tenant","internal","movetables"],"backgroundTag":"unexpected-ast-node","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}