我有:
companies
+------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(255) | YES | | NULL | |
+------------+--------------+------+-----+---------+----------------+
users
+----------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| email | varchar(255) | NO | | | |
| username | varchar(255) | NO | UNI | NULL | |
| company_id | int(11) | YES | | NULL | |
| first_name | varchar(255) | YES | | NULL | |
| last_name | varchar(255) | YES | | NULL | |
| title | varchar(255) | YES | | NULL | |
+----------------------+--------------+------+-----+---------+----------------+
notes
+-----------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| user_id | int(11) | YES | | NULL | |
| title | varchar(255) | YES | | NULL | |
| body | text | YES | | NULL | |
+-----------------+--------------+------+-----+---------+----------------+
一家公司有许多用户,用户有许多说明。
My question is, is it bad to denormalize a little by adding a company_id foreign key to the notes table? The reason is that then I can get all the notes for a company with one fewer join than in the current schema.
Or to put the question another way: What are the pros and cons of adding a redundant company_id foreign key to notes?