E
E
Evgeny Ivanov2018-08-14 07:02:17
MySQL
Evgeny Ivanov, 2018-08-14 07:02:17

Is it optimal to store and use a json string in a database?

The database stores data from the exchange.
Now only the price is stored there. Therefore, for one currency - one column.
But it was necessary to store other data related to this currency (ask, bid, average...).
I'm going to store all the data as a json string. Namely, change the USD field (Decimal type) to the USD field (char type or suggest another better type?). About 100 characters is enough for me.
The main operation with a DB - selection. SELECT.
Select all values ​​where the USD field and time is greater than some number and time is less than a number.
Usually, there are about 100,000 values ​​in a one-time sample.
And now everything is working quite well.
How will such a change affect the load / performance of the system?
There is an option to use more fields. But given that now there are 50 of them, and there are at least 5 new data, the table will already have 250 fields.
Or more tables. Each data type (ask, bid, average...) has its own table.
Is it optimal to store and use a json string in a database?
Which option is better to choose? json string, more fields, more tables?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
R
Rsa97, 2018-08-14
@logpol32

It is enough to add one field - currency, and voila, you can record as many different currencies as you like in your table. And if you build the index correctly, then working with the table will remain fast.

A
Andrey, 2018-08-14
@VladimirAndreev

many databases now natively support json fields.
The question is what to do with this data. Maybe it's worth looking at the document-oriented database initially?

A
Alexander Filippenko, 2018-08-14
@alexfilus

This only makes sense if you are not going to filter/sort/group based on data from a JSON field. If any of this is needed, then it is better to break it down and add the required number of fields / tables.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question