title: SQL query performance
body: <p>I am writing a script to migrate my users table.
  So basically, I've 3 db tables : events, users, newusers. The users table is meant to be replaced by the newusers table and will be dropped later. The newusers table has a column with the oldusers id (PK) value.</p>
  
  <p>The events2 table has 2 FKs : 1 for users, 1 for newusers. 
  I've already written the part that migrates records users to new users, where I am struggling is to update the FK in the events 2 table. </p>
  
  <p>I've written the following:</p>
  
  <pre><code>update events2
   set newusersid = newuser.id
   from events2 e
   inner join newusers newuser on newuser.olduserid = e.userid;
  </code></pre>
  
  <p>but it takes very long time to execute. Is there an improved way </p>
  
  <p>One of the reason for the migration is that we wanted to change the id value in the newusers table so I can't re-use the same PK values for the corresponding users records.</p>
  
  <p>thanks for your help</p>
  
  <p>N.</p>