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

Method insert_if_absent

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

`INSERT ... ON CONFLICT DO NOTHING` semantics: append only if the PK is absent; silently skip on duplicate. Returns `Ok(MutationResult { wal_records })` with an empty vector when the row was skipped, so callers that batch WAL appends can detect no-ops by checking `wal_records.is_empty()`.

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

Source from the content-addressed store, hash-verified

120 /// when the row was skipped, so callers that batch WAL appends can
121 /// detect no-ops by checking `wal_records.is_empty()`.
122 pub fn insert_if_absent(&mut self, values: &[Value]) -> Result<MutationResult, ColumnarError> {
123 let pk_bytes = self.extract_pk_bytes(values)?;
124 if self.pk_index.contains(&pk_bytes) {
125 return Ok(MutationResult {
126 wal_records: Vec::new(),
127 });
128 }
129
130 let row_data = encode_row_for_wal(values)?;
131 let wal = ColumnarWalRecord::InsertRow {
132 collection: self.collection.clone(),
133 row_data,
134 };
135 self.memtable.append_row(values)?;
136 let location = RowLocation {
137 segment_id: self.memtable_segment_id,
138 row_index: self.memtable_row_counter,
139 };
140 self.pk_index.upsert(pk_bytes, location);
141 self.memtable_surrogates.push(None);
142 self.memtable_row_counter += 1;
143
144 Ok(MutationResult {
145 wal_records: vec![wal],
146 })
147 }
148
149 /// Look up the current row for a PK in the memtable, if present.
150 ///

Callers 1

Calls 7

encode_row_for_walFunction · 0.85
extract_pk_bytesMethod · 0.80
append_rowMethod · 0.80
containsMethod · 0.45
cloneMethod · 0.45
upsertMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected