title: Understanding EXPLAIN ANALYZE query plan
body: <p>I have the following output</p>
  
  <pre><code>Merge Join (cost=31843.55..32194.92 rows=30215 width=36)
             (actual time=496.720..510.071 rows=38381 loops=1)
    Merge Cond: (movies.year = people.birth_year)
    -&gt; Sort (cost=9905.45..9918.62 rows=5268 width=22)
       (actual time=151.781..152.690 rows=5634 loops=1) // &lt;---- !!!! LOOKING HERE !!!!
         Sort Key: movies.year
         Sort Method: quicksort Memory: 729kB
       -&gt; Seq Scan on movies (cost=0.00..9579.81 rows=5268 width=22)
          (actual time=145.826..149.340 rows=7640 loops=1) // &lt;---- !!!! LOOKING HERE !!!!
            Filter: (title &gt; ’y’::text)
            Rows Removed by Filter: 456425 // &lt;---- !!!! LOOKING HERE !!!!
    -&gt; Sort (cost=21936.87..21953.89 rows=6808 width=18)
       (actual time=344.918..347.980 rows=38465 loops=1)
         Sort Key: people.birth_year
         Sort Method: quicksort Memory: 423kB
       -&gt; Seq Scan on people (cost=0.00..21503.44 rows=6808 width=18)
          (actual time=341.883..343.847 rows=4151 loops=1)
            Filter: (name &gt; ’zeke’::text)
            Rows Removed by Filter: 1099324
  Planning time: 0.450 ms
  Execution time: 511.988 ms
  </code></pre>
  
  <p>I care to know the selectivity estimate for <code>title &gt; 'y'</code>.<br>
  This plan says <code>Rows Removed by Filter: 456425</code>.</p>
  
  <p><strong>The total rows that we have is</strong> <code>464065</code>.</p>
  
  <p>Since <code>456425</code> rows were removed by the filter, we selected 
  <code>464065 - 456425 = 7640</code> rows which is mentioned in the <code>Seq Scan</code> line.</p>
  
  <p>But how come the topmost <code>Sort</code> shows actual rows numbers as <code>5634</code>? Where is it coming from?</p>
  
  <p>I thought it might be related to the second sort operation, but those are completely different branches.</p>
  
  <p>Is there any way to know if tables fit in memory or not? Plan indicate how much memory is being used, but I do not see them indicating whether all this fits in memory or not.</p>