From 7850cc566fb6b0352c3b121df81c19734d97e06a Mon Sep 17 00:00:00 2001 From: WenyXu Date: Fri, 20 Sep 2024 06:16:29 +0000 Subject: [PATCH] feat: last insert schema hash cache --- src/operator/src/insert.rs | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/operator/src/insert.rs b/src/operator/src/insert.rs index e371a9d6645f..db2496df6c4e 100644 --- a/src/operator/src/insert.rs +++ b/src/operator/src/insert.rs @@ -647,6 +647,28 @@ impl Inserter { .context(CatalogSnafu) } + fn request_schema_hash(request_schema: &[ColumnSchema]) -> Vec { + 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, @@ -698,22 +720,6 @@ impl Inserter { Ok(create_table_expr) } - fn request_schema_hash(request_schema: &[ColumnSchema]) -> Vec { - 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,