Back to all reviewers

Stable schema identifiers

influxdata/influxdb
Based on 5 comments
Rust

Use persistent identifiers for schema elements rather than relying on positional information or enumeration, which can break when schema changes occur. Assign unique, immutable IDs to database objects like tables and columns, and ensure these IDs remain stable throughout the object's lifecycle.

Database Rust

Reviewer Prompt

Use persistent identifiers for schema elements rather than relying on positional information or enumeration, which can break when schema changes occur. Assign unique, immutable IDs to database objects like tables and columns, and ensure these IDs remain stable throughout the object’s lifecycle.

For example, instead of:

// Problematic - using enumeration for column IDs
.enumerate()
.map(|(idx, (col_type, f))| {
    // Using idx as column ID is dangerous
    ColumnDefinition::new(idx, f.name(), col_type, f.is_nullable())
})

Use a system that generates and persists stable IDs:

// Better - using dedicated ID generation
let column_id = table_def.next_column_id();
ColumnDefinition::new(column_id, f.name(), col_type, f.is_nullable())

When designing schema access patterns, minimize catalog locks by including ID-to-name mappings in cached schema objects. Use IDs for internal lookups and operations for performance, while preserving names for user-facing interfaces. When serializing schema objects, ensure both IDs and names are properly preserved to maintain the mapping integrity.

During schema changes like adding columns, preserve existing IDs and assign new IDs to new elements, rather than reassigning all IDs. This guarantees that references to existing columns remain valid even as the schema evolves.

5
Comments Analyzed
Rust
Primary Language
Database
Category

Source Discussions