databendlabs/databend · error
Temp table id used up
Error message
Temp table id used up
What it means
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.
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.
Defensive patterns
Strategy: retry
Validate before calling
// Before creating another temp table in a long session, check the counter headroom
if !is_temp_table_id(next_id.wrapping_add(1)) {
// close and reopen the session to reset the per-session counter
} Try / catch
// The panic aborts the session task; wrap the batch temp-table workload
match result {
Err(err) if err.message() == "Temp table id used up" => {
recreate_session_and_retry();
}
other => other?,
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Invalid temp table desc
- login_handler expect session id in ctx
- mysql handler should be authed when call
- {}
- expect tuple type
AI-assisted analysis of databendlabs/databend@288d84d76e (2026-09-11).
Data as JSON: /api/errors/d97b0752cd59208b.
Report an issue: GitHub.
Appendix: source
Thrown at src/query/storages/common/session/src/temp_table.rs:101
pub db_name: String,
pub table_name: String,
pub meta: TableMeta,
pub copied_files: BTreeMap<String, TableCopiedFileInfo>,
}
impl TempTblMgr {
fn temp_table_desc(db_name: &str, table_name: &str) -> String {
format!("'{}'.'{}'", db_name, table_name)
}
pub fn init() -> Arc<Mutex<Self>> {
Arc::new(Mutex::new(Self::default()))
}
fn inc_next_id(&mut self) {
self.next_id += 1;
if !is_temp_table_id(self.next_id) {
panic!("Temp table id used up");
}
}
pub fn is_empty(&self) -> bool {
self.id_to_table.is_empty() && self.staged_tables.is_empty()
}
pub fn create_table(
&mut self,
req: CreateTableReq,
prefix: String,
) -> Result<CreateTableReply> {
let CreateTableReq {
create_option,
name_ident,
table_meta,
as_dropped,
..View on GitHub (pinned to 288d84d76e)