Understanding MySQL Row Size Limits: Server and InnoDB Layer Calculations
This article explains MySQL's row size restrictions at both the Server and InnoDB layers, detailing the calculation methods, relevant source code paths, error messages, and practical guidelines for ensuring total record length stays within the 65535‑byte server limit and the 8126‑byte InnoDB limit.
MySQL imposes two main row size limits: the Server layer restricts a single record to a maximum of 65535 bytes, while the InnoDB layer limits the size to half of the innodb_page_size (default 16 KB, i.e., 8126 bytes).
The Server‑side limit can be observed from error messages such as “Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535.” The relevant source functions are mysql_prepare_create_table , mysql_create_frm , and pack_header , where the check if (reclength > (ulong) file->max_record_length()) triggers the error.
To compute the Server‑side record length, the article presents pseudo‑code that adds the null‑bitmap size ( (number_null_field + 7) / 8 ), the sum of each field’s packed length ( calc_pack_length(field_type, length) ), and any extra overhead. The function calc_pack_length returns different byte counts depending on the MySQL type (e.g., VARCHAR adds 1 or 2 bytes for length, numeric types return fixed sizes).
InnoDB’s limit is enforced by checking rec_max_size >= page_rec_max . The maximum record size on a leaf page is derived from page_get_free_space_of_empty(comp) , which for the default 16 KB page returns 16252 bytes; halving this yields 8126 bytes. Constants such as UNIV_PAGE_SIZE_DEF (1 << 14 = 16384) and REC_MAX_DATA_SIZE (16384) are used in the calculation.
The article also details how InnoDB computes rec_max_size by adding fixed‑length field sizes, variable‑length field overhead, and null‑bitmap bytes. Functions like dict_col_get_fixed_size , dtype_get_fixed_size_low , and dict_col_get_max_size are referenced, showing how different data types contribute to the total.
Finally, the article concludes that both the Server and InnoDB limits must be satisfied for a table to be created successfully; oversized VARCHAR columns are a common cause of failure, and converting them to TEXT or reducing their length can resolve the issue.
Aikesheng Open Source Community
The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.