In MySQL, is a BIT column a suitable way to store 5, 6, or 7 byte integers?

I have a table whose size I would like to preserve, and one of the columns can be considered as a 5-byte unsigned integer. This is a column that I will not look for.

MySQL offers integer data types

  • TINYINT, for 1-byte integers
  • SMALLINT for 2 byte integers
  • MEDIUMINT, for 3-byte integers
  • INT, for 4 byte integers
  • BIGINT for 8 byte integers.

But he also suggests BIT(M), for 1 ≤ M ≤ 64. This saves (effectively) an unsigned integer from 0 to 2 M-1 . Is there any reason to avoid using a column BIT(40)to store a 5-byte integer? (As I said, I do not need to search on this column. Therefore, any difficulties associated with the speed of query execution can be ignored.)

+3
source share
2 answers

MySQL BIT , . , BIT - . , 57 BIT (8). 57 `b'00111001 ', 57. 9, 57 - ASCII' 9 '. , .

CREATE TABLE testbit(a BIT(8));
INSERT INTO testbit VALUES (b'00111001');
INSERT INTO testbit VALUES (57);
SELECT a FROM testbit;
SELECT a+0 FROM testbit;
+2

, tinyint.

. 1 8 1 , , , tinyint.

, , .

: , . .

+3

Source: https://habr.com/ru/post/1759498/


All Articles