MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / insert_with_surrogate

Method insert_with_surrogate

nodedb-columnar/src/mutation/write.rs:79–114  ·  view source on GitHub ↗

Insert with a stable cross-engine surrogate identity. Identical to [`Self::insert`] but also records `surrogate` in the per-row side-table so scan prefilters can perform bitmap membership checks without a separate lookup pass.

(
        &mut self,
        values: &[Value],
        surrogate: Surrogate,
    )

Source from the content-addressed store, hash-verified

77 /// per-row side-table so scan prefilters can perform bitmap membership
78 /// checks without a separate lookup pass.
79 pub fn insert_with_surrogate(
80 &mut self,
81 values: &[Value],
82 surrogate: Surrogate,
83 ) -> Result<MutationResult, ColumnarError> {
84 let pk_bytes = self.extract_pk_bytes(values)?;
85 let mut wal_records = Vec::with_capacity(2);
86
87 let bitemporal = self.schema.is_bitemporal();
88 if !bitemporal && let Some(prior) = self.pk_index.get(&pk_bytes).copied() {
89 let bitmap = self.delete_bitmaps.entry(prior.segment_id).or_default();
90 bitmap.mark_deleted(prior.row_index);
91 wal_records.push(ColumnarWalRecord::DeleteRows {
92 collection: self.collection.clone(),
93 segment_id: prior.segment_id,
94 row_indices: vec![prior.row_index],
95 });
96 }
97
98 let row_data = encode_row_for_wal(values)?;
99 wal_records.push(ColumnarWalRecord::InsertRow {
100 collection: self.collection.clone(),
101 row_data,
102 });
103
104 self.memtable.append_row(values)?;
105 let location = RowLocation {
106 segment_id: self.memtable_segment_id,
107 row_index: self.memtable_row_counter,
108 };
109 self.pk_index.upsert(pk_bytes, location);
110 self.memtable_surrogates.push(Some(surrogate));
111 self.memtable_row_counter += 1;
112
113 Ok(MutationResult { wal_records })
114 }
115
116 /// `INSERT ... ON CONFLICT DO NOTHING` semantics: append only if the
117 /// PK is absent; silently skip on duplicate.

Calls 10

encode_row_for_walFunction · 0.85
extract_pk_bytesMethod · 0.80
entryMethod · 0.80
append_rowMethod · 0.80
is_bitemporalMethod · 0.45
getMethod · 0.45
mark_deletedMethod · 0.45
pushMethod · 0.45
cloneMethod · 0.45
upsertMethod · 0.45