问题
I'm seeing the following error in my MySQL logs:
[Warning] InnoDB: Cannot add field `wd_field_ft_95_240` in table `tmp`.`#sql_1_0` because after adding it, the row size is 8155 which is greater than maximum allowed size (8126) for a record on index leaf page.
Is this tmp
database some kind of internal MySQL structure? Is this something I need to care about?
回答1:
Some MySQL queries create internal temporary tables to hold partial results.
As of MySQL 5.7.6, the default storage engine for internal temporary tables is InnoDB, which has a pretty small limit on row size, as you can see (though BLOB/TEXT columns can go beyond that limit).
You can go back to the old pre-5.7 default storage engine for internal temporary tables:
internal_tmp_disk_storage_engine=MyISAM
This is the workaround mentioned in this bug: "Bug #77398 row size too large in mysql 5.7 query"
回答2:
Please show us SHOW CREATE TABLE
. I'll bet you have lots of columns declared VARCHAR(255)
. I'll also bet that most of those columns will never need 255 characters. Shrink them.
If that does not suffice, change a few to be TEXT
; the data will be stored off-page and not impact the 8K limit as badly.
If that does not suffice, we can talk about "vertical partitioning". At that point, please show us the query that precipitated the error. If you are doing SELECT *
, change it to specify only the columns you really need.
Do not use MyISAM, that is a step backward. And it is going away in the next version, so a future migration will be hurt.
来源:https://stackoverflow.com/questions/41053663/cannot-add-field-row-size-greater-than-maximum-allowed-size