title: Update using join on big table - performance tips?
body: <p>Been struggling with this update, that never finishes</p>
  <pre><code>update votings v
  set voter_id = (select pv.number from voters pv WHERE pv.person_id = v.person_id);
  </code></pre>
  <p>Table being currently has 96M records</p>
  <pre><code>select count(0) from votings;
    count   
  ----------
   96575239
  (1 registro)
  </code></pre>
  <p>Update apparently is using index</p>
  <pre><code>explain update votings v                             
  set voter_id = (select pv.number from voters pv WHERE pv.rl_person_id = v.person_id);
                                                      QUERY PLAN                                                     
  -------------------------------------------------------------------------------------------------------------------
   Update on votings v  (cost=0.00..788637465.40 rows=91339856 width=1671)
     -&gt;  Seq Scan on votings v  (cost=0.00..788637465.40 rows=91339856 width=1671)
           SubPlan 1
             -&gt;  Index Scan using idx_voter_rl_person_id on voters pv  (cost=0.56..8.58 rows=1 width=9)
                   Index Cond: (rl_person_id = v.person_id)
  (5 registros)
  
  </code></pre>
  <p>Here are the indexes I have for votings</p>
  <pre><code>Índices:
      &quot;votings_pkey&quot; PRIMARY KEY, btree (id)
      &quot;votings_election_id_voter_id_key&quot; UNIQUE CONSTRAINT, btree (election_id, person_id)
      &quot;votings_external_id_external_source_key&quot; UNIQUE CONSTRAINT, btree (external_id, external_source)
      &quot;idx_votings_updated_at&quot; btree (updated_at DESC)
      &quot;idx_votings_vote_party&quot; btree (vote_party)
      &quot;idx_votings_vote_state_vote_party&quot; btree (vote_state, vote_party)
      &quot;idx_votings_voter_id&quot; btree (person_id)
  Restrições de chave estrangeira:
      &quot;votings_election_id_fkey&quot; FOREIGN KEY (election_id) REFERENCES elections(id)
      &quot;votings_voter_id_fkey&quot; FOREIGN KEY (person_id) REFERENCES people_all(id)
  </code></pre>
  <p>Guys, any ideia who plays the biggest part on the update running slowly? the number of rows or the join being used?</p>