{"record":{"id":"510171ea8ad14d1b","repo":"vitessio/vitess","slug":"cannot-reserve-variables-with-a-prefix","errorCode":null,"errorMessage":"cannot reserve variables with a '_' prefix","messagePattern":"cannot reserve variables with a '_' prefix","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/sqlparser/reserved_vars.go","lineNumber":168,"sourceCode":"\t\t\treturn bvar\n\t\t}\n\t}\n}\n\n// NewReservedVars allocates a ReservedVar instance that will generate unique\n// variable names starting with the given `prefix` and making sure that they\n// don't conflict with the given set of `known` variables.\nfunc NewReservedVars(prefix string, known BindVars) *ReservedVars {\n\trv := &ReservedVars{\n\t\tprefix:   prefix,\n\t\tcounter:  0,\n\t\treserved: known,\n\t\tfast:     true,\n\t\tnext:     []byte(prefix),\n\t}\n\n\tif prefix != \"\" && prefix[0] == '_' {\n\t\tpanic(\"cannot reserve variables with a '_' prefix\")\n\t}\n\n\tfor bvar := range known {\n\t\tif strings.HasPrefix(bvar, prefix) {\n\t\t\trv.fast = false\n\t\t\tbreak\n\t\t}\n\t}\n\n\tif prefix == \"vtg\" {\n\t\trv.static = true\n\t}\n\treturn rv\n}\n","sourceCodeStart":150,"sourceCodeEnd":183,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/sqlparser/reserved_vars.go#L150-L183","documentation":"NewReservedVars builds a reserved-variable normalizer that generates bind variable names with the given prefix. A '_' prefix is forbidden because Vitess internally uses underscore-prefixed names for its own hidden variables; using '_' as user prefix would collide with internal system-generated variables and break normalization.","triggerScenarios":"Calling NewReservedVars(\"_\", known) or any prefix starting with '_' (e.g. \"_vt\", \"_inner\") in tests or code that builds a normalizer.","commonSituations":"Test authors picking an intuitive '_'-prefixed prefix for internal-looking bind variables; refactoring that passes user-supplied prefix strings straight into NewReservedVars.","solutions":["Use a non-underscore prefix, e.g. \"vt\" or \"bv\"","Validate user-supplied prefixes for a leading '_' before calling NewReservedVars","If you need hidden variables, use Vitess's dedicated internal variable mechanisms instead of the reserved-var prefix"],"exampleFix":"// before\nrv := sqlparser.NewReservedVars(\"_v\", known)\n// after\nrv := sqlparser.NewReservedVars(\"v\", known)","handlingStrategy":"validation","validationCode":"func safePrefix(p string) error {\n    if strings.HasPrefix(p, \"_\") {\n        return fmt.Errorf(\"prefix %q must not start with '_'\", p)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use plain alphanumeric prefixes like \"bv\" or \"vt\" for bind variables","Never feed user-supplied prefix strings directly into NewReservedVars without a leading-underscore check","Remember underscore prefixes are reserved for Vitess internal variables"],"tags":["sqlparser","reserved-vars","prefix-validation","panic","naming"],"backgroundTag":"invalid-prefix","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}