title: Postgres SQL slow when using OR statement
body: <p>I have a query that take 12 seconds (journal table 1.2m rows), the root cause is below</p>
  
  <pre><code>select 1
  from
     myTable myTable
     join myJournal Journal on (Journal.status=0 and myTable.id = Journal.myTableId)
     join arrival Arrival on (myTable.id = Arrival.myTableId)
     join calc Calc on (myTable.id = Calculated.myTableId)
     join ms ms on (Parent.id = ms.myTableId)   
     join perf Perf on (myTable.id = Perf.myTableId)
     join ref Ref on (myTable.id = Ref.myTableId)
  where
      ((myTable.name like 'cheese%' or 
       Journal.algorithm like 'cheese%' or --if this is removed, its fine &lt;1sec
       myTable.client like 'cheese%' or 
       myTable.something like 'cheese%'))
  </code></pre>
  
  <p>However the journal table performs ok. Doing  </p>
  
  <pre><code>select * from myJournal where algorithm like 'cheese%' --takes &lt; 1 sec.
  </code></pre>
  
  <p>The query also performs fine, if I remove four of the joins (that are not used in the where clause).  </p>
  
  <p>When I join on more than 3 tables the performance degrades dramatically/exponentially.</p>