Efficient Boolean value storage for Innodb Tables
Sometimes you have the task of storing multiple of boolean values (yes/now or something similar) in the table and if you get many columns and many rows you may want to store them as efficient way as possible.
For MyISAM tables you could use BIT(1) fields which get combined together for efficient storage:
-
CREATE TABLE `bbool` (
-
`b1` bit(1) NOT NULL,
-
`b2` bit(1) NOT NULL,
-
`b3` bit(1) NOT NULL,
-
`b4` bit(1) NOT NULL,
-
`b5` bit(1) NOT NULL,
-
`b6` bit(1) NOT NULL,
-
`b7` bit(1) NOT NULL,
-
`b8` bit(1) NOT NULL,
-
`b9` bit(1) NOT NULL,
-
`b10` bit(1) NOT NULL
-
) ENGINE=MyISAM
-
-
mysql> SHOW TABLE STATUS LIKE 'bbool' \G
-
*************************** 1. row ***************************
-
Name: bbool
-
Engine: MyISAM
-
Version: 10
-
Row_format: Fixed
-
Rows: 10
-
Avg_row_length: 7
-
Data_length: 70
-
Max_data_length: 1970324836974591
-
Index_length: 1024
-
Data_free: 0
-
AUTO_INCREMENT: NULL
-
Create_time: 2008-04-24 00:41:01
-
Update_time: 2008-04-24 00:45:40
-
Check_time: NULL
-
Collation: latin1_swedish_ci
-
Checksum: NULL
-
Create_options:
-
Comment:
-
1 row IN SET (0.00 sec)











del.icio.us
digg