title: How to optimise a SQL SELECT query for generating a user's newsfeed?
body: <p>I'm currently trying to build a feature to generate a user's newsfeed using the following query from a table of <code>posts</code>. This is the SQL statement we are using:</p>
  
  <pre><code>SELECT *
  FROM "posts" AS "post"
  WHERE "post"."sourceId" IN (...)
  ORDER BY "post"."createdAt" DESC, "post"."timestamp" DESC
  LIMIT 10;
  </code></pre>
  
  <p>The <code>posts</code> table currently has roughly 200K+ rows and likely to grow much larger. My skills in DB performance isn't the strongest, but is there anyway to optimise this query to make it run as fast as possible? I'm assuming it's not enough to add an index on the <code>sourceId</code> column but instead would need a multi column index to also take into account the <code>ORDER BY</code> column.</p>