Limits on Table Column Count and Row Size
2990
ALTER TABLE
tbl_name
MAX_ROWS=1000000000 AVG_ROW_LENGTH=
nnn
;
You have to specify
AVG_ROW_LENGTH
only for tables with
BLOB
or
TEXT
columns; in this case,
MySQL can't optimize the space required based only on the number of rows.
To change the default size limit for
MyISAM
tables, set the
myisam_data_pointer_size
[473]
,
which sets the number of bytes used for internal row pointers. The value is used to set
the pointer size for new tables if you do not specify the
MAX_ROWS
option. The value of
myisam_data_pointer_size
[473]
can be from 2 to 7. A value of 4 permits tables up to 4GB; a
value of 6 permits tables up to 256TB.
You can check the maximum data and index sizes by using this statement:
SHOW TABLE STATUS FROM
db_name
LIKE '
tbl_name
';
You also can use
myisamchk -dv /path/to/table-index-file
. See
Section 13.7.5, “
SHOW
Syntax”
, or
Section 4.6.3, “
myisamchk
— MyISAM Table-Maintenance Utility”
.
Other ways to work around file-size limits for
MyISAM
tables are as follows:
• If your large table is read only, you can use
myisampack
to compress it.
myisampack
usually
compresses a table by at least 50%, so you can have, in effect, much bigger tables.
myisampack
also can merge multiple tables into a single table. See
Section 4.6.5, “
myisampack
— Generate
Compressed, Read-Only MyISAM Tables”
.
• MySQL includes a
MERGE
library that enables you to handle a collection of
MyISAM
tables that
have identical structure as a single
MERGE
table. See
Section 14.3, “The
MERGE
Storage Engine”
.
• You are using the
NDB
storage engine, in which case you need to increase the values for the
DataMemory
and
IndexMemory
configuration parameters in your
config.ini
file. See
Section 17.3.3.1, “MySQL Cluster Data Node Configuration Parameters”
.
• You are using the
MEMORY
(
HEAP
) storage engine; in this case you need to increase the value of the
max_heap_table_size
[468]
system variable. See
Section 5.1.4, “Server System Variables”
.
E.7.4. Limits on Table Column Count and Row Size
There is a hard limit of 4096 columns per table, but the effective maximum may be less for a given
table. The exact limit depends on several interacting factors.
• Every table (regardless of storage engine) has a maximum row size of 65,535 bytes. Storage
engines may place additional constraints on this limit, reducing the effective maximum row size.
The maximum row size constrains the number (and possibly size) of columns because the total
length of all columns cannot exceed this size. For example,
utf8
characters require up to three
bytes per character, so for a
CHAR(255) CHARACTER SET utf8
column, the server must allocate
255 × 3 = 765 bytes per value. Consequently, a table cannot contain more than 65,535 / 765 = 85
such columns.
Storage for variable-length columns includes length bytes, which are assessed against the row size.
For example, a
VARCHAR(255) CHARACTER SET utf8
column takes two bytes to store the length
of the value, so each value can take up to 767 bytes.
BLOB
and
TEXT
columns count from one to four plus eight bytes each toward the row-size limit
because their contents are stored separately from the rest of the row.
Declaring columns
NULL
can reduce the maximum number of columns permitted. For
MyISAM
tables,
NULL
columns require additional space in the row to record whether their values are
NULL
.
Each
NULL
column takes one bit extra, rounded up to the nearest byte. The maximum row length in
bytes can be calculated as follows:
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...