rails icon indicating copy to clipboard operation
rails copied to clipboard

Ignore order of SQL joins, select, includes, left_outer_joins, eager_load and preload for ActiveRecord::Relation#or & for ActiveRecord::Relation#and

Open sampatbadhe opened this issue 1 year ago • 2 comments

Summary

Fixes https://github.com/rails/rails/issues/45398

Ignore order of SQL joins, select, includes, left_outer_joins, eager_load and preload for ActiveRecord::Relation#or & for ActiveRecord::Relation#and

sampatbadhe avatar Jun 20 '22 03:06 sampatbadhe

I haven't taken the time to actually invent examples, but my recollection is that ordering of left joins can affect the query results (at least, I have strong memories that the PostgreSQL optimizer is more limited in how it can reorder a LEFT JOIN-using query plan over an otherwise equivalent JOIN version). @sampatbadhe are you certain this is safe?

matthewd avatar Aug 08 '22 14:08 matthewd

@matthewd Thank you for your review.

I haven't taken the time to actually invent examples, but my recollection is that ordering of left joins can affect the query results (at least, I have strong memories that the PostgreSQL optimizer is more limited in how it can reorder a LEFT JOIN-using query plan over an otherwise equivalent JOIN version). @sampatbadhe are you certain this is safe?

I'll re-verify with LEFT-JOIN on local and share the result.

sampatbadhe avatar Aug 08 '22 15:08 sampatbadhe