A
A
Artem00712017-07-19 12:59:39
MySQL
Artem0071, 2017-07-19 12:59:39

What is the best way to expand the database?

What is the best way to expand the database? In breadth or divided by tables?
For example, I have a table with users (users), and I want to expand it with links (link # 1, link # 2, link # 3, link # 4, link # 5)
Which is better, add fields for users, or create a separate a link table (social) (taking into account the fact that there are a limited number of links (for example, 5), so there will be a one-to-many relationship, but does it make sense)?
What will be processed faster, tables with many fields, or queries with many JOINs?
Example 2
Let's say I want to create system information for users (which needs to be constantly retrieved), such as user_visibility, comment_opportunity, ... and 5 more fields
In this case, is it better to complement the main one or create a separate one and make a one-to-one relationship with the primary key in the form of a user ID?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Abdula Magomedov, 2017-07-19
@Artem0071

Definitely, it is necessary to make a separate table.
UPD1:. You can do either way, but the fact is that wide tables are difficult to maintain. When everything is laid out on the shelves, expanding the project is easy. And if everything is in one pile if you shove it, then the time will come that even refactoring will not work, because everything has become more complicated, and you start writing all over again from scratch.
UPD2:. And never make a choice based on the fact that you will have a limited amount of something. This is the wrong approach. Because ideas are such that they change every day. Therefore, we must proceed from the principle that there are no problems for expansion.
UPD3:. If you are interested in learning more about database design, I recommend the book by the author "Bill Carwin". Names "Programming SQL databases. Typical errors and their elimination."

J
JSmitty, 2017-07-19
@JSmitty

If you do not need to search by columns, then modern versions of MySQL are able to type json columns, in which you can store all sorts of such unstructured data. Or serialize additional data into a json string, and save it in a text field.
In general, go to the bright side of the force - PostgreSQL. He has it all so developed that a request with joins and search in some cases is even significantly slower, against a request for arbitrary json. And there are indexes on json. And in relation to your question - in PG out of the box there are types of arrays (i.e. a field can store an array of values ​​\u200b\u200bof an arbitrary size), varchar[] for example, for a list of links is quite suitable. And there is a syntax for converting arrays into anything, displaying an arbitrary element, making queries using them, etc.
The classic solution has already been suggested to you, but depending on specific requests, it can be very inefficient (and denormalization is required). In addition, yes, limiting the number of links by columns is not very smart (and the code will turn out to be more cumbersome).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question