vitessio/vitess · error
unable to select @@foreign_key_checks
Error message
unable to select @@foreign_key_checks
What it means
getSettingFKCheck reads the current @@foreign_key_checks value from the target mysqld before replicating (it saves the setting, disables FK checks during apply, and restores it). This error is thrown when the query succeeds but returns anything other than exactly one row and one column, which should never happen.
Source
Thrown at go/vt/vttablet/tabletmanager/vreplication/vreplicator.go:610
return nil
}
insertLog(vr.dbClient, LogStateChange, vr.id, state.String(), message)
vr.state = state
return nil
}
func encodeString(in string) string {
return sqltypes.EncodeStringSQL(in)
}
func (vr *vreplicator) getSettingFKCheck() error {
qr, err := vr.dbClient.Execute("select @@foreign_key_checks")
if err != nil {
return err
}
if len(qr.Rows) != 1 || len(qr.Fields) != 1 {
return errors.New("unable to select @@foreign_key_checks")
}
vr.originalFKCheckSetting, err = qr.Rows[0][0].ToCastInt64()
if err != nil {
return err
}
return nil
}
func (vr *vreplicator) needFKRestrict() bool {
ok, err := vr.dbClient.SupportsCapability(capabilities.RestrictFKOnNonStandardKey)
if err != nil {
return false
}
return ok
}
func (vr *vreplicator) getSettingFKRestrict() error {
if !vr.needFKRestrict() {View on GitHub (pinned to 01a25a7d17)
Solutions
- Check the target mysqld health and version — confirm `select @@foreign_key_checks` works in a mysql client on the same instance
- Reset/reconnect the vreplication dbClient connection (restart the workflow or vttablet) if the connection returned a corrupted result
- If behind a MySQL proxy (e.g. Vitess itself or another proxy), ensure it forwards system-variable SELECTs correctly
Defensive patterns
Strategy: try-catch
Validate before calling
// Verify the target supports the variable before relying on FK-check save/restore
qr, err := conn.ExecuteFetch("SELECT @@foreign_key_checks", 1, false)
if err != nil || len(qr.Rows) != 1 || len(qr.Fields) != 1 {
return fmt.Errorf("target cannot read @@foreign_key_checks")
} Try / catch
if err := vr.getSettingFKCheck(); err != nil {
if strings.Contains(err.Error(), "unable to select @@foreign_key_checks") {
// reconnect dbClient and retry once
vr.dbClient.Close()
if rerr := vr.dbClient.Connect(); rerr == nil { return vr.getSettingFKCheck() }
}
return err
} Prevention
- Keep the target on a supported MySQL version
- Avoid proxies between vttablet and mysqld that mangle results
- Monitor vreplication logs for connection corruption
When it happens
Trigger: vr.dbClient.Execute("select @@foreign_key_checks") returns a result whose Rows/Fields cardinality is not 1x1 — e.g. an empty/odd result from a misbehaving connection or proxy.
Common situations: A connection pool/proxy mangles results; the dbClient connection is in a broken state mid-query; custom MySQL builds or versions where the system variable read behaves oddly.
Related errors
- unable to select @@session.restrict_fk_on_non_standard_key
- failed to set session foreign_key_checks: %w
- value out of range
- both atomic copy and partial mode cannot be specified for th
- invalid workflow
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/d1d72ad841b73e68.
Report an issue: GitHub.