Repository navigation
Free the rows of each run of a LATERAL relation that no tuple uses - #444
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A query with a
LATERALrelation in a nested loop kept the rows of every run of that relation until the query ended. In the regression testsjoinandsubselect, a self-join oftenk1ran the relation 10,000 or 100 million times. The memory then grew by about 50 MB each second until the system stopped the server, and the 126 tests after it could not connect. Now the scan frees the rows of a run that no joined tuple uses.Changes
Tables::marksgives the number of rows of eachLATERALrelation before a run.Tables::compactruns after the join of each outer row. It keeps only the new rows that the joined tuples use, and it gives those tuples the new row numbers. The memory is then the size of the result of the join, not the size of all the runs.Known differences
None. The result of each query is the same. Only the memory changes.
Tests
connection/lateral_runs.testis the output of PostgreSQL 19 for the same script in a new database. It has joins that keep a few rows of many runs, an outer join with empty runs, a whole-row reference, a chain of twoLATERALrelations and an aggregate. fmt, clippy, the workspace tests and the checks of xtask pass on server1.