Is there a significant difference in execution, performance or postgresql logic between
SELECT "users".* FROM "users" WHERE ("users"."deleted_at" IS NULL)
and
SELECT "users".* FROM "users" WHERE (NOT ("users"."deleted_at" IS NOT NULL))
Obviously, if hand-written, the first expression is the one I would write (who would intentionally write double negative ?!). But in this case, I use the ruby ββarel library to dynamically create both versions, sort of like:
def generate_query(search_terms, negated=false, users=User) where_clause = arel_for_one_of_many_possible_queries(search_terms) where_clause = where_clause.not if negated users.where(where_clause) end
And for "deleted" search_term where_clause will be arel_table[:deleted_at].not_eq(nil) , but for other search_terms it can be a lot of sentences, including compound sentences and subqueries. By adding .not to the end, isl will always generate second form SQL. I could generate the first form with a special case of my NULL checks and manually generate .eq or .not_eq , depending on the situation, but I want to get a clear advantage in this before making my code more detailed.
source share