"Jim C. Nasby" <jnasby@xxxxxxxxxxxxx> writes: > You might try rewriting the coalesces into a row comparison... > WHERE row($4, $5, ...) IS NOT DISTINCT FROM row(interface_id, source_id, ...) That would be notationally nicer, but no help performance-wise; I'm fairly sure that IS DISTINCT doesn't get optimized in any fashion whatsoever :-( What might be worth trying is functional indexes on the COALESCE(foo,0) expressions. Or if possible, consider revising your data schema to avoid using NULLs in a way that requires assuming that NULL = NULL. regards, tom lane