-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql: preliminary mechanism to track and limit SQL memory usage.
This patch instruments SQL execution to track memory allocations whose amounts depend on user input and current database contents (as opposed to allocations dependent on other parameters e.g. statement size). It does so by introducing a new MemoryUsageMonitor object intended to be instantiated once per session. It is set up and teared down with the lifecycle of a session. Components can then link and report their memory usage to the monitor via span objects. Spans can gate incremental allocations and keep track of the cumulative allocations so that all can be released at once. This is used to track and limits allocations: - in `valueNode`, - buckets in `groupNode`, - sorted data in `sortNode`, - temp results in `joinNode`, - seen prefixes and suffixes in `distinctNode`, - the Result arrays in Executor, - prepared statements and prepared portals in pgwire. A moderate amount of intelligence is implemented so as to avoid computing sizes for every column of every row in a valueNode - the combined size of all fixed-size columns is precomputed and counted at once for every row. This patch does not track the memory allocated for write intents in the KV transaction object. For troubleshooting the following mechanisms are provided: - an env var COCKROACH_NOTEWORTHY_MEMORY_USAGE, if set, defines the minimum total allocated size for a monitor before it starts logging how much memory it is consuming. - detailed allocation progress is logged at level 2 or above. To trace just SQL activity and memory allocation, one can use for example `--vmodule=executor=2,mem_usage=2`.
- Loading branch information
Showing
51 changed files
with
1,663 additions
and
348 deletions.
There are no files selected for viewing
This file contains 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
Oops, something went wrong.