2

I am trying to estimate database size for know column range. I have searched on it but cant find any proper rules.

I have created a database with single table and this table have 40 Columns. One column is a int primary key and remaining 39 columns are LONGTEXT type.

I am expecting 2 million records.

CREATE TABLE IF NOT EXISTS `TempTable` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
    `Column1` longtext,
    `Column2` longtext,
    --
    --
    --

    `Column39` longtext,

  PRIMARY KEY (`Id`)
)

How can I do this? Do I need to insert fake data to calculate the size?

Gordon Linoff
  • 1,198,228
  • 53
  • 572
  • 709
Shoaib Ijaz
  • 4,903
  • 9
  • 48
  • 80

1 Answers1

2

Using the Data Type Storage Requirements you can estimate the table size:

  • The int is 4 bytes, note that (11) only indicates the maximum number of digits to show (see this answer).
  • (L+4) per string column, L being the length in bytes of the string. But note that when you use Unicode (utf8) not all characters use the same number of bytes.

So the size would be:

R * ( 4 + 39*(L+4) )

With R being the number of records, and L the average string size.

Taking R=2*106 and L=1000 bytes, this gives about:

2*106 * ( 4 + 39 ( 1004 ) ) = 7.832 * 1010 bytes

which is about 72.9 GiB, for other L's:

L (bytes)       : 10    100   1000   10000
Table size (GiB):  1    7.5   72.9   726.7

Some further notes:

Community
  • 1
  • 1
agold
  • 5,872
  • 9
  • 40
  • 53