M
M
muhasa2020-02-10 14:08:20
MySQL
muhasa, 2020-02-10 14:08:20

What is the best way to organize a database with a lot of changing parameters?

(For admins - php was added to the tags in order to indicate - the selection from the database will be carried out through Eloquent ORM, so an effective solution in terms of performance is important)

Question, there is such a section in the project - measuring body parameters.
The first thing that suggests itself is to make a simple flat table

body_dimensions
---
id
weight
bust (объем груди)
waist (объем талии)
hip (объем бедер)
fat (массовая доля жира для тех, у кого умные весы)
visceral fat (висцеральный жир)
muscle (мышцы)
bones (кости)
water (доля воды)
created_at
updated_at
user_id


Convenient and fast. But let's imagine - the customer starts adding a bunch of new parameters to all the smart scales of the world along the way, deleting others - it turns out that we need to significantly alter the structure of the table. What you don't want.

Option 2

body_dimensions
---
id
created_at
updated_at
user_id

body_params
---
id
param

body_dimensions_params
---
id
param_id
user_id
value


And here we do not depend on what is added there - the set of parameters can be freely expanded and even come up with an option with turning off or soft deleting parameters.
But here is another problem - the structure is cumbersome and the ORM can start to slow down (the question for those who know is how detrimental this scheme is to performance within ORMs, in particular Eloquent?)

The third scheme is JSON

body_dimensions
---
id
created_at
updated_at
dimensions : json (тут будут измерения {param_id : value})
user_id

body_params
---
id
param


There are only two tables here - one contains the parameters, the other the measurement results. From the point of view of the structure - the most interesting option, should not cause brakes and so on. But what difficulties can arise when building complex queries to the database? How is JSON worked out in this case - is everything complicated right away or is this question well worked out? I recently discovered JSON in databases for myself, I still don’t quite understand how to make clean queries with it for all standard cases of life.

Which option would you choose? Maybe there is some other 4, 5...n solution?..

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2020-02-10
@tsklab

If you do not link data between clients, display the average temperature for a hospital, for example, then you do not need a database.
You need to keep a history of changing some parameters in the client file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question