MySql LOAD DATA with subquery performance issue
This is probably due to the fact that memory tables by default use a hash index instead of a btree index. Read more about it here.
Or maybe you don't use an index at all in your memory table?
A pretty similar performance problem is described in this blog post: Performance gotcha of MySQL memory tables
If you don't have an index on the id column, add one (btree!)

The MEMORY storage engine supports both HASH and BTREE indexes. You can specify one or the other for a given index by adding a USING clause as shown here:
   CREATE TABLE lookup
       (id INT, INDEX USING HASH (id))
       ENGINE = MEMORY;
   CREATE TABLE lookup
       (id INT, INDEX USING BTREE (id))
       ENGINE = MEMORY;


If you already have an index on that column, check with
show indexes from table_2;

of what index_type your index is. Convert to btree if necessary.