You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Suggestion] Apply simple validation to alter command #1431
tl;dr: It would be nice if the --alter command line arg did some basic validation and threw an error if your SQL starts with ALTER TABLE as that can have unexpected results.
DB: Mariadb 10.6.10
gh-ost: 1.1.5
I ran into an interesting issue today that I think could be prevented with a little input validation in gh-ost. I was adding a modified_time column to an existing table with associated index and used the following flags in my gh-ost command:
gh-ost
--table="exampletable"
--alter="ALTER TABLE exampletable ADD COLUMN modified_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, ADD INDEX i_modified_time (modified_time);"
The command worked by all appearances: it created the new table, I verified that the column and index was created, and then executed the cutover. Shortly we discovered that the new table didn't have any actual data in its indexes, the Cardinality was 0 for all of them including PRIMARY, which made every query crawl. We ended up having to roll back the cutover, which ended up being fairly painful.
Running the same gh-ost command but dropping the ALTER TABLE exampletable from the --alter= flag works correctly, the created table has its indexes populated and the cutover works fine.
Ultimately this is user error, but given that it's an easy mistake to make (especially for someone new at gh-ost) and it's easy to catch, adding a check to the --alter to throw an error if you pass ALTER TABLE to it should be simple to implement and might save someone else a headache and some downtime in the future.
in addition a check that sql do not end with ';'. when the alter statement is end with ';' the -attempt-instant-ddl is failed because the , ALGORITHM=INSTANT will added after the ';' and will failed anytime.
Activity
meiji163 commentedon Nov 7, 2024
Sounds like a reasonable check to add, do you want to open a PR?
ybs-me commentedon Jan 19, 2026
in addition a check that sql do not end with ';'. when the alter statement is end with ';' the
-attempt-instant-ddlis failed because the, ALGORITHM=INSTANTwill added after the ';' and will failed anytime.gh-ost/go/logic/applier.go
Line 207 in cc2dd7f
abhikaddy commentedon May 15, 2026
I'd like to work on this.
drkemp187 commentedon Jul 30, 2026
Opened PR #1744 to reject trailing semicolons on
--alter(and warn on fullALTER TABLEprefix). Happy to adjust based on review.