-
Notifications
You must be signed in to change notification settings - Fork 3.9k
sql: account for memory of results of window functions computations #38839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Local benchmarks don't show any significant difference (they actually show a slight performance improvement that I would explain by noise):
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test with a small memory account that proves that queries of this form will hit the limit when we expec them to?
Reviewable status:
complete! 1 of 0 LGTMs obtained (waiting on @asubiotto and @jordanlewis)
781306d
to
dcbb839
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a test, and while looking closer to the code, I realized that we were, in fact, accounting for the results of computations, but only as nil
Datums. So I think now the memory monitoring is correct - first, when we allocate a slice for windowValues
, we use the default Datum size times the number of rows; then, once we know the size of the datum, we update the account accordingly. Jordan, could you please take a quick look at this to confirm my logic?
Reviewable status:
complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @asubiotto)
pkg/sql/distsqlrun/windower.go, line 555 at r1 (raw file):
builtin.Reset(ctx) usage = datumSliceOverhead + sizeOfDatum*int64(partition.Len())
This is where we account for the slice with default datum size.
dcbb839
to
b1020f7
Compare
I also noticed that there was a bug in benchmarks of windower - Memory account fix doesn't have any significant performance difference, but the true speed went down by about 50%:
|
0fdf3d2
to
eac0516
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status:
complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @asubiotto and @yuzefovich)
pkg/sql/distsqlrun/windower_test.go, line 64 at r2 (raw file):
} t.Run("", func(t *testing.T) {
nit: there is no need to have this. Subtests aren't a requirement - having no t.Run will mean a single top level test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 2 files at r1, 1 of 1 files at r2.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @asubiotto and @yuzefovich)
Previously, Datums that were the result of computing of window functions were accounted for in memory monitoring only as nils which could lead to OOM when the actual Datum's size was a lot bigger than default one (array_agg and concat_agg were most prone to this). Now, the underlying memory is tracked correctly. Release note: None
eac0516
to
0d5409d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TFTR!
bors r+
Reviewable status:
complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @asubiotto and @jordanlewis)
pkg/sql/distsqlrun/windower_test.go, line 64 at r2 (raw file):
Previously, jordanlewis (Jordan Lewis) wrote…
nit: there is no need to have this. Subtests aren't a requirement - having no t.Run will mean a single top level test.
Thanks, fixed.
38839: sql: account for memory of results of window functions computations r=yuzefovich a=yuzefovich Previously, Datums that were the result of computing of window functions were accounted for in memory monitoring only as nils which could lead to OOM when the actual Datum's size was a lot bigger than default one (array_agg and concat_agg were most prone to this). Now, the underlying memory is tracked correctly. Fixes: #38818. Release note: None Co-authored-by: Yahor Yuzefovich <[email protected]>
Build succeeded |
Previously, Datums that were the result of computing of window
functions were accounted for in memory monitoring only as nils which
could lead to OOM when the actual Datum's size was a lot bigger than
default one (array_agg and concat_agg were most prone to this).
Now, the underlying memory is tracked correctly.
Fixes: #38818.
Release note: None