Skip to content
This repository has been archived by the owner on Apr 15, 2023. It is now read-only.

Commit

Permalink
I have a working primary key constraint!!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
chotchki committed Oct 10, 2021
1 parent 75fcab9 commit efa726e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/engine/io/constraint_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ impl ConstraintManager {
for c in &table.constraints {
match c {
crate::engine::objects::Constraint::PrimaryKey(p) => {
debug!("searching for {:?}", user_data);
match self
.index_manager
.search_for_key(
Expand All @@ -88,7 +89,7 @@ impl ConstraintManager {
//We need to check if each of these rows are alive
if self
.vis_row_man
.any_visible(&table, current_tran_id, &rows)
.any_visible(table, current_tran_id, &rows)
.await?
{
return Err(ConstraintManagerError::PrimaryKeyViolation());
Expand All @@ -98,18 +99,32 @@ impl ConstraintManager {
continue;
}
}

//TODO So for a primary key we have to check for no other dups in the table

//So what I want to do is ask the index manager to to get active rows matching the key
}
}
}

Ok(self
//Insert the row
let row_item_ptr = self
.vis_row_man
.insert_row(current_tran_id, table, user_data)
.await?)
.insert_row(current_tran_id, table, user_data.clone())
.await?;

//Update the indexes
//TODO figure out if that makes sense in this layer
for i in &table.indexes {
let tuple_for_index = match user_data.clone().filter_map(&table.sql_type, &i.columns) {
Ok(u) => u,
Err(_) => {
continue;
}
};

self.index_manager
.add(i, tuple_for_index, row_item_ptr)
.await?;
}

Ok(row_item_ptr)
}

/// Gets a specific tuple from below, at the moment just a passthrough
Expand Down
2 changes: 2 additions & 0 deletions src/engine/io/index_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ impl IndexManager {
page_type: PageType::Data,
};

debug!("index searching for {:?}", key);

let (mut first_page, _first_guard) =
match self.file_manager.get_page(&page_id, &PageOffset(0)).await {
Ok(s) => s,
Expand Down

0 comments on commit efa726e

Please sign in to comment.