Origins

To tell you true,
I don’t know if there’s anything here.

But I know that if precedents bear any weight in the matter,
we’ve already come so far from nearly nothing at all.

Two souls, sparked from the very same stardust.

Mendoza

I imagine that the lowly soil, if inquired,
would lament its apparently arbitrary plight.
For it knows nothing of weather patterns or cold fronts,
and cannot well track the passage of seasons and time.

The soil only knows that it loves the rain.
It only feels how completely its thirst can be quenched.
It only remembers how very soon after the showers pass
I once again grow parched, waiting eagerly for her return.

Am I allowed to miss someone who doesn’t even exist? Not any more, anyway.

How to Quickly Add Indices to Large MySQL Tables

Whenever a MySQL query contains a WHERE conditional, the database server must find all the matching rows before it can execute any operations.  In order to optimize this matching, a database administrator might define an index on any columns he or she knows will be used more frequently in WHERE conditions.

As an analogy, imagine if you had an unorganized stack of business cards, and someone asked you to find Jon Smith’s telephone number.  You might have to look through every single business card in order to find Jon Smith, because he could be anywhere in the stack.  On the other hand, if you sorted the cards in alphabetical order by last name, you would be able to jump much more quickly to where Jon Smith might be found.  Furthermore, every time you receive a new business card, you could quickly insert it into its proper place (based on last name) and be sure that future lookups would continue to be quick.  This is the basic idea of MySQL indices.

Now, the easiest time to define the ordering is before we’ve even received a single card.  But let’s say we’ve collected a million cards before realizing that we’d also like to be able to index business contacts by their company.  It would take a long time to organize all that data in the proper order!

Fortunately, there’s a snazzy little trick for quickly adding indices to large MySQL tables.  The basic concept is to create a new table, add the column indices you want, and then import the data from the existing table into the new one.  Here’s how it goes in MySQL:


# Create a new table with the same characteristics as the old table
CREATE TABLE new_table LIKE old_table;

# Add any indices you'd like to the new table
ALTER TABLE new_table ADD INDEX column_id (column_id);

# Copy data over from the old table to the new table
# Note that the columns must be the same for this to work
INSERT INTO new_table SELECT * FROM old_table;

# Delete the old table and rename the new table
DROP TABLE old_table;
ALTER TABLE new_table RENAME TO old_table;