E
E
Egor Developerov2015-10-16 12:03:39
MySQL
Egor Developerov, 2015-10-16 12:03:39

Creating tables by month, MySQL - which way to choose?

There is a table of active sessions, which is written and read quite dynamically. The number of records in it is growing terribly fast. The information is necessary and active, so I can’t archive immediately for the last month.
Here, I came to the conclusion that creating tables by months is the best solution for my case. The only negative is that if the session was opened at the end of last month, and you need to close it in the current one, what should you do? I'm scratching my head...
How can I implement it better?
- creation by Cron
- hang a trigger for the DBMS
- sew this logic into the app itself
- your option

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
shagguboy, 2015-10-16
@spacecucumber

https://dev.mysql.com/doc/refman/5.6/en/partitioni...

L
lega, 2015-10-21
@lega

The only negative is that if the session was opened at the end of last month, and you need to close it in the current one, what should you do? Breaking my head...
There are many options, depending on how you will use the data.
For example, if the session closes, then transfer it from the previous month to the current one (the start month is sewn into the session id).
You can also store events (and not a period), then you can "cut" the data even by days / by hours, for example:
session_id, event, datetime
12345, 'start_session', 2015-09-15
12345, 'finish_session', 2015- 10-15

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question