Answer the question
In order to leave comments, you need to log in
Best way to store data when having a variable large number of attributes?
I'm starting to cut my project, while at the stage of thinking about the concept and technical details.
Now I'm stuck on the fact that I don't know how best to store application data.
It is assumed that there will be several kinds of entities, which may have a variable number of attributes given. You can fill in 10 pieces, or you can fill in 70, but for each type of entity, a set of attributes is known in advance. Moreover, there will be several types of these entities - some attributes will overlap, but most will differ. After the technical implementation, the attributes may change, but this is rather an exception. Estimated number of entries is 100-300k lines. The catch is that I would like to implement revisions of materials, so that the number of lines will constantly grow. Reading will take precedence over (over)writing. It is difficult to predict the number of requests, especially since I have not thought about caching yet.
The easiest solution is to make multiple tables in MySQL- in one common attributes and for each type of entity on a unique table with unique attributes. The disadvantage of this approach is that a table with 50 columns does not look like a good idea :)
The second thing that came to my mind is MongoDB , but I have no experience with it, and after reading some materials, I doubted the appropriateness of the choice.
Well, the third option is to use PostgreSQL with its JSON data type.
Answer the question
In order to leave comments, you need to log in
In MySQL, you can do this: store entities (entity ID, title, ...) in one table, all attributes (ID, title) in another table, attribute values (entity ID, attribute ID, value) in the third table. If necessary, add two more tables: entity types (view ID, title, ...) and entity type relationships with attributes (view ID, attribute ID). This scheme allows you to change the number of attributes without altering the structure of tables and there are no tables with 50 columns).
In PostgreSQL, you can use the hstore extension or, since 9.4, the jsonb type (json with efficient binary storage).
Can be like this.
Product - Products
Product_features - Product properties
Features - Properties (here you can additionally describe what value the property has, for example, "string", "range", "number", etc.)
Feature_values - Property values (here you can merge with the Product_features table)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question