title: How to index polymorphic table in rails with not unique "association_type" and "association_id"
body: <p>I have a polymorphic table called "Votes", where has votes from Answers and Questions.</p>
  
  <p>Votes</p>
  
  <pre><code>user_id     voteable_id    voteable_type      value
  
     1             2            Answer            1
     2             2            Answer            1
  </code></pre>
  
  <p>In this case, the answer with id = 2 has two votes up.</p>
  
  <p>The question is: <strong>How to index this table?</strong></p>
  
  <p><strong>First approach:</strong></p>
  
  <pre><code>add_index :votes, [:voteable_id, :voteable_type]
  </code></pre>
  
  <p>This will not work because duplicate key value will violates unique constraint</p>
  
  <p><strong>Second approach:</strong></p>
  
  <pre><code> add_index :votes, :voteable_id, 
   add_index :votes, :voteable_type
  </code></pre>
  
  <p>This one I guess will not have much performance because of the composite queries for id and type at the same time.</p>
  
  <p><strong>Third approach:</strong></p>
  
  <pre><code>add_index :votes, [:user_id, :voteable_id, :voteable_type]
  </code></pre>
  
  <p>Is this last one a good one? Are three columns to be indexed too much?</p>
  
  <p>Thanks</p>