CPU is rarely the real bottleneck. It's usually the disk, with the amount of memory available to the buffer pool also being a constraint.
The problem is, the resources required to do an ALTER TABLE
are usually not your actual problem... it's the fact that the table will likely be locked during the operation.
There is no way to de-prioritize queries in MySQL, but if there were, it would likely only prolong your agony as the table-level lock would just persist longer.
Try this:
ALTER TABLE t1
ADD COLUMN c2 BIGINT UNSIGNED NOT NULL AFTER c1,
LOCK=NONE,
ALGORITHM=INPLACE;
If the server won't let you do this -- which should solve your problem -- then the error message should explain the reason.
If the reason is related to foreign keys, yet your ALTER
query will not do anything to disturb the foreign key integrity, you can disable the checks that would prevent you from doing an in place alter without locks.
SET @@FOREIGN_KEY_CHECKS = 0; -- before ALTER
SET @@FOREIGN_KEY_CHECKS = 1; -- after ALTER
This does not disable the foreign key constraints on the table. It only exempts any queries you run from your current connection from the necessity to take steps to avoid violating relational integrity. As long as you aren't doing anything to disturb relational integrity, it is a safe strategy to use, but only when you need it.
https://dev.mysql.com/doc/refman/5.7/en/alter-table.html
Without seeing the actual query and knowing details about the query, nobody can really give you a solid answer. – JakeGould – 2017-10-28T02:21:58.367
Too broad for sure.... you need to increase the performance of the query then consider making the query a stored procedure and then call or execute the proc rather than sending the query from the app, etc. Consider using explain and show status like 'last_query_cost' after the query is run to see how you can increase performance and how the SQL is working behind the scenes, etc.
– Pimp Juice IT – 2017-10-30T11:46:35.647