bitscn.com起因:
团购开发报告说更新时出错。
更新sql如下:
update table_name d set d.column_name='aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
where d.id=100976;
报错信息如下:
error code : 1118
row size too large. the maximum row size for the used table type, not counting blobs, is 8126. you have to change some columns to text or blobs
疑惑:
更新字段只涉及 column_name字段,且该字段是text类型。
个人之前理解是:
text的内容在 dynamic的table format下是存在off-page中的,不会占用row size的计算。
barracuda 对应row_format ( dynamic, compress) ,其中dynamic下text的所有内容都是off-page存放的 (点击查看)
antelope 对应row_format (compact, redundant),其中compact下的text是存786b在row中,超过部分存在off-page
而服务器配置是 innodb_file_format = barracuda
照理说所有table用的都是 dynamic 结构。
但是! 原因如下,摘自文档:
to preserve compatibility with those prior versions, tables created with the innodb plugin use the prefix format, unless one of row_format=dynamic or row_format=compressed is specified (or implied) on the create table command.
也就是说,建表时不显示指定 row_format = dynamic ,即使 innodb_file_format = barracuda 表的row-format还是 compact
所以总结为一句话就是:如果某个表的text字段很多建议建表时加上 row_format = dynamic
当然,回过头来mysql的报错也是有误导性的,bug库中也对confirm了这个bug(点击查看),并在5.1.61中优化了报错提示。bitscn.com