Skip to content

Commit d0a8e87

Browse files
Fix primary_key and rid confusion
1 parent bb48ff5 commit d0a8e87

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

simple_tester.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@
2828
print(vals)
2929

3030
for x in range(0, 8):
31-
print(f"query.sum(13, 17, {x})", query.sum(13, 17, x))
31+
print(f"query.sum(15, 17, {x})", query.sum(15, 17, x))

src/database.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,15 @@ pub struct RTable {
111111
impl RTable {
112112
pub fn write(&mut self, values: Vec<u64>) -> Record {
113113
// Use the primary_key_column'th value as the given key
114-
let given_key = values[self.primary_key_column];
115-
let rec = self.page_range.write(self.num_records, values);
114+
let primary_key = values[self.primary_key_column];
115+
116+
let rid = self.num_records;
117+
self.index.add(primary_key, rid);
118+
119+
let rec = self.page_range.write(rid, values);
116120

117121
// Save the RID -> Record so it can later be read
118-
self.page_directory.insert(given_key, rec.clone());
122+
self.page_directory.insert(rid, rec.clone());
119123

120124
self.num_records += 1;
121125
return rec;
@@ -153,13 +157,8 @@ impl RTable {
153157
// Make sum range inclusive
154158
// TODO: Validate this assumption if it should actually be inclusive
155159
for primary_key in start_primary_key..end_primary_key + 1 {
156-
// Lookup RID from primary_key
157-
let rid = self.index.get(primary_key);
158-
159-
if let Some(r) = rid {
160-
if let Some(v) = self.read(*r) {
161-
agg += v[col_index as usize] as i64;
162-
}
160+
if let Some(v) = self.read(primary_key) {
161+
agg += v[col_index as usize] as i64;
163162
}
164163
}
165164

0 commit comments

Comments
 (0)