rails/rails — pull request #12533 by szimek (2013-10-14 18:05:06+00:00)
Title: In Relation#empty? use #exists? instead of #count.

I opened almost exactly the same issue about 2 years ago, but for collections (https://github.com/rails/rails/issues/3179). This time for `Relation` and with pull request!

Right now

```ruby
User.all.empty?
```
generates

```sql
SELECT COUNT(*) FROM `users`
```

query if records are not loaded. After this change it will call `exists?` and thus generate

```sql
SELECT 1 AS one FROM `users` LIMIT 1
```
which should execute faster, especially if there are some additional conditions.

There are no tests, because I'm not sure how to write one for it, but if anyone has some suggestions, I'll add one.