{"record":{"id":"d97b0752cd59208b","repo":"databendlabs/databend","slug":"temp-table-id-used-up","errorCode":null,"errorMessage":"Temp table id used up","messagePattern":"Temp table id used up","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/query/storages/common/session/src/temp_table.rs","lineNumber":101,"sourceCode":"    pub db_name: String,\n    pub table_name: String,\n    pub meta: TableMeta,\n    pub copied_files: BTreeMap<String, TableCopiedFileInfo>,\n}\n\nimpl TempTblMgr {\n    fn temp_table_desc(db_name: &str, table_name: &str) -> String {\n        format!(\"'{}'.'{}'\", db_name, table_name)\n    }\n\n    pub fn init() -> Arc<Mutex<Self>> {\n        Arc::new(Mutex::new(Self::default()))\n    }\n\n    fn inc_next_id(&mut self) {\n        self.next_id += 1;\n        if !is_temp_table_id(self.next_id) {\n            panic!(\"Temp table id used up\");\n        }\n    }\n\n    pub fn is_empty(&self) -> bool {\n        self.id_to_table.is_empty() && self.staged_tables.is_empty()\n    }\n\n    pub fn create_table(\n        &mut self,\n        req: CreateTableReq,\n        prefix: String,\n    ) -> Result<CreateTableReply> {\n        let CreateTableReq {\n            create_option,\n            name_ident,\n            table_meta,\n            as_dropped,\n            ..","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/storages/common/session/src/temp_table.rs#L83-L119","documentation":"The session-local temp-table manager allocates temp table IDs by incrementing a counter; each ID must stay within the reserved temp-table ID range checked by `is_temp_table_id`. When the counter is incremented past the last valid temp ID, it panics with 'Temp table id used up', because continuing would collide with ordinary (persistent) table IDs.","triggerScenarios":"Calling `create_table` for temporary tables so many times within one session that `next_id` exceeds the highest value satisfying `is_temp_table_id` (u64 range: temp IDs occupy the high range near u64::MAX, requiring ~2^63+ creations).","commonSituations":"Extremely long-lived sessions creating/destroying temp tables at very high volume; practically only seen in stress tests or leaks where temp tables are created in a loop for weeks without session restart.","solutions":["Restart the session or reconnect — the temp ID counter is per-session, so a new session resets it.","Audit the code path for temp-table creation loops that never drop tables, and reuse/drop temp tables instead of always creating new ones.","Refactor to recycle freed temp IDs (maintain a free list) instead of a monotonically increasing counter."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Before creating another temp table in a long session, check the counter headroom\nif !is_temp_table_id(next_id.wrapping_add(1)) {\n    // close and reopen the session to reset the per-session counter\n}","typeGuard":null,"tryCatchPattern":"// The panic aborts the session task; wrap the batch temp-table workload\nmatch result {\n    Err(err) if err.message() == \"Temp table id used up\" => {\n        recreate_session_and_retry();\n    }\n    other => other?,\n}","preventionTips":["Drop temp tables you no longer need instead of creating ever-new ones.","Recycle a small pool of temp table names per session.","Restart long-running sessions periodically in high-volume temp-table workloads.","Track temp-table creation counts in tests to catch unbounded loops."],"tags":["rust","panic","temp-table","id-exhaustion","session"],"backgroundTag":"value-out-of-range","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"}