Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,149,889 members, 7,806,575 topics. Date: Tuesday, 23 April 2024 at 06:29 PM

Explain N + 1 Problem To Me Like I'm A 5 Year Old. - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Explain N + 1 Problem To Me Like I'm A 5 Year Old. (477 Views)

Need Someone Who Can Build A 5 Page Website / Explain Time Complexity To Me Like A 5 Year Old / A 5-week Programming Class, Don't Miss This (2) (3) (4)

(1) (Reply) (Go Down)

Explain N + 1 Problem To Me Like I'm A 5 Year Old. by Karleb(m): 12:03pm On Sep 18, 2020
kiss
Re: Explain N + 1 Problem To Me Like I'm A 5 Year Old. by Najdorf: 6:14pm On Sep 18, 2020
N+1?

Do you mean the 3N+1 problem?
Re: Explain N + 1 Problem To Me Like I'm A 5 Year Old. by Karleb(m): 12:18am On Sep 19, 2020
Najdorf:
N+1?

Do you mean the 3N+1 problem?

I mean the N + 1 problem in SQL that causes a query to query other queries unnecessarily.
Re: Explain N + 1 Problem To Me Like I'm A 5 Year Old. by Shepherdd(m): 7:26pm On Sep 19, 2020
Karleb:


I mean the N + 1 problem in SQL that causes a query to query other queries unnecessarily.


It happens when you have a parent child relationship. You query the db for an object and that objects generate another query for it's children and another for the children's relationship and another e.t.c

This happens often when you are using ORM for your database interactions, and it can be mitigated by the JOIN statement. Django's ORM provides the select_related function (it uses JOIN underneath) to avoid this problem.

1 Like

Re: Explain N + 1 Problem To Me Like I'm A 5 Year Old. by wane01(m): 4:01pm On Sep 20, 2020
I dont have a full structured explanation for you but this problem is very common with GraphQL APIs. Especially when having a deep nested schema.

Its happens when you have a recursive SQL query. So one way to mitigate it is being doing a depth limit ( when using GraphQL ).

Facebook built Dataloader which batches the query and transforms it into a single SQL operation.

Sad part of this problem is that its not very noticeable except when using youre using a 3rd party logging service to log out your application queries.

if you really want to understand it I'd advise you search for it within a GraphQL API context. Since its a common problem there, they're many articles on it

cc Pcguru1

1 Like

Re: Explain N + 1 Problem To Me Like I'm A 5 Year Old. by Karleb(m): 4:30pm On Sep 20, 2020
cheesy I like these responses.

1 Like

(1) (Reply)

Web Development Study Partner Needed / What Is Wrong With My SWITCH Statement(javascript) / Backend Developer/ Mobile App Developer

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 9
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.