title: SQL JOIN with WHERE clause on multiple tables slowdown
body: <p>The following query is fast:</p>
  
  <pre><code>SELECT a.id, b.id, c.id
  FROM a
  FULL OUTER JOIN b ON a.id = b.id
  FULL OUTER JOIN c ON a.id = c.id
  WHERE a.some &gt; 5 AND a.thing &lt; 10
  </code></pre>
  
  <p>however doing the where clause on multiple tables is causing about a 10 million X performance penalty in my dataset:</p>
  
  <pre><code>SELECT a.id, b.id, c.id
  FROM a
  FULL OUTER JOIN b ON a.id = b.id
  FULL OUTER JOIN c ON a.id = c.id
  WHERE (a.some &gt; 5 AND a.thing &lt; 10)
      OR (b.some &gt; 5 AND b.thing &lt; 10)
      OR (c.some &gt; 5 AND c.thing &lt; 10)
  </code></pre>
  
  <p>How can I improve the query to be performant? Thank you!</p>
  
  <p>EDIT:</p>
  
  <p>here's the sql explain on the actual query (table names are a bit different):</p>
  
  <pre><code>SELECT
      ohh.hour
  FROM org_hour_host ohh
  FULL OUTER JOIN org_hour_timeseries ohs ON ohh.org_id = ohs.org_id
  FULL OUTER JOIN org_hour_vs_host ohah ON ohh.org_id = ohah.org_id
  WHERE (ohh.org_id IN (10) OR ohs.org_id IN (10) OR ohah.org_id IN (10))
  
  XN Hash Full Join DS_DIST_OUTER  (cost=6682944.40..234919986923528960.00 rows=1934276754413 width=8)
    Outer Dist Key: "outer".org_id
    Hash Cond: ("outer".org_id = "inner".org_id)
    Filter: (("inner".org_id = 10) OR ("outer".org_id = 10) OR ("outer".org_id = 10))
    -&gt;  XN Hash Full Join DS_DIST_NONE  (cost=3050316.80..38694799792.93 rows=1934276754413 width=16)
          Hash Cond: ("outer".org_id = "inner".org_id)
          -&gt;  XN Seq Scan on org_hour_host ohh  (cost=0.00..3130270.08 rows=313027008 width=12)
          -&gt;  XN Hash  (cost=2440253.44..2440253.44 rows=244025344 width=4)
                -&gt;  XN Seq Scan on org_hour_timeseries ohs  (cost=0.00..2440253.44 rows=244025344 width=4)
    -&gt;  XN Hash  (cost=2906102.08..2906102.08 rows=290610208 width=4)
          -&gt;  XN Seq Scan on org_hour_vs_host ohah  (cost=0.00..2906102.08 rows=290610208 width=4)
  (11 rows)
  
  
  
  
  
  SELECT
      ohh.hour
  FROM org_hour_host ohh
  FULL OUTER JOIN org_hour_timeseries ohs ON ohh.org_id = ohs.org_id
  FULL OUTER JOIN org_hour_vs_host ohah ON ohh.org_id = ohah.org_id
  WHERE ohh.org_id IN (10)
  
  XN Merge Left Join DS_DIST_NONE  (cost=0.00..6350089909.81 rows=634262751009 width=8)
    Merge Cond: ("outer".org_id = "inner".org_id)
    -&gt;  XN Merge Left Join DS_DIST_NONE  (cost=0.00..3667829.03 rows=64777233 width=12)
          Merge Cond: ("outer".org_id = "inner".org_id)
          -&gt;  XN Seq Scan on org_hour_host ohh  (cost=0.00..131.03 rows=10483 width=12)
                Filter: (org_id = 10)
          -&gt;  XN Seq Scan on org_hour_timeseries ohs  (cost=0.00..2440253.44 rows=244025344 width=4)
    -&gt;  XN Seq Scan on org_hour_vs_host ohah  (cost=0.00..2906102.08 rows=290610208 width=4)
  (8 rows)
  </code></pre>