database - MySQL JOIN Abuse? How bad can it get? -
I am reading a lot about relational databases on each SELECT using several joint statements. However, I was thinking that there is a problem in the long term while misusing this method.
For example, we say that we have a user
table, I will usually add the "most used" data instead of doing any additional jons. For example, When the "most used" data is called, the user name, image, and location will be displayed.
This data will always be required when displaying any user interaction on the website, for example: each comments
table JOIN for articles
. Instead users
& amp; Use the information on the users_profiles
tables, just the user
table to get 'location' and 'display'.
This is my attitude, although I know that there are very good and experienced programmers who can give me a word of advice about this matter.
My questions are:
Should I try? Being conservative with Jones? Or should I use them more?
Note: I have to explain that I am not trying to avoid zones, I use them only when it is necessary to comment on this example / The article authors will have additional profile information that only appears on the user profile pages ... etc.
My advice about data modeling is:
- 1: 1 should support optional (blank) columns generally speaking . There are still instances where 1: 1 is understood, usually rotates around sub-type.
- Whenever too is not indirect appropriate (more on this below);
- The grace of joining the aggregation may vary, so that it needs to be examined. For an example of this see;
- Enhances the selection of N + 1 better, for example, an N + 1 selection, choosing an order from a database table, and then to get all the line items for that order, Issuing query;
- Scalability to connect Typically only one problem when you are making a large selection If you choose a row and then join some things, then seldom There is a problem (but sometimes it is);
- The foreign key should be indexed always until you work with a small table;
More.
Now for the sake of a model, I give you an example. Suppose you are creating a system for authentication and authorization of users. An ovenentennial solution might look like this:
- Surname (id, user name, user_id);
- User (id, ...);
- Login Roles (ID, Login_ID, Role_ID); <
- role (id, name);
- Role Privilege (ID, Role_ID, Privilege_ID);
- Privileges (id, name).
So you need 6 to get the actual username in the real name. Sure it may be a genuine requirement but this system can not be construed due to hand-irritability due to some developers thinking that they may need one day, even if each user has There is only one surname, the login user is 1: 1 and so is a simple solution:
- User (id, username, email address, user type) < / Ul>
And, It is true, that's it. Perhaps if you need a complex role system, but it is also very possible that you do not, and if you do this then it is easy for slots (User Type becomes a foreign key in a user type or roles table ) Or is it usually new to the old, new to the old.
This is a matter of complexity: it is easy to connect and is difficult to remove, generally it is constantly monitored against the unexpected complexity, which is bad by adding and reducing unnecessary complexity.
Comments
Post a Comment