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
query method #eager_loading?
works incorrectly when order by sql contains table name with schema
#42331
Comments
@zzak thanks for pointing this out but I think this is a different issue, anyways I'll work on a PR to address this issue too. |
#42602 should fix this |
This issue has been automatically marked as stale because it has not been commented on for at least three months. |
still relevant, attached PR |
This issue has been automatically marked as stale because it has not been commented on for at least three months. |
ping |
This issue has been automatically marked as stale because it has not been commented on for at least three months. |
There's an attached PR, can anyone please reopen it? |
Some DBMS (e.g. PostgreSQL) allows to define multiple schemas per database. `eager_loading?` now works when ordering using a table name which contains a schema prefix. Fixes rails#42331
Steps to reproduce
Here's bug report which reproduces the issue
Expected behavior
for query like
ShopPost.includes(:post_detail).order(Arel.sql('shop.posts.id DESC'))
#eager_load?
should return false.As result includes should not eager loaded because when are not present in where/order clauses.
Actual behavior
for query like
ShopPost.includes(:post_detail).order(Arel.sql('shop.posts.id DESC'))
#eager_load?
returns false.As result includes always eager loaded.
System configuration
Rails version: 6.1.3.2, 5.2.6, edge 509f3ca
Ruby version: 2.7.3
PostgreSQL: 12
Additional information
This bug has big performance impact on calculations like
ShopPost.includes(:post_detail).order(Arel.sql('shop.posts.id DESC')).count
when many associations are included, because it transforms into
SELECT COUNT(DISTINCT ...
In
ActiveAdmin
resources always apply sort as strings which leads to slow queries for all tables which have table schema.The text was updated successfully, but these errors were encountered: