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 1073601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:00:45+00:00 2026-05-16T21:00:45+00:00

I have a mysql database with a particular table with a little over 6

  • 0

I have a mysql database with a particular table with a little over 6 million rows and no indexes. A simple query such as SELECT ... FROM log ORDER BY log_date ASC will take an unacceptable amount of time. I obviously need to add indexes to the table, but am unsure of the most efficient way to go about this.

1) My first option would be to issue ALTER TABLE log ADD INDEX log_date, but I’m not sure how long it would take… would it take approximately the same length of time as the previous query? If so, this is unacceptable.

2) My second option would be to export the table, TRUNCATE the table, issue the ALTER TABLE statement, and then re-import the table data. I’m not sure how long it would take to re-import the data, and am concerned as to what would happen if the system tries to write rows to the table during the process.

Is anyone able to offer insight into the best way to index a moderately large table in a production system without causing too much grief?

  • 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-05-16T21:00:46+00:00Added an answer on May 16, 2026 at 9:00 pm

    As far as I know, option 2 will actually cause you more hassle than option 1, not just because it involves more shuffling about of data but because importing the data to the table and building the index at the same time is going to take longer than just importing the data and then building the entire index.

    Think about it: if MySQL is importing the table data and building the index at the same time, then at every row inserted it not only has to insert that row but also insert a row into the index. That’s going to be slower than just building the index outright from already-present data. On the other hand, if you restore the data in its entirety and then build the index, you’re back to option 1 but you’ve pointlessly emptied and refilled the table in the meantime.

    I don’t think you’re going to get better performance than you can get just by biting the bullet and issuing the ALTER TABLE command. Perhaps you can schedule the command to be run at a time when usage is lower, like the middle of the night??

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

Sidebar

Related Questions

I have a table in MySQL database from which I want to select a
I have a MySQL database, and a particular table in that database will need
I have a data table populated from a MySQL database via PHP. The first
I have a table linked to my mySQL database. I have a particular field
I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
I have a MySQL database where the table was set up to store the
I have a MySQL database table called Participant that looks something like this: (idParticipant)
Let's say I have a MySQL database with 3 tables: table 1: Persons, with
I have an interesting problem here. I have a MySql database table that has
I have a mysql database on which I create users, and grant them select,

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.