2

I run the following SQL Query on a MySQL platform.

Table A is a table which has a single column (primary key) and 25K rows. Table B has several columns and 75K rows.

It takes 20 minutes to execute following query. I will be glad if you could help.

INSERT INTO sometable
SELECT A.PrimaryKeyColumn as keyword, 'SomeText', B.*
FROM A, B
WHERE B.PrimaryKeyColumn = CONCAT(A.PrimaryKeyColumn, B.NotUniqueButIndexedColumn);
noway
  • 2,585
  • 7
  • 41
  • 61

2 Answers2

5

Run the SELECT without the INSERT to see if the problem is with the SELECT or not.

If it is with the SELECT, follow the MySQL documentation explaining how to optimize queries using EXPLAIN.

If the SELECT runs fine but the INSERT takes forever, make sure you don't have a lot of unnecessary indexes on sometable. Beyond that, you may need to do some MySQL tuning and/or OS tuning (e.g., memory or disk performance) to get a measurable performance boost with the INSERT.

Trott
  • 66,479
  • 23
  • 173
  • 212
0

If I get it right you are roughly trying to insert 1.875 Billion records - (which does not match the where clause).

For that 20 minutes doesn't sound too bad....

Min
  • 31
  • 2