Reputation: 55760
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
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
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
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
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