Commit eca2e00
refactor: Simplify NLJ re-scans with
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes #123` indicates that this PR will close issue #123.
-->
- Closes #.
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->
### Background
#21448 introduced
memory-limited execution for NLJ (thanks to @viirya).
The idea is:
1. Load the build (left) side of the NLJ until the memory limit is
reached.
2. Probe the right side and complete the join for the current buffered
build-side chunk.
3. Load the next chunk of the build side and repeat the right-side scan
until all data is processed.
To support repeated probing of the right side, input batches are spilled
to disk during the first pass. In subsequent passes, input is read
directly from the spill. This avoids re-evaluating potentially expensive
pipelines (e.g., Parquet decoding + filtering), making repeated probes
both memory-efficient and fast.
### This PR
This PR extracts the spill-backed replayable stream into a separate
module to simplify the NLJ implementation.
Although the lines of code increase, the new module provides a clearer
interface and I think it's easier to maintain.
Additionally, this utility may be useful elsewhere. I have seen a
similar pattern in SedonaDB for memory-limited spatial joins.
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->
- Introducing `ReplayableStreamSource` for the above purpose
- Refactor NLJ logic with `ReplayableStreamSource`
## Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
5. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->
UTs, also covered by existing memory-limited NLJ test
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->
No
---------
Co-authored-by: Martin Grigorov <martin-g@users.noreply.github.com>ReplayableStreamSource (#21742)1 parent 766dff1 commit eca2e00
3 files changed
Lines changed: 482 additions & 83 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| |||
931 | 931 | | |
932 | 932 | | |
933 | 933 | | |
934 | | - | |
935 | | - | |
936 | | - | |
937 | | - | |
938 | | - | |
939 | | - | |
940 | | - | |
941 | | - | |
942 | | - | |
943 | | - | |
| 934 | + | |
| 935 | + | |
944 | 936 | | |
945 | 937 | | |
946 | 938 | | |
| |||
960 | 952 | | |
961 | 953 | | |
962 | 954 | | |
963 | | - | |
| 955 | + | |
| 956 | + | |
964 | 957 | | |
965 | 958 | | |
966 | 959 | | |
| |||
1258 | 1251 | | |
1259 | 1252 | | |
1260 | 1253 | | |
1261 | | - | |
| 1254 | + | |
1262 | 1255 | | |
1263 | 1256 | | |
1264 | 1257 | | |
| |||
1356 | 1349 | | |
1357 | 1350 | | |
1358 | 1351 | | |
1359 | | - | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
1360 | 1361 | | |
1361 | 1362 | | |
1362 | 1363 | | |
| |||
1370 | 1371 | | |
1371 | 1372 | | |
1372 | 1373 | | |
1373 | | - | |
1374 | | - | |
1375 | | - | |
1376 | | - | |
1377 | | - | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
1378 | 1379 | | |
1379 | 1380 | | |
1380 | 1381 | | |
| |||
1571 | 1572 | | |
1572 | 1573 | | |
1573 | 1574 | | |
1574 | | - | |
1575 | | - | |
1576 | | - | |
1577 | | - | |
1578 | | - | |
1579 | | - | |
1580 | | - | |
1581 | | - | |
1582 | | - | |
1583 | | - | |
1584 | | - | |
1585 | | - | |
1586 | | - | |
1587 | | - | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
1588 | 1578 | | |
1589 | | - | |
1590 | | - | |
1591 | | - | |
1592 | | - | |
1593 | | - | |
1594 | | - | |
1595 | | - | |
1596 | | - | |
1597 | | - | |
1598 | | - | |
1599 | | - | |
1600 | | - | |
| 1579 | + | |
| 1580 | + | |
1601 | 1581 | | |
1602 | 1582 | | |
1603 | 1583 | | |
| |||
1613 | 1593 | | |
1614 | 1594 | | |
1615 | 1595 | | |
1616 | | - | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
1617 | 1602 | | |
1618 | 1603 | | |
1619 | 1604 | | |
| |||
1626 | 1611 | | |
1627 | 1612 | | |
1628 | 1613 | | |
1629 | | - | |
1630 | | - | |
1631 | | - | |
1632 | | - | |
1633 | | - | |
1634 | | - | |
1635 | | - | |
1636 | | - | |
1637 | | - | |
1638 | | - | |
1639 | | - | |
1640 | | - | |
1641 | | - | |
1642 | 1614 | | |
1643 | 1615 | | |
1644 | 1616 | | |
| |||
1654 | 1626 | | |
1655 | 1627 | | |
1656 | 1628 | | |
1657 | | - | |
1658 | | - | |
1659 | | - | |
1660 | | - | |
1661 | | - | |
1662 | | - | |
1663 | | - | |
1664 | | - | |
1665 | | - | |
1666 | | - | |
1667 | | - | |
1668 | | - | |
1669 | | - | |
1670 | | - | |
1671 | | - | |
1672 | | - | |
1673 | | - | |
1674 | | - | |
1675 | | - | |
1676 | | - | |
1677 | | - | |
1678 | | - | |
1679 | | - | |
1680 | 1629 | | |
1681 | 1630 | | |
1682 | 1631 | | |
| |||
2257 | 2206 | | |
2258 | 2207 | | |
2259 | 2208 | | |
2260 | | - | |
| 2209 | + | |
| 2210 | + | |
| 2211 | + | |
| 2212 | + | |
| 2213 | + | |
2261 | 2214 | | |
2262 | 2215 | | |
2263 | 2216 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
0 commit comments