[英]Primary Foreign Key slowing down InnoDB inserts
I'm importing a lot (only ~10,000) of employees and then making them all a user account at once. 我要导入很多(仅约10,000名)员工,然后立即将其全部设为用户帐户。 Inserting into my user_profile table is slowing everything down a ton because the primary key of the table is a foreign key as well, and not the usual autoincrement id. 插入到我的user_profile表中会减慢一切速度,因为该表的主键也是外键,而不是通常的自动增量ID。
Is there any way to speed this up? 有什么办法可以加快速度吗? Or do I need to go back and add an autoincrement id to user_profile somehow? 还是我需要返回并以某种方式将自动增量ID添加到user_profile?
Edit: 编辑:
user:
id
username
salt
password
user_profile:
user_id -> Primary Key and Foreign Key to user table
first_name
last_name
email
...
My recommendation is to add a id
field to the user_profile
table, make it the primary key (unsigned and auto_increment). 我的建议是将一个id
字段添加到user_profile
表中,使其成为主键(unsigned和auto_increment)。 Then make the user_id
field the foreign key to the user ( id
) table. 然后,将user_id
字段作为用户( id
)表的外键。 I've never seen a field act as the primary key AND foreign key to another table. 我从未见过字段充当另一个表的主键和外键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.