The storage requirements for each of the data types supported by MySQL are listed here by category. The maximum size of a row in a For tables using the An exception to this rule is the In addition, while a When calculating storage requirements for MySQL Cluster tables, you must also remember that every table using the You may find the Storage Requirements for Numeric Types The storage requirements for As of MySQL 5.0.3, values for Before MySQL 5.0.3, Storage Requirements for Date and Time Types The storage requirements shown in the table arise from the way that MySQL represents temporal values: A four-byte integer packed as A four-byte integer packed as Storage Requirements for String Types In the following table, Variable-length string types are stored using a length prefix plus data. The length prefix requires from one to four bytes depending on the data type, and the value of the prefix is To calculate the number of bytes used to store a particular The actual length of the column value The column's maximum possible length The character set used for the column, because some character sets contain multi-byte characters For example, a The effective maximum number of bytes that can be stored in a As of MySQL 5.0.3, the If the size of the column is fewer than 256 characters, the column requires one byte extra storage per row. If the size of the column is 256 characters or more, the column requires two bytes extra storage per row. The number of bytes required per character varies according to the character set used. For example, if a The size of an The size of a MyISAM
table is 65,535 bytes. (However, each BLOB
or TEXT
column contributes only 9-12 bytes toward this size.) This limitation may be shared by other storage engines as well. Important
NDBCLUSTER
storage engine, there is the factor of 4-byte alignment to be taken into account when calculating storage requirements. This means that all NDB
data storage is done in multiples of 4 bytes. Thus, a column value that would take 15 bytes in a table using a storage engine other than NDB
requires 16 bytes in anNDB
table. This requirement applies in addition to any other considerations that are discussed in this section. For example, in NDBCLUSTER
tables, the TINYINT
, SMALLINT
, MEDIUMINT
, and INTEGER
(INT
) column types each require 4 bytes storage per record due to the alignment factor.BIT
type, which is not 4-byte aligned. In MySQL Cluster tables, a BIT(
column takes M
)M
bits of storage space. However, if a table definition contains 1 or more BIT
columns (up to 32 BIT
columns), then NDBCLUSTER
reserves 4 bytes (32 bits) per row for these. If a table definition contains more than 32 BIT
columns (up to 64 such columns), then NDBCLUSTER
reserves 8 bytes (that is, 64 bits) per row.NULL
itself does not require any storage space, NDBCLUSTER
reserves 4 bytes per row if the table definition contains any columns defined as NULL
, up to 32 NULL
columns. (If a MySQL Cluster table is defined with more than 32 NULL
columns up to 64 NULL
columns, then 8 bytes per row is reserved.)NDBCLUSTER
storage engine requires a primary key; if no primary key is defined by the user, then a “hidden” primary key will be created by NDB
. This hidden primary key consumes 31-35 bytes per table record.ndb_size.pl
utility to be useful for estimating NDB
storage requirements. This Perl script connects to a current MySQL (non-Cluster) database and creates a report on how much space that database would require if it used the NDBCLUSTER
storage engine. See Section 17.9.14, “ndb_size.pl — NDBCLUSTER Size Requirement Estimator”, for more information.Data Type Storage Required 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
<= 53FLOAT
4 bytes DOUBLE [PRECISION]
, REAL
8 bytes DECIMAL(
, M
,D
)NUMERIC(
M
,D
)Varies; see following discussion BIT(
M
)approximately ( M
+7)/8 bytesDECIMAL
(and NUMERIC
) are version-specific:DECIMAL
columns are represented using a binary format that packs nine decimal (base 10) digits into four bytes. Storage for the integer and fractional parts of each value are determined separately. Each multiple of nine digits requires four bytes, and the “leftover” digits require some fraction of four bytes. The storage required for excess digits is given by the following table:Leftover Digits Number of Bytes 0 0 1 1 2 1 3 2 4 2 5 3 6 3 7 4 8 4 DECIMAL
columns are represented as strings and storage requirements are: M
+2 bytes if D
> 0,
bytes if M
+1D
= 0, D
+2 if M
< D
DATE
: A three-byte integer packed as DD
+ MM
×32 + YYYY
×16×32TIME
: A three-byte integer packed as DD
×24×3600 + HH
×3600 + MM
×60 + SS
DATETIME
: Eight bytes:YYYY
×10000 + MM
×100 + DD
HH
×10000 + MM
×100 + SS
TIMESTAMP
: A four-byte integer representing seconds UTC since the epoch ('1970-01-01 00:00:00'
UTC)YEAR
: A one-byte integerM
represents the declared column length in characters for non-binary string types and bytes for binary string types. L
represents the actual length in bytes of a given string value.Data Type Storage Required CHAR(
M
)M
× w
bytes, 0 <=
255, where M
<=w
is the number of bytes required for the maximum-length character in the character setBINARY(
M
)M
bytes, 0 <=
255M
<=VARCHAR(
, M
)VARBINARY(
M
)L
+ 1 bytes if column values require 0 – 255 bytes, L
+ 2 bytes if values may require more than 255 bytesTINYBLOB
, TINYTEXT
L
+ 1 bytes, where L
< style="margin-left: 3px; font-weight: normal; ">8BLOB
, TEXT
L
+ 2 bytes, where L
< style="margin-left: 3px; font-weight: normal; ">16MEDIUMBLOB
, MEDIUMTEXT
L
+ 3 bytes, where L
< style="margin-left: 3px; font-weight: normal; ">24LONGBLOB
, LONGTEXT
L
+ 4 bytes, where L
< style="margin-left: 3px; font-weight: normal; ">32ENUM('
value1
','value2
',...)1 or 2 bytes, depending on the number of enumeration values (65,535 values maximum) SET('
value1
','value2
',...)1, 2, 3, 4, or 8 bytes, depending on the number of set members (64 members maximum) L
(the byte length of the string). For example, storage for a MEDIUMTEXT
value requires L
bytes to store the value plus three bytes to store the length of the value.CHAR
, VARCHAR
, or TEXT
column value, you must take into account the character set used for that column and whether the value contains multi-byte characters. In particular, when using the utf8
Unicode character set, you must keep in mind that not all utf8
characters use the same number of bytes and can require up to three bytes per character. For a breakdown of the storage used for different categories of utf8
characters, see Section 9.1.9, “Unicode Support”.VARCHAR
, VARBINARY
, and the BLOB
and TEXT
types are variable-length types. For each, the storage requirements depend on these factors:VARCHAR(255)
column can hold a string with a maximum length of 255 characters. Assuming that the column uses the latin1
character set (one byte per character), the actual storage required is the length of the string (L
), plus one byte to record the length of the string. For the string 'abcd'
, L
is 4 and the storage requirement is five bytes. If the same column is instead declared to use the ucs2
double-byte character set, the storage requirement is 10 bytes: The length of 'abcd'
is eight bytes and the column requires two bytes to store lengths because the maximum length is greater than 255 (up to 510 bytes).Note
VARCHAR
or VARBINARY
column is subject to the maximum row size of 65,535 bytes, which is shared among all columns. For a VARCHAR
column that stores multi-byte characters, the effective maximum number of characters is less. For example, utf8
characters can require up to three bytes per character, so a VARCHAR
column that uses the utf8
character set can be declared to be a maximum of 21,844 characters.NDBCLUSTER
engine supports only fixed-width columns. This means that a VARCHAR
column from a table in a MySQL Cluster will behave as follows:VARCHAR(100)
column in a Cluster table uses the utf8
character set, each character requires 3 bytes storage. This means that each record in such a column takes up 100 × 3 + 1 = 301 bytes for storage, regardless of the length of the string actually stored in any given record. For a VARCHAR(1000)
column in a table using theNDBCLUSTER
storage engine with the utf8
character set, each record will use 1000 × 3 + 2 = 3002 bytes storage; that is, the column is 1,000 characters wide, each character requires 3 bytes storage, and each record has a 2-byte overhead because 1,000 >= 256.TEXT
and BLOB
columns are implemented differently in the NDB Cluster storage engine, wherein each row in aTEXT
column is made up of two separate parts. One of these is of fixed size (256 bytes), and is actually stored in the original table. The other consists of any data in excess of 256 bytes, which is stored in a hidden table. The rows in this second table are always 2,000 bytes long. This means that the size of a TEXT
column is 256 if size
<= 256 (where size
represents the size of the row); otherwise, the size is 256 + size
+ (2000 – (size
– 256) % 2000).ENUM
object is determined by the number of different enumeration values. One byte is used for enumerations with up to 255 possible values. Two bytes are used for enumerations having between 256 and 65,535 possible values. See Section 10.4.4, “The ENUM
Type”.SET
object is determined by the number of different set members. If the set size is N
, the object occupies (
bytes, rounded up to 1, 2, 3, 4, or 8 bytes. A N
+7)/8SET
can have a maximum of 64 members. SeeSection 10.4.5, “The SET
Type”.
Monday, March 23, 2009
Data Type Storage Requirements
Posted by
admin
at
7:41 PM
Subscribe to:
Post Comments (Atom)
Search Articles
Study Categories
- 3D (1)
- actionscript (3)
- Activity (5)
- Articles (1)
- Blog (1)
- browser (5)
- CMS (1)
- Computing (1)
- css (1)
- database (6)
- Designer Guidelines (2)
- dreamweaver (4)
- Editor's Pick (1)
- Events (2)
- flash (9)
- Games (1)
- google (2)
- Graphic (4)
- html (2)
- IIS (2)
- javascript (7)
- Joomla (3)
- Lazacode (2)
- menu navigation (2)
- Mobile (1)
- MySQL (5)
- Online Tools (1)
- Open Source Development Kit (11)
- OS (5)
- pdf (1)
- PHP (7)
- PHP. Server (1)
- Powerpoint (1)
- Ruby (1)
- Server (5)
- Software/Tools (8)
- tracker (1)
- video (1)
- Vista (2)
- VMS (1)
- Web Editor (5)
- Web Idea (2)
- Website tricks (2)
- What is? (6)
- Windows (2)
- Wordpress (1)
0 comments:
Post a Comment