title: Index on multiple columns in Ruby on Rails
body: <p>I'm implementing functionality to track which articles a user has read.</p>
  
  <pre><code>  create_table "article", :force =&gt; true do |t|
      t.string   "title"
      t.text     "content"
    end
  </code></pre>
  
  <p>This is my migration so far:</p>
  
  <pre><code>create_table :user_views do |t|
    t.integer :user_id
    t.integer :article_id
  end
  </code></pre>
  
  <p>The user_views table will always be queried to look for both columns, never only one. My question is how my index should look like. Is there a difference in the order of these tables, should there be some more options to it or whatever. My target DB is Postgres.</p>
  
  <pre><code>add_index(:user_views, [:article_id, :user_id])
  </code></pre>
  
  <p>Thanks.</p>
  
  <p>UPDATE:<br>
  Because only one row containing the same values in both columns can exist (since in knowing if user_id HAS read article_id), should I consider the :unique option? If I'm not mistaken that means I don't have to do any checking on my own and simply make an insert every time a user visits an article.</p>