Skip to content

Commit 19f4938

Browse files
committed
Disable innodb_strict_mode when rebuilding tables
If the option was already disabled in the session that created the table, then we need to also disable it when rebuilding the table or the rebuild can fail with: Row size too large. The maximum row size for the used table type, not counting BLOBs, is 8126.
1 parent 4a7cb7d commit 19f4938

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

myhoard/restore_coordinator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,8 @@ def rebuild_tables(self) -> None:
459459
cursor.execute("SET SESSION sql_mode = %s", (lenient_sql_mode,))
460460
self.log.info("Disabling requirement for primary keys during tables rebuild")
461461
cursor.execute("SET SESSION sql_require_primary_key = false")
462+
self.log.info("Disabling innodb strict mode during tables rebuild")
463+
cursor.execute("SET SESSION innodb_strict_mode = false")
462464
cursor.execute(
463465
"SELECT TABLE_SCHEMA,TABLE_NAME,TABLE_ROWS,AVG_ROW_LENGTH"
464466
" FROM INFORMATION_SCHEMA.TABLES WHERE ENGINE='InnoDB'"

test/test_restore_coordinator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ def _restore_coordinator_sequence(
5353
cursor.execute("SET SESSION sql_mode = ''")
5454
cursor.execute("CREATE TABLE bad0 (id INTEGER, data TEXT)")
5555
cursor.execute("CREATE TABLE bad1 (id INTEGER, data DATETIME default '0000-00-00 00:00:00')")
56+
# Tables with compact rows and a row length longer than 8126 bytes raise an error unless strict mode is disabled
57+
cursor.execute("SET SESSION innodb_strict_mode = false")
58+
columns = ", ".join([f"d{i} CHAR(255)" for i in range(40)])
59+
cursor.execute(f"CREATE TABLE bad2 ({columns}) ROW_FORMAT=COMPACT")
5660
cursor.execute("COMMIT")
5761

5862
private_key_pem, public_key_pem = generate_rsa_key_pair()

0 commit comments

Comments
 (0)