0

I hava a database with the following structure.

enter image description here

How can I determine, what storage space will a number of such entries take, if:

I'll run this on a MySql server (innoDB). The int columns will have small values (1-30 at most), except one, which will have a value between [1-400].

There will be 40 entries produced every day.

TheAptKid
  • 1,559
  • 3
  • 25
  • 47

2 Answers2

1

Mysql manual has a section on data type storage space. Since you are using numbers and dates, which are stored on fixed length, it is pretty easy to estimate the storage space: each integer column requires 4 bytes (even if you store the numeric value of 1 in it), the date column requires 3 bytes.

You may reduce the storage requirements by using smaller integer types.

Shadow
  • 33,525
  • 10
  • 51
  • 64
  • Also you should add that NULL takes no space with InnoDB, according to this: http://stackoverflow.com/questions/229179/null-in-mysql-performance-storage – rlanvin Jun 15 '16 at 06:26
  • @rlanvin unless you expect to have a bunch of nulls in every record, it does not matter when you **estimate** the required data storage space. If you expect to have a bunch of nulls, then I would consider using a different table structure anyway. – Shadow Jun 15 '16 at 06:39
  • well you never know, there are perfectly valid use cases for nulls. Anyway, I just thought it was worth mentioning for the sake of completeness. – rlanvin Jun 15 '16 at 07:10
  • I never said there was no valid uses cases for nulls. My point is that an occasional null value here and there will not significantly impact the space needed for a table, hence there is no point in considering this saving in an estimate - unless you know that you will have not just a few, but lots of nulls. – Shadow Jun 15 '16 at 08:59
0

What you have described comes in the "tiny" category. After adding the 40 entries for the first day, you will be a few hundred bytes, occupying one 16KB InnoDB block.

After a year, you might have a megabyte -- still "tiny" as database tables go.

Switch to SMALLINT, add UNSIGNED if appropriate; that will cut it down noticeably. Follow the various links in the comments and other answers; they give you more insight.

Rick James
  • 135,179
  • 13
  • 127
  • 222