Get the first 3 big orders without reading them all
transcript
You want the first three big orders. Do you really need to read every page? Or only as far as the third one?
The eager way reads every page, builds a list, then filters. That is 3 fetches and 11 rows. The lazy way pulls one order at a time, and stops at the third. That is 2 fetches and 8 rows. Page 3 is never read.
Take three asks the filter for one order. The filter asks the history, until it finds a big one. The history fetches a page only when its buffer is empty. After the third big order, take three stops asking.
Build the pipeline, and the store is asked zero times. Pull three big orders, and it is asked twice. Eight rows, not eleven. A million orders would save far more. The saving grows with the size of the table.
Need only a few? Pull them. Don't build the whole list first.
Full breakdown in the lecture.