{"record":{"id":"032d1fcc41decd39","repo":"databendlabs/databend","slug":"partitionitem-bucketspilled-unreachable","errorCode":null,"errorMessage":"PartitionItem::BucketSpilled(_) => unreachable!()","messagePattern":"PartitionItem::BucketSpilled\\(_\\) => unreachable!\\(\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/query/service/src/pipelines/processors/transforms/aggregator/aggregate_meta.rs","lineNumber":227,"sourceCode":"                BinaryType::from_data(row_group_column),\n            ]);\n\n            return data_block.add_meta(Some(AggregateSerdeMeta::create_spilled(\n                bucket_num as isize,\n            )));\n        }\n\n        let mut buckets = Vec::with_capacity(data.len());\n        let mut payload_row_counts = Vec::with_capacity(data.len());\n        let mut payload_blocks = Vec::with_capacity(data.len());\n\n        for item in data {\n            let (bucket, block) = match item {\n                PartitionItem::Serialized(payload) => (payload.bucket, payload.data_block),\n                PartitionItem::AggregatePayload(payload) => {\n                    (payload.bucket, payload.payload.aggregate_flush_all()?)\n                }\n                PartitionItem::BucketSpilled(_) => unreachable!(),\n            };\n\n            if block.num_rows() == 0 {\n                continue;\n            }\n            buckets.push(bucket);\n            payload_row_counts.push(block.num_rows());\n            payload_blocks.push(block);\n        }\n\n        if payload_blocks.is_empty() {\n            return Ok(DataBlock::empty());\n        }\n\n        let merged_block = DataBlock::concat(&payload_blocks)?;\n        merged_block.add_meta(Some(AggregateSerdeMeta::create_partitioned_payload(\n            buckets,\n            payload_row_counts,","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/service/src/pipelines/processors/transforms/aggregator/aggregate_meta.rs#L209-L245","documentation":"`AggregateMeta::serialize_mixed` panics when it encounters a `PartitionItem::BucketSpilled` entry. Mixed-mode serialization expects each partition to be either fully in-memory (Serialized) or an AggregatePayload; a bucket that was already spilled to disk must not be present in the data being serialized, so this indicates mixed-mode bookkeeping produced an invalid partition set.","triggerScenarios":"Serializing aggregate metadata that contains a `BucketSpilled` partition item — i.e. the aggregator spilled a bucket to disk but the spill/mixed-mode logic still handed the partition to `serialize_mixed`.","commonSituations":"Distributed aggregation with spilling enabled under memory pressure, where spill state and in-memory partition tracking get out of sync; bugs in spill-aware aggregation planning.","solutions":["Reduce memory pressure or disable/tune aggregation spilling settings so buckets do not spill unexpectedly in this code path","Check whether the query uses features that mix spilled buckets with serialized payloads and avoid the affected combination","Report a bug with the query and settings; the spill bookkeeping in aggregate_meta.rs needs to handle or reject BucketSpilled explicitly","Upgrade Databend for spill-handling fixes in the aggregator"],"exampleFix":"// before\nPartitionItem::BucketSpilled(_) => unreachable!(),\n// after\nPartitionItem::BucketSpilled(item) => return Err(ErrorCode::Internal(\n    format!(\"BucketSpilled item {} not supported in serialize_mixed\", item.bucket))),","handlingStrategy":"validation","validationCode":"if data.iter().any(|i| matches!(i, PartitionItem::BucketSpilled(_))) { return Err(ErrorCode::Internal(\"BucketSpilled item in serialize_mixed input\")); }","typeGuard":"fn is_serializable(i: &PartitionItem) -> bool { !matches!(i, PartitionItem::BucketSpilled(_)) }","tryCatchPattern":null,"preventionTips":["Keep spilled buckets out of the mixed-mode serialize path by filtering or routing them to the spilled handler","Track spill state in a dedicated structure so mixed serialization sees only in-memory partitions","Add aggregator tests that combine spilling with distributed exchange"],"tags":["rust","panic","aggregation","spilling"],"backgroundTag":"internal-invariant-violation","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}