title: What’s most efficient way to query a LEFT JOIN with tons of data with Doctrine 2 DQL
body: <p>I have an entity “coin” linked with a oneToMany on prices. Prices is updated every minute and has millions of entries.</p>
  
  <p>What I’m trying to achieve is a DQL query that will grab the last price to date.</p>
  
  <p>Right now I see 2 ways to do it and I’m wondering which one is best in term of performance:</p>
  
  <p>I could look for prices in the DB with ‘prices’.’lastupdated’ equal to the last update.</p>
  
  <p>OR I could grab the last 100 price ids (we update 100 coins every minute and add 100 new rows in the Database) with a LIMIT 100 and ORDER BY ‘id’ DESC on my left join.
  I know it’s tricky to use LIMIT on a LEFT JOIN with doctrine but I found a solution here:
  <a href="https://stackoverflow.com/questions/26401620/how-to-limit-results-of-a-left-join-with-doctrine-dql">How to limit results of a left-join with Doctrine (DQL)</a>
  and here: <a href="https://www.colinodell.com/blog/201703/limiting-subqueries-doctrine-2-dql" rel="nofollow noreferrer">https://www.colinodell.com/blog/201703/limiting-subqueries-doctrine-2-dql</a></p>
  
  <p>I’m wondering what will take the least amount of ressources to execute that query.</p>
  
  <p>Of course I’m using getArrayResults() and am using partials and doctrine cache.</p>
  
  <p>What is your opinion on that?
  Thanks!</p>