I'd always thought that the storage size of a BIT(1)
column is 1 bit.
But http://dev.mysql.com/doc/refman/5.6/en/storage-requirements.html
states that it is approximately (1+7)/8 bytes = 1 byte = 8 bits.
If I have 32000 rows of BIT(1)
data, does it mean that it takes 32000 * (1+7)/8 bytes = 32000 bytes of storage ?
KB, MB, GB - A kilobyte (KB) is 1,024 bytes. A megabyte (MB) is 1,024 kilobytes. A gigabyte (GB) is 1,024 megabytes. A terabyte (TB) is 1,024 gigabytes. kb, Mb, Gb - A kilobit (kb) is 1,024 bits.
byte: Abbreviation for binary term, a unit of storage capable of holding a single character. On almost all modern computers, a byte is equal to 8 bits. Large amounts of memory are indicated in terms of kilobytes, megabytes, and gigabytes.
The byte was originally the smallest number of bits that could hold a single character (I assume standard ASCII). We still use ASCII standard, so 8 bits per character is still relevant.
Whole numbers (integers) are usually represented with 4 bytes, or 32 bits. In the past, symbols (e.g., letters, digits) were represented with one byte (8 bits), with each symbol being mapped to a number between 0-255. The ASCII table provides the mapping.
BIT(M) approximately (M+7)/8 bytes
http://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html
-> data needs to be aligned so mysql need multiples of byte
What this means is that the database engine can't store just one bit. It will combine all bit fields in a table and store them together until it reaches the minimum size it can store on disk (say 4 bytes on a 32 bit machine). The next bit field will be stored in a second 4-byte memory slot.
So on this typical 32 bit machine, one bit or 32 bits will need 4 bytes, and 33 bits would need 8 bytes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With