How databases store data on your drive

in #technology6 years ago

Maybe you already know how to work with databases. You can select values and search for specific rows as well as join several tables together. But have you ever wondered, how a database management system (DBMS) stores your data on the drive?
A table is displayed in two dimensions, but you cannot do that when you want to store the table, so how does that work?
To work that out we have a look at a simple table with only three columns:

Now there are two different ways of saving these information to the drive. Those are called rowstore and columnstore. Rowstore, as the name suggests, stores the row column after column for every row:

So in this case every three entries the next row starts. The other (popular) way of storing data on the drive is column store where all entries of a columns are stored after each other.

That's not too complicated, is it? The interesting question is, what technology to use if you can decide.
Row store is a good choice if you have a lot of columns and want to display them. Also it is the right choice, when you often insert rows (with many columns) or single columns have a lot of data, like blobs.
On the other hand column store is the better choice, if you have not that many columns and a lot of entries. In this example it will be faster if you want to know, how much salary you have to pay a year (with the sum function) or if you want to update the salary column to give every employee a raise.
Another advantage of columnstore is the more efficient compressing. Since all values in a column have the same type it is easier to compress these when they are saved all next to each other. In addition every single column can be compressed on its own.
Before you enable compressing in your database you should remember, that, especially if you use columnstore, you have to decompress a lot of data to read single rows.

That being said it now should be clear, that there are not the perfect settings for every database. You should always plan ahead and think about what you want to do with that table, how much data you will store in that table and how often and with what actions the data is being accessed.

Sort:  

Congratulations @eldrior! You have received a personal award!

1 Year on Steemit
Click on the badge to view your Board of Honor.

Do not miss the last post from @steemitboard:
SteemitBoard World Cup Contest - The results, the winners and the prizes

Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Congratulations @eldrior! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 60085.46
ETH 2416.33
USDT 1.00
SBD 2.43