mysql 外键和索引
mysql foreign keys and indexs
如果我有2张桌子
user
-----------------
id integer PK
name varchar
address
----------------
id integer PK
user_id integer
city varchar
现在,如果 user.id <-> adress.user_id 之间存在一对多的外键
还需要在 user_id 列中创建索引以加速 select 查询?
或者因为我已经创建了一个外键,所以我还隐式创建了一个索引,该索引将从 dmbs 中用于加速查询?
索引为created automatically when creating an FK:
The index_name value is ignored if there is already an explicitly
defined index on the child table that can support the foreign key.
Otherwise, MySQL implicitly creates a foreign key index that is named
according to the following rules ...
查看这篇文章:http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.html
InnoDB permits a foreign key to reference any index column or group of
columns. However, in the referenced table, there must be an index
where the referenced columns are listed as the first columns in the
same order.
所以上面有一个索引 table
如果我有2张桌子
user
-----------------
id integer PK
name varchar
address
----------------
id integer PK
user_id integer
city varchar
现在,如果 user.id <-> adress.user_id 之间存在一对多的外键 还需要在 user_id 列中创建索引以加速 select 查询?
或者因为我已经创建了一个外键,所以我还隐式创建了一个索引,该索引将从 dmbs 中用于加速查询?
索引为created automatically when creating an FK:
The index_name value is ignored if there is already an explicitly defined index on the child table that can support the foreign key. Otherwise, MySQL implicitly creates a foreign key index that is named according to the following rules ...
查看这篇文章:http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.html
InnoDB permits a foreign key to reference any index column or group of columns. However, in the referenced table, there must be an index where the referenced columns are listed as the first columns in the same order.
所以上面有一个索引 table