{"record":{"id":"89b6326d3defa3cc","repo":"vitessio/vitess","slug":"unable-to-select-session-restrict-fk-on-non-stan","errorCode":null,"errorMessage":"unable to select @@session.restrict_fk_on_non_standard_key","messagePattern":"unable to select @@session\\.restrict_fk_on_non_standard_key","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vttablet/tabletmanager/vreplication/vreplicator.go","lineNumber":636,"sourceCode":"\nfunc (vr *vreplicator) needFKRestrict() bool {\n\tok, err := vr.dbClient.SupportsCapability(capabilities.RestrictFKOnNonStandardKey)\n\tif err != nil {\n\t\treturn false\n\t}\n\treturn ok\n}\n\nfunc (vr *vreplicator) getSettingFKRestrict() error {\n\tif !vr.needFKRestrict() {\n\t\treturn nil\n\t}\n\tqr, err := vr.dbClient.Execute(\"select @@session.restrict_fk_on_non_standard_key\")\n\tif err != nil {\n\t\treturn err\n\t}\n\tif len(qr.Rows) != 1 || len(qr.Fields) != 1 {\n\t\treturn errors.New(\"unable to select @@session.restrict_fk_on_non_standard_key\")\n\t}\n\tvr.originalFKRestrict, err = qr.Rows[0][0].ToCastInt64()\n\tif err != nil {\n\t\treturn err\n\t}\n\treturn nil\n}\n\nfunc (vr *vreplicator) resetFKCheckAfterCopy(dbClient *vdbClient) error {\n\t_, err := dbClient.Execute(fmt.Sprintf(\"set @@session.foreign_key_checks=%d\", vr.originalFKCheckSetting))\n\treturn err\n}\n\nfunc (vr *vreplicator) resetFKRestrictAfterCopy(dbClient *vdbClient) error {\n\tif !vr.needFKRestrict() {\n\t\treturn nil\n\t}\n\t_, err := dbClient.Execute(fmt.Sprintf(\"set @@session.restrict_fk_on_non_standard_key=%d\", vr.originalFKRestrict))","sourceCodeStart":618,"sourceCodeEnd":654,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vttablet/tabletmanager/vreplication/vreplicator.go#L618-L654","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Confirm the target understands the session variable before starting vreplication\nqr, err := conn.ExecuteFetch(\"SELECT @@session.restrict_fk_on_non_standard_key\", 1, false)\nif err != nil {\n    return fmt.Errorf(\"target does not support restrict_fk_on_non_standard_key: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := vr.getSettingFKRestrict(); err != nil {\n    if strings.Contains(err.Error(), \"restrict_fk_on_non_standard_key\") {\n        log.Warn(\"target missing FK restrict variable\", slog.Any(\"error\", err))\n    }\n    return err\n}","preventionTips":["Run a Vitess-compatible mysqld version on targets","Smoke-test FK-related session variables before moving tables","Pin target versions in deployment configs"],"tags":["vreplication","foreign-keys","system-variable","version-compat"],"backgroundTag":"unknown-system-variable","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}