nate berkopec
- 1y ·
-
Public·
-
mastodon.social
In ActiveRecord, "exists?" is faster than "count > 0".
exists? generates sql like SELECT 1 AS ONE WHERE ... LIMIT 1, which means the DB can stop as soon as it finds one row.
count generates a COUNT query, which means every row must be checked and summed. Much slower!