Skip to content

Commit 3ad6ab9

Browse files
committed
Update some comment about FK unique index
1 parent 2d2b030 commit 3ad6ab9

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

infos/db.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,10 +558,19 @@ func (info *FKInfo) RefColumns() []*ColumnInfo {
558558

559559
// RefUniqueIndex returns the referenced unique index.
560560
// NOTE: It only returns unique index that have exactly the same group of columns as the referenced columns.
561-
// See: https://dev.mysql.com/doc/refman/5.6/en/create-table-foreign-keys.html
562-
// InnoDB permits a foreign key to reference any column or group of columns. However, in the referenced table,
563-
// there must be an index where the referenced columns are listed as the first columns in the same order.
564-
// NDB requires an explicit unique key (or primary key) on any column referenced as a foreign key.
561+
//
562+
// By SQL standard, the referenced columns should be a primary key or unique key of the referenced table
563+
// to uniquely identify a row. But
564+
//
565+
// InnoDB allows a foreign key constraint to reference a non-unique key.
566+
// This is an InnoDB extension to standard SQL.
567+
//
568+
// However
569+
//
570+
// The handling of foreign key references to nonunique keys or keys that contain NULL values
571+
// is not well defined (...) You are advised to use foreign keys that reference only UNIQUE
572+
// (including PRIMARY) and NOT NULL keys.
573+
//
565574
func (info *FKInfo) RefUniqueIndex() *IndexInfo {
566575
if info == nil {
567576
return nil

0 commit comments

Comments
 (0)