-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
sql: free scanner and parser allocations after large statement #97334
Comments
Seems like this may not be a large change, so let's try to get it done this release if possible and backport. |
two questions out of curiosity:
whats the down side of resetting parser/scanner every loop? |
Awesome find! Did we confirm that this solves the problem? I think in some cases the prepared statement cache may hang onto some of the same memory. It's worth looking into this - depending on how the allocations are performed (are they slices of nodes?) the prepared statement cache may prevent this memory from being collected if there are pointers into bigger backing slices. We saw problems like this before when cached things pointed directly to the backing byte buffer of e.g. a protobuf, but the same principle could apply to the bytes that come in from a connection and so on. |
Great point. We're actually looking into the prepared statement cache now. |
It looks like these two issues with prepared statements were actually responsible for the memory usage we saw: |
@michae2 so is this issue still valid, or should we close it? |
This issue is valid (the repro still causes it) but is not as urgent as I thought. |
This is related to this recent issue with how the scanner handles SQL comments: #127710. (Different cause, but same memory leak symptoms.) |
After a large statement is scanned and parsed, we hang onto the scanner and parser allocations in
cockroach/pkg/sql/parser/parse.go
Lines 111 to 119 in 3d054f3
Here's a repro, using python to create a large statement:
Even though this statement is less than 16 MiB, it causes us to hold onto over a GiB of memory in the scanner and parser, and this is not released until the connection closes:
This issue is somewhat similar to #47969 and #72581 and #80497
Jira issue: CRDB-24639
The text was updated successfully, but these errors were encountered: