public inbox for [email protected]  
help / color / mirror / Atom feed
nested loop joins
2+ messages / 2 participants
[nested] [flat]

* nested loop joins
@ 2021-10-26 18:47  Greg Rychlewski <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: Greg Rychlewski @ 2021-10-26 18:47 UTC (permalink / raw)
  To: [email protected]

Hi,

I'm looking to understand how nested loop joins with limits work. Say I
have this query

SELECT *
FROM a  INNER JOIN b ON a.id = b.id
LIMIT 10;

Say this was done as a nested loop join where the rows of "a" are the outer
loop.

In this scenario, would all the rows of "a" be materialized or are they
lazily evaluated?

If they are lazily evaluated is it done using cursors?

Thanks


^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: nested loop joins
@ 2021-10-26 18:56  Tom Lane <[email protected]>
  parent: Greg Rychlewski <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2021-10-26 18:56 UTC (permalink / raw)
  To: Greg Rychlewski <[email protected]>; +Cc: [email protected]

Greg Rychlewski <[email protected]> writes:
> I'm looking to understand how nested loop joins with limits work. Say I
> have this query

> SELECT *
> FROM a  INNER JOIN b ON a.id = b.id
> LIMIT 10;

> Say this was done as a nested loop join where the rows of "a" are the outer
> loop.

> In this scenario, would all the rows of "a" be materialized or are they
> lazily evaluated?

Evaluation of the join will stop as soon as it's produced 10 rows.
Only as much of "a" will be read as necessary to get that.
(Potentially, not all of "b" would be read either, if 10 matches
to the first "a" row exist in "b".)

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2021-10-26 18:56 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-10-26 18:47 nested loop joins Greg Rychlewski <[email protected]>
2021-10-26 18:56 ` Tom Lane <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox