I wanted to know what is the better approach (performance wise) when working with Yii and mysql tables:
- 1 table with ALL the columns
- multiple tables (distribute the columns across them) with foreign keys relations
basically, what i’m asking is:
Is there any performance degradation when a single table has many relations since Yii will fetch all the corresponding tables into the object when you do a query?
A more general question is: what is good practice and smarter approach when dealing with 1 vs multiple tables and foreign keys (again performance..)
If performance was the only criteria in your design strategy, you would choose 1. A very bad choice, that would give you a lot of problems in a later stage of your problems.
Databases should be designed with normalization in mind, so without any doubt, you must choose option 2!
Update
Example of normalized and not normalized: suppose we have a table with dvd rentals, and want to keep track of who rented the dvd:
flat table:
There is room for 3 rental entries, after that there is trouble. Beside that, when there is a extra field needed for the phone number of the customers, 3 extra fields must be made.
First step normalization:
This is better, but still not fully normalized. What if a customer rents the same dvd twice. Then there would be a double customer entry in the rentals table.
Final: