Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a index while a SQL statement is running? 1

Status
Not open for further replies.

Zych

IS-IT--Management
Apr 3, 2003
313
US
What would happen if I added a index into a table that was in use by another SQL statement? The statement has been running all night and I just realized that it would be faster if I indexed the main field in a table I am referencing.

Here is some background. I have a table with names and phone numbers. I have another table that has an area code field, a number field and a phone field (this field combines the area code and number into one phone number.) The phone numbers in both fields are in the same format as a char10 format. I am trying to dedupe one list from the other into a third table. The statement has worked before but these tables are on the large side. (The first is about a million and the second with the three fields is about 3.5 million.) I was thinking that if I indexed the phone field of the second table it would run faster but I don't want to start over again since I have no idea how long this will take. I am still a newbie to MySQL and SQL in general and I don't know what would happen if I added the index to the second table from a second machine.

I hope I made sense.

Thanks,

Zych
 
Kill the job and index the tables.

If you stick the key word EXPLAIN before your select statement and run it it will tell you how it will do the query. In general you should work out what the query will do before running a query and in most cases this means using index's.

This might help
 
Sorry forgot adding an index after the query has started will not help - the query optimiser has already determined how to do the query and cannot change its mind once it has started.
 
Thanks for the info. I actually did restart it and it ran much much much faster when it was indexed. Also thanks for the extra info about the EXPLAIN. It will come in handy in the future.

- Zych
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top