title: Oracle slow join with view
body: <p>I'm using the following query to find a monetary transaction for a person.</p>
  <pre class="lang-sql prettyprint-override"><code>SELECT
    PERSON.NAME,
    MONETARY_TRANSACTION.DESCRIPTION
  FROM PERSON
  LEFT JOIN MONETARY_TRANSACTION
    ON PERSON.ID = MONETARY_TRANSACTION.PERSON_ID
  WHERE PERSON.ID = 5
  AND ROWNUM &lt;= 1
  </code></pre>
  <p><em>1.5 min.</em></p>
  <p>If I run them seperately:</p>
  <pre class="lang-sql prettyprint-override"><code>SELECT NAME FROM PERSON WHERE PERSON.ID = 5 AND ROWNUM &lt;=1;
  </code></pre>
  <p><em>0.158 sec.</em></p>
  <pre class="lang-sql prettyprint-override"><code>SELECT DESCRIPTION FROM MONETARY_TRANSACTION WHERE PERSON_ID = 5 AND ROWNUM &lt;= 1;
  </code></pre>
  <p><em>5.423 sec.</em></p>
  <p>I'm guessing it's taking so long because the join happens before the where clause and each join the view gets recalculated (2.8 million people rows).</p>
  <p>The view is MONETARY_TRANSACTION</p>