{"record":{"id":"2b8e11d58621770e","repo":"influxdata/influxdb","slug":"sorted-column-column-name-is-not-in-the-schema","errorCode":null,"errorMessage":"sorted column {column_name} is not in the schema","messagePattern":"sorted column (.+?) is not in the schema","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/iox_query/src/statistics/aggregate_per_plan.rs","lineNumber":255,"sourceCode":"                Arc::clone(plan),\n                plan.schema(),\n                plan.partition_statistics(None)?,\n            ))\n        })\n        .collect::<Result<Vec<_>, DataFusionError>>();\n\n    // If any without statistics, return none\n    let Ok(plans_schema_and_stats) = plans_schema_and_stats else {\n        return None;\n    };\n\n    // get value range of the sorted column for each input\n    let mut min_max_ranges = Vec::with_capacity(plans_schema_and_stats.len());\n    for (input, input_schema, input_stats) in plans_schema_and_stats {\n        // get index of the sorted column in the schema\n        let Ok(sorted_col_index) = input_schema.index_of(column_name) else {\n            // panic that the sorted column is not in the schema\n            panic!(\"sorted column {column_name} is not in the schema\");\n        };\n\n        let column_stats = input_stats.column_statistics;\n        let sorted_col_stats = column_stats[sorted_col_index].clone();\n        match (sorted_col_stats.min_value, sorted_col_stats.max_value) {\n            (Precision::Exact(min), Precision::Exact(max)) => {\n                min_max_ranges.push((min, max));\n            }\n            // WARNING: this may produce incorrect results until we use more precision\n            // as `Inexact` is not guaranteed to cover the actual min and max values\n            // https://github.com/apache/arrow-datafusion/issues/8078\n            (Precision::Inexact(min), Precision::Inexact(max)) => {\n                let _deduplicate_exec = input.as_any().downcast_ref::<DeduplicateExec>()?;\n                min_max_ranges.push((min, max));\n            }\n            // the statistics  values are absent\n            _ => return None,\n        }","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/influxdata/influxdb/blob/06200ef96ba82c5f6727e5038a83af8e722c6875/core/iox_query/src/statistics/aggregate_per_plan.rs#L237-L273","documentation":"statistics_min_max panics when the sorted column name cannot be found in one of the input plans' schemas. The function assumes every input plan's schema contains the column the plan is sorted by; if a projection or rename removed it, index_of fails and the code deliberately panics with this message.","triggerScenarios":"Calling statistics_min_max (directly or via tests) with a column_name that is not present in at least one input plan's schema — e.g. after a projection dropped or renamed the sort column.","commonSituations":"Optimizer pushed a projection that eliminated the sort column; schema case mismatch (column stored as 'Time' but queried as 'time'); custom plans where inputs have divergent schemas.","solutions":["Verify column_name exists in every input plan schema before calling statistics_min_max","Check for case mismatches in column naming between plans","Fix the upstream optimizer/projection rule so the sorted column is preserved in each input's schema"],"exampleFix":"// before\nlet Ok(sorted_col_index) = input_schema.index_of(column_name) else {\n    panic!(\"sorted column {column_name} is not in the schema\");\n};\n// after\nlet Some(sorted_col_index) = input_schema.index_of(column_name) else {\n    return internal_err!(\"sorted column {column_name} is not in schema of input {}\", input.name());\n};","handlingStrategy":"validation","validationCode":"for input in plan.inputs() {\n    assert!(input.schema().index_of(column_name).is_ok(),\n        \"{} not in {}\", column_name, input.schema());\n}","typeGuard":"fn has_column(schema: &SchemaRef, col: &str) -> bool {\n    schema.fields().iter().any(|f| f.name() == col)\n}","tryCatchPattern":"// panic-based; guard with catch_unwind or pre-validate index_of before calling","preventionTips":["Confirm sort column survives projections","Normalize column name casing before lookup","Add schema assertions in optimizer tests"],"tags":["rust","panic","schema","statistics"],"backgroundTag":"schema-validation-failed","analyzedSha":"06200ef96ba82c5f6727e5038a83af8e722c6875","analyzedAt":"2026-09-19T12:55:30.003Z","contentChangedAt":"2026-09-19T12:55:30.003Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}