title: Rewrite Where condition using Lateral Join
body: <p>I have a <code>WITH</code> statement which returns a table like followings:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>id</th>
  <th>parent_id</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>null</td>
  </tr>
  <tr>
  <td>3</td>
  <td>2</td>
  </tr>
  <tr>
  <td>4</td>
  <td>null</td>
  </tr>
  <tr>
  <td>5</td>
  <td>4</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>The desired output of my query is where <code>parent_id</code> is <code>null</code> or <code>parent_id</code> is present in the <code>id</code> column:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>id</th>
  <th>parent_id</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>null</td>
  </tr>
  <tr>
  <td>4</td>
  <td>null</td>
  </tr>
  <tr>
  <td>5</td>
  <td>4</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I wrote the following query:</p>
  <pre><code>SELECT * FROM items
  WHERE parent_id IS NULL OR parent_id = ANY(SELECT id from items)
  </code></pre>
  <p>As far I have understood, lateral joins are faster than the <code>ANY</code> operator so my idea was to rewrite the above query using them. I started with:</p>
  <pre><code>SELECT * FROM items i1
  JOIN LATERAL (SELECT * FROM items i2 WHERE i2.parent_id = i1.id ) t ON true
  </code></pre>
  <p>But where do I add the condition to take the items where <code>parent_id</code> is null?</p>