Z
Z
ZoorGan2014-03-06 16:52:47
MySQL
ZoorGan, 2014-03-06 16:52:47

How to organize the structure of database tables?

It is necessary to store information about the interaction of the user with the object in the database. Among the characteristics of the session, there are two parameters: the duration of the session and the elements of the object involved. The proposed structure is as follows:
The sessions
rIBD7x9Wze.png
table The elements
9X5TECFbtT.png
table The linking table session_elements
l7tJMfcviE.png
Everything seems to be fine, but there will be too many sessions (80k-100k per month) and elements (10k-20k). Thus, the link table will grow even faster in the calculation that one session will have an average of 5-10 elements. The main queries will look like:

SELECT  * FROM `sessions` WHERE `duration` > 100 AND EXIST (SELECT  * FROM `session_elements` WHERE `session_id` = 1 AND `element_id` = 1)

I would like not to make a mistake at the design stage and not to redo it in the course of work. The size of the tables is intimidating. Maybe it would be more appropriate to use something like mongoDB and store it in convenient json formats?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Kerman, 2014-03-06
@ZoorGan

Let's count. 2 ints per session (8 bytes) 100,000 times a month is 800kb. Plus elements, let's say 20 bytes per line and 4 bytes per int in the amount of 20,000 - this is 192kb. Total 1 megabyte per month. 12 mb per year.
My conclusion: put a couple of GB on the server. memory for 500 rubles and forget about the problems of the next 170 years.

G
gro, 2014-03-06
@gro

What does this request do?

G
gro, 2014-03-06
@gro

It is not clear what these requests are and at what point they will occur.
If at each page load, then this is one thing, and if once by cron at night to collect statistics, then another.
Explicitly text json will grow much faster than a two int table.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question