Skip to content

Commit f9aac6a

Browse files
authored
Avoid compute/store another fp on content if uuid is already the key. (#221)
1 parent 59c2d9b commit f9aac6a

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

src/base/schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ impl std::fmt::Display for FieldSchema {
359359
pub struct CollectorSchema {
360360
pub fields: Vec<FieldSchema>,
361361
/// If specified, the collector will have an automatically generated UUID field with the given index.
362-
pub auto_uuid_field_idx: Option<usize>,
362+
pub auto_uuid_field_idx: Option<u32>,
363363
}
364364

365365
impl std::fmt::Display for CollectorSchema {

src/builder/analyzer.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,12 @@ impl AnalyzerContext<'_> {
971971
})
972972
.transpose()?;
973973

974+
let value_stable = collector_schema
975+
.auto_uuid_field_idx
976+
.map(|uuid_idx| match &primary_key_def {
977+
AnalyzedPrimaryKeyDef::Fields(fields) => fields.contains(&uuid_idx),
978+
})
979+
.unwrap_or(false);
974980
Ok(async move {
975981
trace!("Start building executor for export op `{}`", export_op.name);
976982
let (executor, query_target) = executor_fut
@@ -990,6 +996,7 @@ impl AnalyzerContext<'_> {
990996
primary_key_def,
991997
primary_key_type,
992998
value_fields: value_fields_idx,
999+
value_stable,
9931000
})
9941001
})
9951002
}

src/builder/plan.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ pub struct AnalyzedExportOp {
109109
pub primary_key_type: ValueType,
110110
/// idx for value fields - excluding the primary key field.
111111
pub value_fields: Vec<u32>,
112+
/// If true, value is never changed on the same primary key.
113+
/// This is guaranteed if the primary key contains auto-generated UUIDs.
114+
pub value_stable: bool,
112115
}
113116

114117
pub enum AnalyzedReactiveOp {

src/execution/indexer.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,20 @@ async fn precommit_source_tracking_info(
226226
.fields
227227
.push(value.fields[*field as usize].clone());
228228
}
229-
let curr_fp = Some(
230-
Fingerprinter::default()
231-
.with(&field_values)?
232-
.into_fingerprint(),
233-
);
234-
235229
let existing_target_keys = target_info.existing_keys_info.remove(&primary_key_json);
236230
let existing_staging_target_keys = target_info
237231
.existing_staging_keys_info
238232
.remove(&primary_key_json);
239233

234+
let curr_fp = if !export_op.value_stable {
235+
Some(
236+
Fingerprinter::default()
237+
.with(&field_values)?
238+
.into_fingerprint(),
239+
)
240+
} else {
241+
None
242+
};
240243
if existing_target_keys
241244
.as_ref()
242245
.map(|keys| !keys.is_empty() && keys.iter().all(|(_, fp)| fp == &curr_fp))

0 commit comments

Comments
 (0)