Subject Re: [firebird-support] Query too slow
Author Ann W. Harrison
Alex Castillo wrote:
>
> SELECT ....
> WHERE i.CLAVEUNICA NOT IN (
> SELECT DISTINCT d.CLAVEUNICA
> FROM DOCUMENTOSALIDA doc
> JOIN DETALLECONTRATOSALIDA d ON DOC.IDDOCUMENTOSALIDA=D.IDDOCUMENTOSALIDA
> WHERE doc.TIPOSALIDA <> 'T'
> )
> AND (i.SALDOINICIAL + i.ENTRADAS - i.SALIDAS)= 0
>
> I've solved the slowness using a NOT EXISTS clause, but I wanted to tell you experts in order to analize the "why".
>

There is a subtle difference in NULL handling between NOT IN and
NOT EXISTS. The result is that NOT IN can not use indexes that
NOT EXISTS can.

Good luck,

Ann