(Mysql) Using Memory engine for 4.3 million row table?
ENGINE=MEMORY is not designed for big tables.  InnoDB is well designed for virtually all use cases; switch to it.

It sounds like you need more than an ENGINE and index type change.  Please provide SHOW CREATE TABLE for the relevant tables, and the statement that is so slow.

set a.id=b.id?? -- By convention, DBAs call the PRIMARY KEY id.  It is very strange to be setting the PK of one table to the PK of another.

Chunking

One approach to UPDATEing 4M rows will less impact is to "chunk" up the problem.  I discuss details here.