Skip to content

Commit

Permalink
feat: last insert schema hash cache
Browse files Browse the repository at this point in the history
  • Loading branch information
WenyXu committed Sep 24, 2024
1 parent 4024860 commit 7850cc5
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/operator/src/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,28 @@ impl Inserter {
.context(CatalogSnafu)
}

fn request_schema_hash(request_schema: &[ColumnSchema]) -> Vec<u8> {
let mut hasher = Sha256::new();
for schema in request_schema {
hasher.update(&schema.column_name);
}
hasher.finalize().to_vec()
}

fn has_same_schema(&self, table_id: TableId, request_schema: &[ColumnSchema]) -> bool {
let request_schema_hash = Arc::new(Self::request_schema_hash(request_schema));
let last_insert_schema_hash = self.last_insert_schema_hash_cache.get(&table_id);
let same_schema = last_insert_schema_hash
.map(|hash| hash == request_schema_hash)
.unwrap_or_default();

if !same_schema {
self.last_insert_schema_hash_cache
.insert(table_id, request_schema_hash);
}
same_schema
}

fn get_create_table_expr_on_demand(
&self,
req: &RowInsertRequest,
Expand Down Expand Up @@ -698,22 +720,6 @@ impl Inserter {
Ok(create_table_expr)
}

fn request_schema_hash(request_schema: &[ColumnSchema]) -> Vec<u8> {
let mut hasher = Sha256::new();
for schema in request_schema {
hasher.update(&schema.column_name);
}
hasher.finalize().to_vec()
}

fn has_same_schema(&self, table_id: TableId, request_schema: &[ColumnSchema]) -> bool {
let request_schema_hash = Arc::new(Self::request_schema_hash(request_schema));
let last_insert_schema_hash = self
.last_insert_schema_hash_cache
.get_with(table_id, || request_schema_hash.clone());
request_schema_hash == last_insert_schema_hash
}

fn get_alter_table_expr_on_demand(
&self,
req: &RowInsertRequest,
Expand Down

0 comments on commit 7850cc5

Please sign in to comment.