Databases · Junior · Question 73 of 75
Does PostgreSQL automatically create an index on a foreign key column like orders.user_id?
- ✓Correct answer: No; only primary keys and unique constraints get indexes automatically, so you usually add one yourself
- 2Only if the table has more than 1000 rows
- 3Yes, always
Explanation
Without an index, joins by user_id and deletes of users (which check for referencing orders) have to scan the whole orders table.