Improve speed of a JOIN in MySQL

Posted by ran2 on Stack Overflow See other posts from Stack Overflow or by ran2
Published on 2010-06-16T09:19:53Z Indexed on 2010/06/16 9:22 UTC
Read the original article Hit count: 271

Filed under:
|

Dear all,

I know there a similar threads around, but this is really the first time I realize that query speed might affect me - so it´s not that easy for me to really make the transfer from other folks problems.

That being said I have using the following query successfully with smaller data, but if I use it on what are mildly large tables (about 120,000 records). I am waiting for hours.

INSERT INTO anothertable (id,someint1,someint1,somevarchar1,somevarchar1) SELECT DISTINCT md.id,md.someint1,md.someint1,md.somevarchar1,pd.somevarchar1 from table1 AS md JOIN table2 AS pd ON (md.id = pd.id);

Tables 1 and 2 contain about 120,000 records. The query has been running for almost 2 hours right now. Is this normal? Do I just have to wait. I really have no idea, but I am pretty sure that one could do it better since it´s my very first try.

I read about indexing, but dont know yet what to index in my case?

Thanks for any suggestions - feel free to point my to the very beginners guides !

best

matt

© Stack Overflow or respective owner

Related posts about mysql

Related posts about speed