Make pt-online-schema-change support converting nullable column to NOT NULL
MySQL allows you to change a NULLable column to a NOT NULL (if you provide a DEFAULT) with a simple ALTER TABLE statement.
So If I had a column defined like this:
col15 enum('value1'
I can do the following:
ALTER TABLE my_table MODIFY col15 enum('value1'
and while rebuilding the table MySQL will correctly convert any NULL values into 'value1'.
I tried to run pt-online-
pt-online-
Altering `my_db`
Creating new table...
Created new table my_db._MyTable_new OK.
Altering new table...
Altered `my_db`
Creating triggers...
Created triggers OK.
Copying approximately 34327495 rows...
Dropping triggers...
Dropped triggers OK.
Dropping new table...
Dropped new table OK.
`my_db`.`MyTable` was not altered.
Error copying rows from `my_db`.`MyTable` to `my_db`
Level: Warning
Code: 1048
Message: Column 'col15' cannot be null Query: INSERT LOW_PRIORITY IGNORE INTO `my_db`
So the new table has a NOT NULL definition, but the insert statement (to copy) does not see if the value it would insert is NULL and therefore insert the DEFAULT value.
Changing that behaviour and recognising that edge case would be really nice.
The column concerned is not indexed, so I have to manually go through the whole table to first change the NULL value to 'value1', and slowly enough to not affect replication. That's precisely what pt-online-
Note: this is with percona-
This probably needs 2 changes:
1. the copy/insert statements wrap some sort of IF(colX IS NULL, <new default>, colX) in the appropriate columns,
2. the triggers should do the same thing.
Would be a nice feature to see.
Blueprint information
- Status:
- Not started
- Approver:
- None
- Priority:
- Undefined
- Drafter:
- None
- Direction:
- Needs approval
- Assignee:
- None
- Definition:
- New
- Series goal:
- None
- Implementation:
- Unknown
- Milestone target:
- None
- Started by
- Completed by