When designing an InnoDB table, identify an advantage of using the BIT datatype Instead of one of the integer datatypes.

When designing an InnoDB table, identify an advantage of using the BIT datatype Instead of one
of the integer datatypes.

When designing an InnoDB table, identify an advantage of using the BIT datatype Instead of one
of the integer datatypes.

A.
BIT columns are written by InnoDB at the head of the row, meaning they are always the first to
be retrieved.

B.
Multiple BIT columns pack tightly into a row, using less space.

C.
BIT (8) takes less space than eight TINYINT fields.

D.
The BIT columns can be manipulated with the bitwise operators &, |, ~, ^, <<, and >>. The other
integer types cannot.

Explanation:



Leave a Reply 7

Your email address will not be published. Required fields are marked *


Steve

Steve

C.

BIT(8) will use one byte, whereas 8 TINIYINT columns will take 8 bytes.

Tim Little

Tim Little

Can we verify that? I make such a table, and BIT(8) seems to take up more than a single bit (lots more) in INNODB. I am using version 5.6.12.

Saimoni

Saimoni

Have tested and results indicate – C is answer

Created 2 tables – populated with 4K rows each, same date – number “1”
No indexes

CREATE TABLE `bit_table` (
`id` bit(8) NOT NULL
)
COLLATE=’latin1_swedish_ci’
ENGINE=InnoDB;

CREATE TABLE `smallint_table` (
`id1` smallint NOT NULL,
`id2` smallint NOT NULL,
`id3` smallint NOT NULL,
`id4` smallint NOT NULL,
`id5` smallint NOT NULL,
`id6` smallint NOT NULL,
`id7` smallint NOT NULL,
`id8` smallint NOT NULL
)
COLLATE=’latin1_swedish_ci’
ENGINE=InnoDB;

Compared sizes

SELECT table_name AS “Tables”,
round(((data_length + index_length) / 1024 / 1024), 2) “Size in MB”
FROM information_schema.TABLES
WHERE table_name in (‘bit_table’,’smallint_table’)
ORDER BY (data_length + index_length) DESC;

+—————-+————+
| Tables | Size in MB |
+—————-+————+
| smallint_table | 0.20 |
| bit_table | 0.14 |
+—————-+————+

mysql> select count(1) from smallint_table;
+———-+
| count(1) |
+———-+
| 4001 |
+———-+
1 row in set (0.00 sec)

mysql> select count(1) from bit_table;
+———-+
| count(1) |
+———-+
| 4001 |
+———-+
1 row in set (0.00 sec)

RPJ

RPJ

Question is: what is the answer they are looking on for the exam.

Cristian

Cristian

C is correct – confirmed as Saimoni did (on 5.6.14-56-log Percona Server). I think B is the red herring because this is true in Sybase & Microsoft, but not in MySQL. D is plain wrong (other numeric types CAN be manipulated with bit operators, though the result is a little obfuscated), and A is just bullshit. 😉