Optimize SQL
Defer deletion to to avoid table locking
Use INSERT ... ON DUPLICATE KEY UPDATE instead of REPLACER