Cory Klein
Cory Klein

Reputation: 55760

Why is my database file the same size as an ordinary text file with the same data?

We currently store data for a product I work on in ascii plaintext files in a format like this:

timestamp:2011120211T10:42:23
value:42
error:Foobar error
value:100
error:
timestamp:2011120211T10:43:58
value:0
...

I tried importing this exact data from one 13 MB text file into an Sqlite database with columns (DATETIME, TEXT, TEXT, TEXT, TEXT). However, much to my surprise, the file size of the database was also 13 MB.

Why is this? I would expect a database to use a format more space efficient than plain ascii, is that not the case?

Upvotes: 2

Views: 1255

Answers (4)

Tinyfool
Tinyfool

Reputation: 1480

Database is not made for more space efficient, it is made for time efficient. In many case database not waste any space but text is not waste so many space too.

Database record number is more space efficient text, but text is seem as text.

And even have some space benefit, it will not so big to easy find out. But when you use byte not use MB, you will find out.

Upvotes: 0

Andrew Barber
Andrew Barber

Reputation: 40150

That is definitely not the case. There is lots of metadata there, and space is actually often wasted in the name of efficiency, to allow for inserts, for indexing, etc.

The only time I would expect an ASCII dump to be larger than the database files is if the database was largely binary data which would need to be BASE64 encoded to be output as ASCII, and if there were no/minimal indexes.

Upvotes: 8

duffymo
duffymo

Reputation: 308968

I would imagine that the efficiency and speed of the database would stem from the data structures it uses in memory and algorithms that it implements to search, not the structure of the files.

Upvotes: 0

TLiebe
TLiebe

Reputation: 7996

Databases can support compression of data but that affects performance. I'm not familiar with Sqlite but I'd guess that data compression is an option you would need to turn on.

Upvotes: 0

Related Questions