{"record":{"id":"3b6ff052bc5ce96d","repo":"risingwavelabs/risingwave","slug":"not-enough-memory-to-run-this-query-batch-memory","errorCode":null,"errorMessage":"Not enough memory to run this query, batch memory limit is {0} bytes","messagePattern":"Not enough memory to run this query, batch memory limit is (.+?) bytes","errorType":"error_code","errorClass":"BatchError","httpStatus":null,"severity":"error","filePath":"src/batch/src/error.rs","lineNumber":143,"sourceCode":"    Shared(\n        #[from]\n        #[backtrace]\n        Arc<Self>,\n    ),\n\n    #[error(\"Empty workers found\")]\n    EmptyWorkerNodes,\n\n    #[error(\"Serving vnode mapping not found for fragment {0}\")]\n    ServingVnodeMappingNotFound(FragmentId),\n\n    #[error(\"Streaming vnode mapping has not been initialized\")]\n    StreamingVnodeMappingNotInitialized,\n\n    #[error(\"Streaming vnode mapping not found for fragment {0}\")]\n    StreamingVnodeMappingNotFound(FragmentId),\n\n    #[error(\"Not enough memory to run this query, batch memory limit is {0} bytes\")]\n    OutOfMemory(u64),\n\n    #[error(\"Failed to spill out to disk\")]\n    Spill(\n        #[from]\n        #[backtrace]\n        opendal::Error,\n    ),\n\n    #[error(\"Failed to execute time travel query\")]\n    TimeTravel(\n        #[source]\n        #[backtrace]\n        anyhow::Error,\n    ),\n}\n\n// Serialize/deserialize error.","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/batch/src/error.rs#L125-L161","documentation":"BatchError::OutOfMemory is thrown when a batch query cannot proceed because the memory manager denies allocation: the query would exceed the configured per-query batch memory limit. The error carries the limit in bytes so developers can compare it against the workload's needs. It is a deliberate guard to protect the node from OOM, not an unexpected fault.","triggerScenarios":"Executing a batch query (e.g. SELECT over a large materialized view) whose operator working set exceeds the batch memory limit (developer.batch_spill_by_mem_limit / batch memory context); the memory manager refuses an allocation during executors like sort/hash-agg/hash-join and the executor maps this to BatchError::OutOfMemory.","commonSituations":"Large ad-hoc analytical queries over big MVs, low memory limit configured on small dev instances or in k8s with small resource requests, missing spill configuration so the query must hold everything in memory.","solutions":["Reduce the query's memory footprint (add LIMIT, filters, or break it into smaller queries).","Increase the batch memory limit in the RisingWave configuration (memory management settings) or the node's memory resources.","Enable/configure spill-to-disk so operators can evict data instead of failing.","Check `EXPLAIN` and the query plan for unbounded operators (large hash builds / sorts) and tune accordingly."],"exampleFix":"// before (risingwave.toml)\n[developer]\nbatch_memory_limit_mb = 0  # tiny limit causes OOM for big queries\n\n// after\n[developer]\nbatch_memory_limit_mb = 2048  # raise limit and rely on spill for larger workloads","handlingStrategy":"try-catch","validationCode":"// Rust: estimate query memory needs against the configured limit before running\n// (pseudo) if est_bytes > batch_memory_limit { spill_plan or split_query }","typeGuard":null,"tryCatchPattern":"match result {\n    Err(BatchError::OutOfMemory(limit)) => {\n        // fall back: enable spill or rewrite query with LIMIT/filter, then retry\n    }\n    other => other?,\n}","preventionTips":["Configure an adequate batch memory limit for the largest expected query.","Enable spill-to-disk so memory-heavy operators degrade instead of failing.","Monitor memory manager metrics and alert before the limit is hit.","Split large analytical workloads into smaller paginated/windowed queries."],"tags":["memory","batch","resource-limit","query-execution"],"backgroundTag":"value-out-of-range","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}