G
G
Godmode2015-11-11 23:40:02
MySQL
Godmode, 2015-11-11 23:40:02

Bytes and data types, what's the catch?

Reading manuals and comments, I periodically come across messages that such and such a data type in Mysql takes so many bytes, for example, like datetime 8 and timestamp 4
I can’t understand what it affects in any way on the sampling speed or on the size of the database on the hard disk and how much can you save? INT sometimes indicate not 11 but 6 for example - what kind of savings is there?
If we take the difference in 4 bytes, then I save 1 Mb on every 262144 records ... not a big saving, it seems to me. Or am I wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2015-11-12
@saboteur_kiev

on 262144 records it may not be dense, but this is a very small database and strange, because the database stores rows of data, and not one single column. 4 bytes here, 4 bytes there, 2 bytes somewhere else. and now it saves decently on one line ..
It also affects the sampling speed (the comparison goes along the entire length), and the size of the database on the hard disk and the size of the table in memory, and its caching.
Let's give a simple example: if we take a 32-bit processor, 32 bits pass through it in one clock cycle. 32 / 8 = 4 bytes.
For example, take a value and add one to it - one assembler cycle per increment instruction itself, one more assembler cycle per value. A total of two beats. And for an 8-byte value, it will take three cycles, that is, the speed of this operation is 33% longer. This example doesn't really work that way, but it is indicative in the sense that you shouldn't throw bytes left and right.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question