{"record":{"id":"c0980ea87ca17a99","repo":"risingwavelabs/risingwave","slug":"invalid-iter-key-range-table-id-left-right","errorCode":null,"errorMessage":"invalid iter key range: {table_id} {left:?} {right:?}","messagePattern":"invalid iter key range: (.+?) (.+?) (.+?)","errorType":"error_code","errorClass":"HummockError","httpStatus":null,"severity":"error","filePath":"src/storage/src/hummock/store/version.rs","lineNumber":1017,"sourceCode":"        committed: &CommittedVersion,\n        local_stats: &mut StoreLocalStatistic,\n        factory: &mut F,\n    ) -> StorageResult<()> {\n        {\n            fn bound_inner<T>(bound: &Bound<T>) -> Option<&T> {\n                match bound {\n                    Bound::Included(bound) | Bound::Excluded(bound) => Some(bound),\n                    Bound::Unbounded => None,\n                }\n            }\n            let (left, right) = &table_key_range;\n            if let (Some(left), Some(right)) = (bound_inner(left), bound_inner(right))\n                && right < left\n            {\n                if cfg!(debug_assertions) {\n                    panic!(\"invalid iter key range: {table_id} {left:?} {right:?}\")\n                } else {\n                    return Err(HummockError::other(format!(\n                        \"invalid iter key range: {table_id} {left:?} {right:?}\"\n                    ))\n                    .into());\n                }\n            }\n        }\n\n        local_stats.staging_imm_iter_count = imms.len() as u64;\n        for imm in imms {\n            factory.add_batch_iter(imm);\n        }\n\n        // 2. build iterator from committed\n        // Because SST meta records encoded key range,\n        // the filter key range needs to be encoded as well.\n        let user_key_range = bound_table_key_range(table_id, &table_key_range);\n        let user_key_range_ref = (\n            user_key_range.0.as_ref().map(UserKey::as_ref),","sourceCodeStart":999,"sourceCodeEnd":1035,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/storage/src/hummock/store/version.rs#L999-L1035","documentation":"Hummock iterator was given a key range whose left bound is greater than its right bound, which is invalid for a forward iterator. In debug builds this panics; in release builds it returns HummockError::other with this message.","triggerScenarios":"Calling iter_with_memtable or rev_iter-derived iter_inner on a HummockVersion/table where bound_inner(left) > bound_inner(right), i.e. start key exceeds end key.","commonSituations":"Bugs in code constructing scan ranges (e.g. reversed user range scans, wrong bound ordering after prefix/limit handling), or corrupted range metadata for a table_id.","solutions":["Check the code that builds the iterator range to ensure left <= right","Validate user-supplied scan bounds (start/end keys) before passing them to Hummock iterators","Reproduce in a debug build to get a panic with a stack trace pinpointing the caller","Inspect how the table's key range was derived (e.g. from SST metadata) for corruption"],"exampleFix":"// before\nlet iter = store.iter(table_id, end_key, start_key).await?;\n// after\nassert!(start_key <= end_key, \"reversed range\");\nlet iter = store.iter(table_id, start_key, end_key).await?;","handlingStrategy":"validation","validationCode":"fn validate_range(left: &[u8], right: &[u8]) -> Result<(), String> {\n    if left > right { Err(format!(\"invalid range: {:?} > {:?}\", left, right)) } else { Ok(()) }\n}","typeGuard":null,"tryCatchPattern":"let (left, right) = if start_key <= end_key {\n    (start_key, end_key)\n} else {\n    (end_key, start_key) // or reject\n};","preventionTips":["Always normalize scan ranges so start <= end before iterating","Test range construction with reversed/empty user bounds","Assert bound ordering in debug builds around iterator creation"],"tags":["storage","hummock","iterator"],"backgroundTag":"invalid-argument-value","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}