Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>when you use a function on the column:</p> <pre><code>date(datepif) &gt; '01/06/2009' AND date(datepif) &lt;= '01/06/2010' </code></pre> <p>an index will NOT be used. Try something like this</p> <pre><code>datepif &gt; someconversionhere('01/06/2009') AND datepif &lt;= someconversionhere('01/06/2010') </code></pre> <p>Use inner joins too. There isn't any info in the question to indicate table size or if there is an index or not, so this is a guess and should work best if there are many more rows in billspaid for the date range vs rows that match the joining tables for r.controlno = 1234567, which I suspect is the case:</p> <pre><code>SELECT COALESCE(b1.billyr,b2.billyr) AS billyr ,COALESCE(b1.billno,b2.billno) AS billno ,COALESCE(b1.propacct,b2.propacct) AS propacct ,COALESCE(b1.vinid,b2.vinid) AS vinid ,COALESCE(b1.taxpaid,b2.taxpaid) AS taxpaid ,COALESCE(b1.duedate,b2.duedate) AS duedate ,COALESCE(b1.datepif,b2.datepif) AS datepif ,COALESCE(b1.propdesc,b2.propdesc) AS propdesc FROM rtadba.reasacct r INNER JOIN cwdba.txpyaccts a ON r.accountno=t.accountno INNER JOIN cwdba.txpytaxid t ON a.taxpayerno=t.taxpayerno LEFT OUTER JOIN trcdba.billspaid b1 ON t.custno=b1.custno AND b1.datepif &gt; someconversionhere('01/06/2009') AND b1.datepif &lt;= someconversionhere('01/06/2010') LEFT OUTER JOIN trcdba.billspaid b2 ON t.custno2=b2.custno AND b2.datepif &gt; someconversionhere('01/06/2009') AND b2.datepif &lt;= someconversionhere('01/06/2010') WHERE r.controlno = 1234567 AND COALESCE(b1.custno,b2.custno) IS NOT NULL </code></pre> <p>create an index for each of these:</p> <pre><code>rtadba.reasacct.controlno and cover on accountno cwdba.txpyaccts.accountno and cover on taxpayerno cwdba.txpytaxid.taxpayerno and cover on custno trcdba.billspaid.custno +datepif trcdba.billspaid.custno2 +datepif </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload