欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

MySQL表字段數(shù)量限制及行大小限制詳情

 更新時(shí)間:2022年07月22日 14:06:05   作者:T.Y.Bao  
這篇文章主要介紹了MySQL表字段數(shù)量限制及行大小限制詳情,表的行最大的row size會(huì)限制字段數(shù)量,如果當(dāng)前row size過大就不能加字段了,更多相關(guān)需要的小伙伴可以參考下面文章詳情

字段數(shù)量限制 Column Count Limits

MySQL對(duì)于每個(gè)表的字段數(shù)量是嚴(yán)格控制在4096個(gè),但是實(shí)際情況下的限制大小取決于以下因素(也就是基本達(dá)不到4096就被限制了):

  • 表的行最大的row size會(huì)限制字段數(shù)量,如果當(dāng)前row size過大就不能加字段了
  • The storage requirements of individual columns constrain the number of columns that fit within a given maximum row size.
  • 存儲(chǔ)引擎本身也會(huì)對(duì)字段數(shù)量有限制,比如Innodb最大字段數(shù)量為1017
  • 每張表都有一個(gè)后綴為.frm的表定義文件,表定義可能會(huì)影響字段數(shù)量大小

行大小限制 Row Size Limits

row size由以下因素影響:

  • MySQL本身對(duì)row size有硬性規(guī)定,不能超過65535bytes,即使存儲(chǔ)引擎允許更大的size. 而BLOBTEXT類型列只占行的9到12個(gè)字節(jié),具體存儲(chǔ)地方不在該行里;但是其他的比如varchar還是算在行里的,這里要注意
  • Innodb存儲(chǔ)引擎對(duì)于每行的大小一般限制為頁(yè)大小的一半:頁(yè)16KB,row size 8KB。另外對(duì)于不定長(zhǎng)類型也有不同:If a row containing variable-length columns exceeds the InnoDB maximum row size, InnoDB selects variable-length columns for external off-page storage until the row fits within the InnoDB row size limit. The amount of data stored locally for variable-length columns that are stored off-page differs by row format. For more information, see InnoDB Row Formats.簡(jiǎn)單來說就是,對(duì)于像varchar這種不定長(zhǎng)類型,如果這種類型長(zhǎng)度超過了Innodb存儲(chǔ)引擎規(guī)定的row size,那么Innodb會(huì)選擇頁(yè)外存儲(chǔ)直到行大小符合Innodb存儲(chǔ)引擎規(guī)定的row size。(但是即使這樣也不能超過65535B,即65535B是包含不定長(zhǎng)列中的內(nèi)容的長(zhǎng)度)
  • Different storage formats use different amounts of page header and trailer data, which affects the amount of storage available for rows. Row Size Limit Examples 65535B限制
mysql> CREATE TABLE t (a VARCHAR(10000), b VARCHAR(10000),
       c VARCHAR(10000), d VARCHAR(10000), e VARCHAR(10000),
       f VARCHAR(10000), g VARCHAR(6000)) ENGINE=InnoDB CHARACTER SET latin1;
ERROR 1118 (42000): Row size too large. The maximum row size for the used
table type, not counting BLOBs, is 65535. This includes storage overhead,
check the manual. You have to change some columns to TEXT or BLOBs

看,由于Latin1編碼1個(gè)字符是1個(gè)字節(jié),總共不能超過65535個(gè)字符,超過就報(bào)錯(cuò);而常用的utf8mb4編碼最多1個(gè)字符占用4個(gè)字節(jié),所以當(dāng)使用utf8mb4編碼時(shí),最多只能有65535/4=16383個(gè)字符(實(shí)際測(cè)肯定會(huì)小點(diǎn),因?yàn)檫€有字節(jié)去記錄變長(zhǎng)字段長(zhǎng)度):

test> CREATE TABLE t (a VARCHAR(10000), b VARCHAR(6384)
             ) ENGINE=InnoDB CHARACTER SET utf8mb4
[2022-07-21 15:05:56] [42000][1118] Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs

test> CREATE TABLE t (a VARCHAR(10000), b VARCHAR(6383)
             ) ENGINE=InnoDB CHARACTER SET utf8mb4
[2022-07-21 15:09:51] [42000][1118] Row size too large. The maximum row size for the used table type, not counting BLOBs, is 65535. This includes storage overhead, check the manual. You have to change some columns to TEXT or BLOBs
test> CREATE TABLE t (a VARCHAR(10000), b VARCHAR(6382)
             ) ENGINE=InnoDB CHARACTER SET utf8mb4
[2022-07-21 15:09:58] completed in 33 ms

根據(jù)提示,如果超過row size限制,可以使用TEXT or BLOBs類型,這個(gè)在row size中只占用9到12個(gè)字節(jié)。

8126B限制

65535B的限制主要針對(duì)不定長(zhǎng)類型的限制,而定長(zhǎng)類型的限制更為嚴(yán)格,像在Innodb存儲(chǔ)引擎中,只能達(dá)到8KB多也就是頁(yè)大小的一半(可以修改)。

innodb_strict_mode is enabled in the following example to ensure that InnoDB returns an error if the defined columns exceed the InnoDB row size limit. When innodb_strict_mode is disabled (the default), creating a table that uses REDUNDANT or COMPACT row format succeeds with a warning if the InnoDB row size limit is exceeded.

mysql> SET SESSION innodb_strict_mode=1;
mysql> CREATE TABLE t4 (
       c1 CHAR(255),c2 CHAR(255),c3 CHAR(255),
       c4 CHAR(255),c5 CHAR(255),c6 CHAR(255),
       c7 CHAR(255),c8 CHAR(255),c9 CHAR(255),
       c10 CHAR(255),c11 CHAR(255),c12 CHAR(255),
       c13 CHAR(255),c14 CHAR(255),c15 CHAR(255),
       c16 CHAR(255),c17 CHAR(255),c18 CHAR(255),
       c19 CHAR(255),c20 CHAR(255),c21 CHAR(255),
       c22 CHAR(255),c23 CHAR(255),c24 CHAR(255),
       c25 CHAR(255),c26 CHAR(255),c27 CHAR(255),
       c28 CHAR(255),c29 CHAR(255),c30 CHAR(255),
       c31 CHAR(255),c32 CHAR(255),c33 CHAR(255)
       ) ENGINE=InnoDB ROW_FORMAT=COMPACT DEFAULT CHARSET latin1;
ERROR 1118 (42000): Row size too large (> 8126). Changing some columns to TEXT or BLOB or using
ROW_FORMAT=DYNAMIC or ROW_FORMAT=COMPRESSED may help. In current row format, BLOB prefix of 768
bytes is stored inline.

Row Limits總結(jié)

Row Limits 一般為 MySQL本身65535B限制和存儲(chǔ)引擎8126B限制(默認(rèn)Innodb)。

  • 針對(duì)不定長(zhǎng)類型,如varchar,一般首先收到限制的是MySQL本身65535B的限制。受不到存儲(chǔ)引擎限制是因?yàn)?,不定長(zhǎng)類型如果長(zhǎng)度超過8126B,會(huì)采用頁(yè)外存儲(chǔ),也就是不定長(zhǎng)類型的長(zhǎng)度過長(zhǎng)的話計(jì)入65535B而不計(jì)入8126B(大致可以這么理解)。
  • 針對(duì)定長(zhǎng)類型,首先會(huì)受到存儲(chǔ)引擎8126B限制。

到此這篇關(guān)于MySQL表字段數(shù)量限制及行大小限制詳情的文章就介紹到這了,更多相關(guān)MySQL行大小限制內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論