Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8210119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:57:50+00:00 2026-06-07T09:57:50+00:00

Adding a new column or adding a new index can take hours and days

  • 0

Adding a new column or adding a new index can take hours and days for large innodb tables in MySQL with more than 10 million rows. What is the best way to increase the performance on large innodb tables in these two cases? More memory, tweaking the configuration (for example increasing the sort_buffer_size or innodb_buffer_pool_size), or some kind of trick? Instead of altering a table directly, one could create a new one, change it, and copy the old data the new, like this which is useful for ISAM tables and multiple changes:

CREATE TABLE tablename_tmp LIKE tablename;
ALTER TABLE tablename_tmp ADD fieldname fieldtype;
INSERT INTO tablename_tmp SELECT * FROM tablename;
ALTER TABLE tablename RENAME tablename_old;
ALTER TABLE tablename_tmp RENAME tablename;

Is it recommendable for innodb tables, too, or is it just what the ALTER TABLE command does anway?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:57:52+00:00Added an answer on June 7, 2026 at 9:57 am

    Edit 2016: we’ve recently (August 2016) released gh-ost, modifying my answer to reflect it.

    Today there are several tools which allow you to do online alter table for MySQL. These are:

    • edit 2016: gh-ost: GitHub’s triggerless schema migration tool (disclaimer: I am author of this tool)
    • oak-online-alter-table, as part of the openark-kit (disclaimer: I am author of this tool)
    • pt-online-schema-change, as part of the Percona Toolkit
    • Facebook’s online schema change for MySQL

    Let’s consider the “normal” `ALTER TABLE`:

    A large table will take long time to ALTER. innodb_buffer_pool_size is important, and so are other variables, but on very large table they are all negligible. It just takes time.

    What MySQL does to ALTER a table is to create a new table with new format, copy all rows, then switch over. During this time the table is completely locked.

    Consider your own suggestion:

    It will most probably perform worst of all options. Why is that? Because you’re using an InnoDB table, the INSERT INTO tablename_tmp SELECT * FROM tablename makes for a transaction. a huge transaction. It will create even more load than the normal ALTER TABLE.

    Moreover, you will have to shut down your application at that time so that it does not write (INSERT, DELETE, UPDATE) to your table. If it does – your whole transaction is pointless.

    What the online tools provide

    The tools do not all work alike. However, the basics are shared:

    • They create a “shadow” table with altered schema
    • They create and use triggers to propagate changes from original table to ghost table
    • They slowly copy all the rows from your table to shadow table. They do so in chunks: say, 1,000 rows at a time.
    • They do all the above while you are still able to access and manipulate the original table.
    • When satisfied, they swap the two, using a RENAME.

    The openark-kit tool has been in use for 3.5 years now. The Percona tool is a few months old, but possibly more tested then the former. Facebook’s tool is said to work well for Facebook, but does not provide with a general solution to the average user. I haven’t used it myself.

    Edit 2016: gh-ost is a triggerless solution, which significantly reduces master write-load on the master, decoupling the migration write load from the normal load. It is auditable, controllable, testable. We’ve developed it internally at GitHub and released it as open source; we’re doing all our production migrations via gh-ost today. See more here.

    Each tool has its own limitations, look closely at documentation.

    The conservative way

    The conservative way is to use an Active-Passive Master-Master replication, do the ALTER on the standby (passive) server, then switch roles and do the ALTER again on what used to be the active server, now turned passive. This is also a good option, but requires an additional server, and deeper knowledge of replication.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to ALTER a table by adding a new CLOB column (on Oracle
I want to update a column by adding a new value alongside the old
Clojure structs can be arbitrarily extended, adding new fields. Is it possible to extend
I'm adding a new column, summary , to an existing table. It will contain
When adding a new non-nullable column to a table using code first migrations, it
I have situation where I need to change the order of the columns/adding new
How do I adding new aloha-button in aloha-multisplit-expanded box. (I want the ability to
I have trouble with adding new row to my UITableView. I read similar questions
My GitHub app seems to be adding new SSH keys to github every time
Grabbing delimited dates from database and adding new ones to the list, then want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.