From 2bf7c30049558c2503f20e9810fdf4727650fe99 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Mon, 7 Nov 2016 00:27:50 +0900 Subject: Should except `:distinct` rather than `:order` for `exists?` Records fetching order is very important for performance if `limit` is presented. Should not except the order in the case. And `exists?` replaces select list to `1 AS one` therefore `:distinct` is useless (`DISTINCT 1 AS one`). And PostgreSQL raises the following error if `:distinct` and `:order` are used in the same time. ``` ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list ``` --- activerecord/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activerecord/CHANGELOG.md') diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index dd2a1b4b19..a85fa321cd 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -7,7 +7,8 @@ *Pavel Evstigneev* -* Avoid `unscope(:order)` when `limit_value` is presented for `count`. +* Avoid `unscope(:order)` when `limit_value` is presented for `count` + and `exists?`. If `limit_value` is presented, records fetching order is very important for performance. Should not unscope the order in the case. -- cgit v1.2.3