Fixing a bug in my lateral joins queries with rails
24-Jan-2025 71
I have some posts about using lateral joins in rails to fetch the “top N” of each record. Some months ago Ben Sheldon helped me see a performance problem on the queries that I was using.
Here I try to explain the problem, the solution proposed by him, and also an introduction about a tool he published to build this kind of “top N” queries using lateral joins.
The problem
In his words, “The outermost condition of the association (e.g. WHERE user_id IN ($1, ...)) doesn’t get pushed down in the current query. This leads to the lateral join being applied to all records before the condition is applied.”.
Fixing a bug in my lateral joins queries with rails #ruby #rubydeveloper #rubyonrails #Fixing #lateral #joins #queries #rails #bug https://rubyonrails.ba/link/fixing-a-bug-in-my-lateral-joins-queries-with-rails