bit(8) vs tinyint
In the eyes of the storage engine, is there any difference at all between bit(8)
and tinyint
?
or bit(16)
vs smallint
?
or bit(24)
vs mediumint
?
or bit(32)
vs int
?
What I want to know is that are they sy开发者_如何学编程nonymous and the engine treats one like the other?
First off: I don't have any idea of the internals of how the individual engines would treat bit fields when trying to do queries. I would be curious if it would be faster to index or query those two column types.
From a raw storage standpoint, these are the storage requirements for numeric types:
- TINYINT = 1 byte
- SMALLINT = 2 bytes
- MEDIUMINT = 3 bytes
- INT, INTEGER = 4 bytes
- BIGINT = 8 bytes
- FLOAT(p) = 4 bytes if 0 <= p <= 24, 8 bytes if 25 <= p <= 53 FLOAT = 4 bytes
- DOUBLE
[PRECISION], REAL = 8 bytes - DECIMAL(M,D), NUMERIC(M,D) = Varies; see following discussion
- BIT(M) =
approximately (M+7)/8 bytes
Unless you're using NDBCluster storage engine which requires 4 bytes per storage record. (unless you have multiple bit types which will compact into that 4 byte minimum)
Edit:
According to this page on numeric types tinyint(1) and bit were synonymous before version 5.0.3 for myISAM and 5.0.5 for MEMORY, InnoDB, BDB, and NDBCLUSTER. This would imply they are no longer.
精彩评论