What is the best use of this function in Postgres
IS DISTINCT FROM
, doing tests got the same result using COALESCE
but in less time, follow the test:
SELECT COUNT(P.id)
FROM produto P
INNER JOIN cliente CL ON P.id_cliente = CL.id_cliente
WHERE
COALESCE(CL.tp_pessoa,'') <> 'JURIDICA' -- teste com COALESCE, média de 610 ms
(CL.tp_pessoa <> 'JURIDICA' OR CL.tp_pessoa IS NULL) -- teste com OR, média de 668 ms
CL.tp_pessoa IS DISTINCT FROM 'JURIDICA' -- teste com IS DISTINCT FROM, média de 667 ms
OUTRO TESTE:
COALESCE(CL.tp_pessoa,'') <> COALESCE(P.observacao,'') -- teste com IS DISTINCT FROM, média de 940 ms
CL.tp_pessoa IS DISTINCT FROM P.observacao -- teste com '''IS DISTINCT FROM''', média de 930 ms, aqui teve uma leve vantagem da função
In addition to the lower performance, this is a function that is not found in other banks like SQL Server
, another reason not to use it.
By doing another test, where both criteria can be NULL
, IS DISTINCT FROM
had a slight advantage, would this be its use, where else does it apply?