背景
最近遇到一个业务问题,在执行一个大的业务查询时会抛出异常报错,所以今天就总结一下 MySQL执行请求报错 Row size too large (> 8126) 报错的相关问题。
现象
- 触发报错主要是使用了order by 语句。
- 相同的SQL ,不同的实例。有报错,有不报错。
- 所有实例都set innodb_strict_mode = off;
报错
ERROR 1118 (42000): Row size too large (> 8126). Changing some columns to TEXT or BLOB may help. In current row format, BLOB prefix of 0 bytes is stored inline.
MySQL 限制
创建表报错:maximum row size > 65535
创建表报错:row size too large > 8126
插入数据报错:row size too larget > 8126
- 创建表报错:maximum row size > 65535
此限制是由mysql 服务进行限制的,不论使用什么存储引擎,都会限制行大小不能超过65535。代码示例:
CREATETABLE 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,is65535. This includes storage overhead,check the manual. You have to change some columns to TEXTor BLOBs
- 创建表报错:row size too large > 8126
此限制是innodb 存储引擎限制,在创建表时报错。限制行的长度为innodb_page 一半略小一点的大小(溢出页不算在内)。
当 set innodb_strict_mode = off; 时,创建表,只会抛出Warning 的警告,并不会报错。代码示例:
CREATETABLE tab ( col1 varchar(40)NOTNULL, col2 varchar(40)NOTNULL, col3 varchar(40)NOTNULL, col4 varchar(40)NOTNULL, col5 varchar(40)NOTNULL, col6 varchar(40)NOTNULL, col7 varchar(40)NOTNULL, col8 varchar(40)NOTNULL, col9 varchar(40)NOTNULL, col10 varchar(40)NOTNULL, col11 varchar(40)NOTNULL, col12 varchar(40)NOTNULL, col13 varchar(40)NOTNULL, col14 varchar(40)NOTNULL, col15 varchar(40)NOTNULL, col16 varchar(40)NOTNULL, col17 varchar(40)NOTNULL, col18 varchar(40)NOTNULL, col19 varchar(40)NOTNULL, col20 varchar(40)NOTNULL, col21 varchar(40)NOTNULL, col22 varchar(40)NOTNULL, col23 varchar(40)NOTNULL, col24 varchar(40)NOTNULL, col25 varchar(40)NOTNULL, col26 varchar(40)NOTNULL, col27 varchar(40)NOTNULL, col28 varchar(40)NOTNULL, col29 varchar(40)NOTNULL, col30 varchar(40)NOTNULL, col31 varchar(40)NOTNULL, col32 varchar(40)NOTNULL, col33 varchar(40)NOTNULL, col34 varchar(40)NOTNULL, col35 varchar(40)NOTNULL, col36 varchar(40)NOTNULL, col37 varchar(40)NOTNULL, col38 varchar(40)NOTNULL, col39 varchar(40)NOTNULL, col40 varchar(40)NOTNULL, col41 varchar(40)NOTNULL, col42 varchar(40)NOTNULL, col43 varchar(40)NOTNULL, col44 varchar(40)NOTNULL, col45 varchar(40)NOTNULL, col46 varchar(40)NOTNULL, col47 varchar(40)NOTNULL, col48 varchar(40)NOTNULL, col49 varchar(40)NOTNULL, col50 varchar(40)NOTNULL, col51 varchar(40)NOTNULL, col52 varchar(40)NOTNULL, col53 varchar(40)NOTNULL, col54 varchar(40)NOTNULL, col55 varchar(40)NOTNULL, col56 varchar(40)NOTNULL, col57 varchar(40)NOTNULL, col58 varchar(40)NOTNULL, col59 varchar(40)NOTNULL, col60 varchar(40)NOTNULL, col61 varchar(40)NOTNULL, col62 varchar(40)NOTNULL, col63 varchar(40)NOTNULL, col64 varchar(40)NOTNULL, col65 varchar(40)NOTNULL, col66 varchar(40)NOTNULL, col67 varchar(40)NOTNULL, col68 varchar(40)NOTNULL, col69 varchar(40)NOTNULL, col70 varchar(40)NOTNULL, col71 varchar(40)NOTNULL, col72 varchar(40)NOTNULL, col73 varchar(40)NOTNULL, col74 varchar(40)NOTNULL, col75 varchar(40)NOTNULL, col76 varchar(40)NOTNULL, col77 varchar(40)NOTNULL, col78 varchar(40)NOTNULL, col79 varchar(40)NOTNULL, col80 varchar(40)NOTNULL, col81 varchar(40)NOTNULL, col82 varchar(40)NOTNULL, col83 varchar(40)NOTNULL, col84 varchar(40)NOTNULL, col85 varchar(40)NOTNULL, col86 varchar(40)NOTNULL, col87 varchar(40)NOTNULL, col88 varchar(40)NOTNULL, col89 varchar(40)NOTNULL, col90 varchar(40)NOTNULL, col91 varchar(40)NOTNULL, col92 varchar(40)NOTNULL, col93 varchar(40)NOTNULL, col94 varchar(40)NOTNULL, col95 varchar(40)NOTNULL, col96 varchar(40)NOTNULL, col97 varchar(40)NOTNULL, col98 varchar(40)NOTNULL, col99 varchar(40)NOTNULL, col100 varchar(40)NOTNULL, col101 varchar(40)NOTNULL, col102 varchar(40)NOTNULL, col103 varchar(40)NOTNULL, col104 varchar(40)NOTNULL, col105 varchar(40)NOTNULL, col106 varchar(40)NOTNULL, col107 varchar(40)NOTNULL, col108 varchar(40)NOTNULL, col109 varchar(40)NOTNULL, col110 varchar(40)NOTNULL, col111 varchar(40)NOTNULL, col112 varchar(40)NOTNULL, col113 varchar(40)NOTNULL, col114 varchar(40)NOTNULL, col115 varchar(40)NOTNULL, col116 varchar(40)NOTNULL, col117 varchar(40)NOTNULL, col118 varchar(40)NOTNULL, col119 varchar(40)NOTNULL, col120 varchar(40)NOTNULL, col121 varchar(40)NOTNULL, col122 varchar(40)NOTNULL, col123 varchar(40)NOTNULL, col124 varchar(40)NOTNULL, col125 varchar(40)NOTNULL, col126 varchar(40)NOTNULL, col127 varchar(40)NOTNULL, col128 varchar(40)NOTNULL, col129 varchar(40)NOTNULL, col130 varchar(40)NOTNULL, col131 varchar(40)NOTNULL, col132 varchar(40)NOTNULL, col133 varchar(40)NOTNULL, col134 varchar(40)NOTNULL, col135 varchar(40)NOTNULL, col136 varchar(40)NOTNULL, col137 varchar(40)NOTNULL, col138 varchar(40)NOTNULL, col139 varchar(40)NOTNULL, col140 varchar(40)NOTNULL, col141 varchar(40)NOTNULL, col142 varchar(40)NOTNULL, col143 varchar(40)NOTNULL, col144 varchar(40)NOTNULL, col145 varchar(40)NOTNULL, col146 varchar(40)NOTNULL, col147 varchar(40)NOTNULL, col148 varchar(40)NOTNULL, col149 varchar(40)NOTNULL, col150 varchar(40)NOTNULL, col151 varchar(40)NOTNULL, col152 varchar(40)NOTNULL, col153 varchar(40)NOTNULL, col154 varchar(40)NOTNULL, col155 varchar(40)NOTNULL, col156 varchar(40)NOTNULL, col157 varchar(40)NOTNULL, col158 varchar(40)NOTNULL, col159 varchar(40)NOTNULL, col160 varchar(40)NOTNULL, col161 varchar(40)NOTNULL, col162 varchar(40)NOTNULL, col163 varchar(40)NOTNULL, col164 varchar(40)NOTNULL, col165 varchar(40)NOTNULL, col166 varchar(40)NOTNULL, col167 varchar(40)NOTNULL, col168 varchar(40)NOTNULL, col169 varchar(40)NOTNULL, col170 varchar(40)NOTNULL, col171 varchar(40)NOTNULL, col172 varchar(40)NOTNULL, col173 varchar(40)NOTNULL, col174 varchar(40)NOTNULL, col175 varchar(40)NOTNULL, col176 varchar(40)NOTNULL, col177 varchar(40)NOTNULL, col178 varchar(40)NOTNULL, col179 varchar(40)NOTNULL, col180 varchar(40)NOTNULL, col181 varchar(40)NOTNULL, col182 varchar(40)NOTNULL, col183 varchar(40)NOTNULL, col184 varchar(40)NOTNULL, col185 varchar(40)NOTNULL, col186 varchar(40)NOTNULL, col187 varchar(40)NOTNULL, col188 varchar(40)NOTNULL, col189 varchar(40)NOTNULL, col190 varchar(40)NOTNULL, col191 varchar(40)NOTNULL, col192 varchar(40)NOTNULL, col193 varchar(40)NOTNULL, col194 varchar(40)NOTNULL, col195 varchar(40)NOTNULL, col196 varchar(40)NOTNULL, col197 varchar(40)NOTNULL, col198 varchar(40)NOTNULL, PRIMARY KEY (col1)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
- 插入数据报错:row size too larget > 8126
此限制是innodb 存储引擎限制,在插入数据时报错。限制行的长度为innodb_page 一半略小一点的大小(溢出页不算在内)。
insertinto tab values('0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab1','0cc175b9c0f1b6a831c399e269772661a123fab2','0cc175b9c0f1b6a831c399e269772661a123fab2');
原理说明
首先了弄明白原因,就要先理解此报错由来: ERROR 1118 (42000): Row size too large (> 8126).
首先此报错会在三种情况下产生:
- 开启 innodb_strict_mode 时,在创建,修改表结构等DDL操作时,会就抛出上面的报错。
- 关闭 innodb_strict_mode时,在创建,修改表结构等DDL操作时,会就抛出 Warning Row size too large (> 8126). 的警告,但是操作会成功。
- 无论 innodb_strict_mode 是否开启,在执行DML 操作时,只要Innodb 无法存储行数据,就会抛 ERROR 的报错。
innodb 行限制说明:限制大小 innodb_page_size 一半略小一点。限制大小不包含 overflow pages。
分析业务报错的原因
- 首先分析SQL,可以得知在使用 order by 时会生成临时表。这就会给报错提供了机会。
- 当时关闭了 innodb_strict_mode。这点可以通过 mysql error log 得到验证。如截图,只是警告,说明创建临时表是成功的。
- 那问题就得到定位了,符合报错原理中的,第三点,在插入数据时报错。同时插入数据报错不会写入error log。
- 通过整体的分析,也可以得出结论,不同的实例数据应该是不一样的,导致行数据量上的差距,就可以得最初所提到的结果。
解决方案
- 调整innodb_page_size 大小,可以提高行的限制,但是在存量实例上,肯定是不适用的。只有新建mysql 时才能更改innodb_page_size。RDS 是不支持修改的。
- 就是拆分表,将很多列的表,拆分少列的表。
- 修改表结构,将一些数据大的表调整为TEXT、BLOB、JSON等。如下列表类型的最大值。
参考
https://mariadb.com/kb/en/troubleshooting-row-size-too-large-errors-with-innodb/