In which order Rails does the DB queries <p>In <a href="http://stackoverflow.com/questions/2170001/select-n-objects-randomly-with-condition-in-rails">Select n objects randomly with condition in Rails</a> Anurag kindly proposed this answer to randomly select n posts with votes >= x</p> <pre><code>Post.all(:conditions =&gt; ["votes &gt;= ?", x], :order =&gt; "rand()", :limit =&gt; n) </code></pre> <p>my concern is that the number of posts that have more than x votes is very big.</p> <p>what is the order the DB apply this criteria to the query?</p> <p>Does it </p> <ul> <li>(a) select n posts with votes > x and then randomises it? or</li> <li>(b) select all posts with votes > x and then randomises and then selects the n first posts?</li> <li>(c) other?</li> </ul>