vitessio/vitess · error
unable to select @@session.restrict_fk_on_non_standard_key
Error message
unable to select @@session.restrict_fk_on_non_standard_key
What it means
getSettingFKRestrict reads @@session.restrict_fk_on_non_standard_key (Vitess/MySQL FK restriction setting) from the target before applying replication, saving the original value. The error is returned when the result is not exactly one row and one column.
Solutions
- Verify the target server supports restrict_fk_on_non_standard_key (check mysqld version and Vitess compatibility)
- Test `select @@session.restrict_fk_on_non_standard_key` manually against the target; if unknown-variable errors occur, upgrade or point replication at a supported target
- Reconnect/restart vreplication (or vttablet) if the result shape was corrupted by a stale connection
Defensive patterns
Strategy: validation
Validate before calling
// Confirm the target understands the session variable before starting vreplication
qr, err := conn.ExecuteFetch("SELECT @@session.restrict_fk_on_non_standard_key", 1, false)
if err != nil {
return fmt.Errorf("target does not support restrict_fk_on_non_standard_key: %v", err)
} Try / catch
if err := vr.getSettingFKRestrict(); err != nil {
if strings.Contains(err.Error(), "restrict_fk_on_non_standard_key") {
log.Warn("target missing FK restrict variable", slog.Any("error", err))
}
return err
} Prevention
- Run a Vitess-compatible mysqld version on targets
- Smoke-test FK-related session variables before moving tables
- Pin target versions in deployment configs
When it happens
Trigger: vr.dbClient.Execute("select @@session.restrict_fk_on_non_standard_key") returns a result with Rows/Fields cardinality != 1x1 — most commonly an unknown-variable error path variant or an empty result set.
Common situations: Target mysqld/MySQL version that doesn't define restrict_fk_on_non_standard_key (older versions return an error, which surfaces as the wrapped query error instead); running replication against a non-Vitess MySQL without the variable; broken connection/proxy.
Related errors
- unable to select @@foreign_key_checks
- failed to set session foreign_key_checks
- attempted to execute unprepared query
- both atomic copy and partial mode cannot be specified for…
- can only delete a specific vdiff, please provide a valid…
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/89b6326d3defa3cc.
Report an issue: GitHub.
Appendix: source
Thrown at go/vt/vttablet/tabletmanager/vreplication/vreplicator.go:636
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() {
return nil
}
qr, err := vr.dbClient.Execute("select @@session.restrict_fk_on_non_standard_key")
if err != nil {
return err
}
if len(qr.Rows) != 1 || len(qr.Fields) != 1 {
return errors.New("unable to select @@session.restrict_fk_on_non_standard_key")
}
vr.originalFKRestrict, err = qr.Rows[0][0].ToCastInt64()
if err != nil {
return err
}
return nil
}
func (vr *vreplicator) resetFKCheckAfterCopy(dbClient *vdbClient) error {
_, err := dbClient.Execute(fmt.Sprintf("set @@session.foreign_key_checks=%d", vr.originalFKCheckSetting))
return err
}
func (vr *vreplicator) resetFKRestrictAfterCopy(dbClient *vdbClient) error {
if !vr.needFKRestrict() {
return nil
}
_, err := dbClient.Execute(fmt.Sprintf("set @@session.restrict_fk_on_non_standard_key=%d", vr.originalFKRestrict))View on GitHub (pinned to 01a25a7d17)