1

I want to run 3 ALTER queries with pt-online-schema-change tool:

--alter "ADD INDEX userid_sid_ts_fid (user_id, scorecard_id, timestamp, factor_id), DROP INDEX uidts, RENAME INDEX userid_sid_ts_fid to uidts"

However I face this error:

Error altering new table `*****`.`_scoring_basis_new`: DBD::mysql::db do failed: Key 'userid_sid_ts_fid' doesn't exist in table '_scoring_basis_new'

So it looks like is trying to run these 3 queries asynchronously rather than 1 by 1. How can I prevent that?

1
  • If you have further questions, be sure to include SHOW CREATE TABLE.
    – Rick James
    Commented Dec 15, 2022 at 18:24

1 Answer 1

3

Try doing that like this

--alter "DROP INDEX uidts,ADD INDEX uidts (user_id, scorecard_id, timestamp, factor_id)"

This should work because I have seen pt-duplicate-key-checker present ALTER TABLE commands dropping a single column out of an index by dropping and redefining like that.

To verify this, make an empty copy of the table and run

CREATE TABLE mycopyoftable LIKE mytable;
ALTER TABLE mycopyoftable
    DROP INDEX uidts
   ,ADD INDEX uidts (user_id, scorecard_id, timestamp, factor_id)
;
SHOW CREATE TABLE mycopyoftable \G

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.