Hi,
I'm refactoring some old code and stumbled upon this named query (It's using hibernate on top of mysql):
delete F from
foo F
inner join user DU on F.user_id = DU.id
where
(COALESCE(:userAlternateId,null) is null or DU.alternate_id like :userAlternateId )
and ( COALESCE(:fooId,null) is null or F.foo_id like :fooId )
and (
( COALESCE(:fromUpdated,null) is null or F.updated_at>=:fromUpdated )
and ( COALESCE(:toUpdated,null) is null or F.updated_at<=:toUpdated )
)
I don't understand why this COALESCE is being used in this fashion: COALESCE(:userAlternateId,null) is null
is this a performance hack or does it make the query database independent or ...?
btw userAlternateId is a string/varchar, other id's are longs and from-to are dates