{"record":{"id":"d4d036f842312c68","repo":"influxdata/influxdb","slug":"specified-key-column-id-column-id-does-not-exist-in-the","errorCode":null,"errorMessage":"specified key column (id: {column_id}) does not exist in the table schema","messagePattern":"specified key column \\(id: (.+?)\\) does not exist in the table schema","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"influxdb3_cache/src/last_cache/mod.rs","lineNumber":26,"sourceCode":"mod provider;\npub use provider::{LastCacheProvider, background_catalog_update};\nmod table_function;\nuse schema::InfluxColumnType;\npub use table_function::{LAST_CACHE_UDTF_NAME, LastCacheFunction};\n\n#[derive(Debug, thiserror::Error)]\npub enum Error {\n    #[error(\"invalid cache size\")]\n    InvalidCacheSize,\n    #[error(\n        \"last cache already exists for database and table, but it was configured differently: {reason}\"\n    )]\n    CacheAlreadyExists { reason: String },\n    #[error(\"specified column (name: {column_name}) does not exist in the table definition\")]\n    ColumnDoesNotExistByName { column_name: String },\n    #[error(\"specified column (id: {column_id}) does not exist in the table definition\")]\n    ColumnDoesNotExistById { column_id: ColumnId },\n    #[error(\"specified key column (id: {column_id}) does not exist in the table schema\")]\n    KeyColumnDoesNotExist { column_id: ColumnId },\n    #[error(\"specified key column (name: {column_name}) does not exist in the table schema\")]\n    KeyColumnDoesNotExistByName { column_name: String },\n    #[error(\"key column must be string, int, uint, or bool types, got: {column_type}\")]\n    InvalidKeyColumn { column_type: InfluxColumnType },\n    #[error(\"specified value column ({column_id}) does not exist in the table schema\")]\n    ValueColumnDoesNotExist { column_id: ColumnId },\n    #[error(\"requested last cache does not exist\")]\n    CacheDoesNotExist,\n}\n\nimpl Error {\n    fn cache_already_exists(reason: impl Into<String>) -> Self {\n        Self::CacheAlreadyExists {\n            reason: reason.into(),\n        }\n    }\n}","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/influxdata/influxdb/blob/06200ef96ba82c5f6727e5038a83af8e722c6875/influxdb3_cache/src/last_cache/mod.rs#L8-L44","documentation":"This is the `KeyColumnDoesNotExist` variant of the last-cache `Error` enum. It is raised when a column supplied as a key column, referenced by numeric ColumnId, is not present in the table's schema. Key columns form the group-by dimension of a last-of-value cache, so the library validates each key id against the current table schema before constructing the cache.","triggerScenarios":"Calling `create_last_cache` / `create_from_table` with `key_columns` containing a ColumnId absent from the table schema; building a cache over a table after its key columns were dropped or re-created with new ids.","commonSituations":"Configuring cache key columns by id copied from an older schema after ALTER TABLE; schema drift between test and production tables; generating cache configs programmatically from stale metadata.","solutions":["Verify each key column id against the current table schema before calling create_last_cache","Reference key columns by name (`KeyColumnDoesNotExistByName` path) or look up ids fresh from the schema","Re-fetch the table definition after schema changes and rebuild cache configuration"],"exampleFix":"// before\nlet key_ids = vec![3]; // id no longer in schema\ncreate_last_cache(db, tbl, name, Some(key_ids), None, count, ttl);\n// after\nlet key_ids: Vec<ColumnId> = [\"tag_one\"].iter()\n    .map(|n| table_def.schema().column_id_by_name(n).unwrap())\n    .collect();\ncreate_last_cache(db, tbl, name, Some(key_ids), None, count, ttl);","handlingStrategy":"validation","validationCode":"fn validate_key_columns(schema: &Schema, ids: &[ColumnId]) -> Result<(), String> {\n    ids.iter().find(|id| schema.field_id(**id).is_none())\n        .map_or(Ok(()), |id| Err(format!(\"key column id {id} not in schema\")))\n}","typeGuard":"fn all_key_columns_exist(schema: &Schema, ids: &[ColumnId]) -> bool {\n    ids.iter().all(|id| schema.field_id(*id).is_some())\n}","tryCatchPattern":"match res {\n    Err(LastCacheError::KeyColumnDoesNotExist { column_id }) => {\n        eprintln!(\"key column id {column_id} missing; re-derive keys from current schema\");\n    }\n    Err(e) => return Err(e.into()),\n    Ok(_) => {}\n}","preventionTips":["Define cache key columns by tag name, not by numeric id","Validate key column ids against the schema in every environment at startup","Rebuild cache definitions whenever the table schema changes"],"tags":["influxdb3","last-cache","schema","key-column"],"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"}