viktorianer

viktorianer

High Performance PostgreSQL for Rails: Explanation regarding the use of includes with a limit (Page 124)

Dear Andrew, @andatki

I found the explanation regarding the use of .includes() with a limit in the context of vehicle reservations to be quite insightful. However, I believe the discussion on performance implications could benefit from further clarification, particularly regarding the difference in behavior with and without a limit.

Here’s a suggested rewrite to enhance clarity:


When using .includes() to load vehicle reservations, the query is split into two parts. First, a query retrieves a limited number of vehicles (e.g., 2 vehicles). Then, another query fetches the associated reservations for these vehicles using an IN clause with the vehicle_ids of the retrieved vehicles. Keep in mind that if the IN clause contains too many values, it can lead to performance issues.

Performance Implications

  • Without limit: If there are many vehicles, the IN clause can become very large, which may degrade performance.
  • With limit: The IN clause remains small, improving performance for the secondary query.

Additionally, this explanation can move before LEFT OUTER JOIN part, in order to avoid a context switch.

I hope this suggestion helps make the performance implications clearer for the readers.

Best regards,

Viktor

Most Liked

andatki

andatki

Author of High Performance PostgreSQL for Rails

Thank you @viktorianer. Your description makes sense. If we revise the book in the future, I’ll pay extra attention to this section, as eager loading is of course a very common pattern.

In my experience, I’ve seen poor performance from big lists of values in an IN clause on big tables. I wrote up some thoughts about this in a blog post here: Big Problems From Big IN lists with Ruby on Rails and PostgreSQL | Software Engineer, Author, High Performance PostgreSQL for Rails

Where Next?

Popular Pragmatic Bookshelf topics Top

telemachus
Python Testing With Pytest - Chapter 2, warnings for “unregistered custom marks” While running the smoke tests in Chapter 2, I get these...
New
mikecargal
Title: Hands-On Rust (Chap 8 (Adding a Heads Up Display) It looks like ​.with_simple_console_no_bg​(SCREEN_WIDTH*2, SCREEN_HEIGHT*2...
New
Chrichton
Dear Sophie. I tried to do the “Authorization” exercise and have two questions: When trying to plug in an email-service, I found the ...
New
adamwoolhether
When trying to generate the protobuf .go file, I receive this error: Unknown flag: --go_opt libprotoc 3.12.3 MacOS 11.3.1 Googling ...
New
leonW
I ran this command after installing the sample application: $ cards add do something --owner Brian And got a file not found error: Fil...
New
adamwoolhether
I’m not quite sure what’s going on here, but I’m unable to have to containers successfully complete the Readiness/Liveness checks. I’m im...
New
akraut
The markup used to display the uploaded image results in a Phoenix.LiveView.HTMLTokenizer.ParseError error. lib/pento_web/live/product_l...
New
jwandekoken
Book: Programming Phoenix LiveView, page 142 (157/378), file lib/pento_web/live/product_live/form_component.ex, in the function below: d...
New
tkhobbes
After some hassle, I was able to finally run bin/setup, now I have started the rails server but I get this error message right when I vis...
New
dachristenson
I’ve got to the end of Ch. 11, and the app runs, with all tabs displaying what they should – at first. After switching around between St...
New

Other popular topics Top

dasdom
No chair. I have a standing desk. This post was split into a dedicated thread from our thread about chairs :slight_smile:
New
AstonJ
Curious to know which languages and frameworks you’re all thinking about learning next :upside_down_face: Perhaps if there’s enough peop...
New
dimitarvp
Small essay with thoughts on macOS vs. Linux: I know @Exadra37 is just waiting around the corner to scream at me “I TOLD YOU SO!!!” but I...
New
AstonJ
If you are experiencing Rails console using 100% CPU on your dev machine, then updating your development and test gems might fix the issu...
New
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1143 25883 760
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
AstonJ
Was just curious to see if any were around, found this one: I got 51/100: Not sure if it was meant to buy I am sure at times the b...
New
PragmaticBookshelf
Author Spotlight: Sophie DeBenedetto @SophieDeBenedetto The days of the traditional request-response web application are long gone, b...
New
sir.laksmana_wenk
I’m able to do the “artistic” part of game-development; character designing/modeling, music, environment modeling, etc. However, I don’t...
New

Sub Categories: