简体   繁体   中英

Should I Store Unix Time In A Separate Table

My application records status changes in discord. (Online, offline, idle and DND) This is achieved using discord.py and an SQL server (MariaDB).

Specifically, if I receive hundreds of of status updates per second (all with the same Unix timestamp since they happened within a second of each other), should I Store each Unix timestamp in a separate table with an ID for each?

I am asking this question in hopes of saving disk space in the long run.

My hypothesis is that if a smaller number is stored with less digits (the ID that points to a timestamp), it would take up less space as the large Unix timestamp wouldn't need to be repeated hundreds of times.

A few questions/remarks are raised by your post...

  1. Do you really need to store timestamps with up-to-the-second accuracy? SToring with a bigger interval would mean less space usage.
  2. You could use a smaller int to store timestamps with an epoch closer to the present, so you could use less space overall, without needing a new table.
  3. You should maybe consider dropping events that happen too frequently. If a user change status 10 times in a minute, maybe it's not worth it recording them all?
  4. Finaly, an enum (smallint) and a timestamp is not that big in a database. They can usualy handle thousand of gigabytes "just fine"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM