Skip to main content

πŸ—“οΈ 31012025 1512
πŸ“Ž #wip

mysql_column_data_size

Numeric Types​

Data TypeSize (MySQL)Notes / DetailsCross-Database Consideration
TINYINT1 byteRange: -128 to 127 (signed), 0 to 255 (unsigned)Similar in PostgreSQL, SQL Server
SMALLINT2 bytesRange: -32,768 to 32,767 (signed)Same size in most RDBMS
MEDIUMINT3 bytesMySQL-specific; not common in other databasesRarely supported elsewhere
INT or INTEGER4 bytesRange: -2,147,483,648 to 2,147,483,647 (signed)Common size across databases
BIGINT8 bytesRange: -2⁢³ to 2⁢³-1 (signed)Standard size in most RDBMS
DECIMAL(p, s)Varies based on precision pApprox. ⌊p / 9βŒ‹ Γ— 4 bytesCan vary slightly; PostgreSQL and SQL Server similar
FLOAT4 bytesSingle-precision floating-pointSame across databases
DOUBLE (or REAL)8 bytesDouble-precision floating-pointStandard across databases

Character/String Types​

Data TypeSize (MySQL)Notes / DetailsCross-Database Consideration
CHAR(n)Fixed n bytes (padded)Fixed-length string (padded with spaces)Same concept across databases
VARCHAR(n)Length of string + 1 or 2 bytes for length prefix1 byte prefix if n ≀ 255, otherwise 2 bytesSimilar in most RDBMS; PostgreSQL uses 4-byte header
TINYTEXTUp to 255 bytes + 1 byte length prefixText stored separately; only a pointer in rowMySQL-specific; other RDBMS use TEXT with varying storage
TEXTUp to 65,535 bytes + 2-byte length prefixAllocated on separate pageSupported by most RDBMS, but PostgreSQL stores inline by default
MEDIUMTEXTUp to 16,777,215 bytes + 3-byte length prefixLarge text; external storageMySQL-specific; PostgreSQL uses TEXT with no limit
LONGTEXTUp to 4,294,967,295 bytes + 4-byte length prefixFor massive text storageMySQL-specific; alternative storage may be needed in other RDBMS
ENUM1 or 2 bytes1 byte for up to 255 values, 2 bytes for largerMySQL-specific; PostgreSQL uses CHECK constraints

Date/Time Types​

Data TypeSize (MySQL)Notes / DetailsCross-Database Consideration
DATE3 bytesStores year, month, and dayStandard across databases
DATETIME8 bytesStores date and time (accurate to seconds)Same size across databases
TIMESTAMP4 bytesStores seconds since 1970 (UNIX epoch time)Slight differences in handling across databases
TIME3 bytesStores time (accurate to seconds)Standard size across databases
YEAR1 byteStores year (1901 to 2155)MySQL-specific, rarely supported elsewhere

Binary Data Types​

Data TypeSize (MySQL)Notes / DetailsCross-Database Consideration
BINARY(n)Fixed length, n bytesSimilar to CHAR but stores binary dataSupported by most RDBMS
VARBINARY(n)Length of data + 1 or 2 bytes for length prefixSimilar to VARCHAR, for binary dataSupported in most databases
TINYBLOBUp to 255 bytes + 1 byte prefixStores small binary dataMySQL-specific; PostgreSQL stores binary data as BYTEA
BLOBUp to 65,535 bytes + 2-byte prefixBinary large objectSupported by most databases (e.g., BYTEA in PostgreSQL)
MEDIUMBLOBUp to 16,777,215 bytes + 3-byte prefixFor larger binary objectsMySQL-specific
LONGBLOBUp to 4,294,967,295 bytes + 4-byte prefixFor very large binary objectsMySQL-specific

Other Types​

Data TypeSize (MySQL)Notes / DetailsCross-Database Consideration
BIT(n)Varies, typically ⌈n / 8βŒ‰ bytesCompact storage for binary bitsSimilar concept across databases; SQL Server uses BIT
BOOLEAN or BOOL1 byteStored as TINYINT(1) internallyDifferent in PostgreSQL (BOOLEAN) and SQL Server (BIT)
JSONVaries (depends on content)Stored as text in MySQLSupported as native type in PostgreSQL

Row Overhead​

Overhead TypeSize (MySQL)Notes
Row metadata overhead7-23 bytes per rowIncludes transaction ID, rollback pointer, etc.
NULL storage overhead~1 bit per nullable columnStored in a bitmap in row metadata
Variable-length column overhead1-2 bytes per columnLength metadata for each variable-length column

Index storage​

  • Primary keys and secondary indexes also take up space.
  • Estimate each index’s size using: index size = (index key size + pointer size) * number of rows

The pointer size in InnoDB is typically 6 bytes. For composite indexes, sum the sizes of all indexed columns.

TODO: Deeper dive into B tree / B+ Tree storage size


References