Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5-0-stable: Avoid unscope(:order) when limit_value is presented for countand exists? #27234

Closed
wants to merge 4 commits into from

Conversation

kamipo
Copy link
Member

@kamipo kamipo commented Nov 30, 2016

Backport #26972 and #26981.

Our Rails app encountered lots of slow queries due to except :order in production.
Currently I'm using relation.load.size instead as a workaround to keep :order.

I'd like to backport these fixes to latest stable branch.

@rails-bot
Copy link

r? @kaspth

(@rails-bot has picked a reviewer for you, use r? to override)

@rails-bot
Copy link

warning Warning warning

  • Pull requests are usually filed against the master branch for this repo, but this one is against 5-0-stable. Please double check that you specified the right target!

If `limit_value` is presented, records fetching order is very important
for performance. Should not unscope the order in the case.
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
```
To ease to customize a relation for `exists?`.
@kamipo
Copy link
Member Author

kamipo commented Apr 30, 2017

Closing since 5.1 has been released.

@kamipo kamipo closed this Apr 30, 2017
@kamipo kamipo deleted the backport_26972 branch April 30, 2017 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants