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

Commit

Permalink
Integrated index and constraint definition into the table objects. Ne…
Browse files Browse the repository at this point in the history
…ed to continue to implement.
  • Loading branch information
chotchki committed Aug 30, 2021
1 parent 6341c39 commit 028fe2e
Show file tree
Hide file tree
Showing 25 changed files with 621 additions and 290 deletions.
42 changes: 2 additions & 40 deletions benches/feophant_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,19 @@ use criterion::BenchmarkId;
use criterion::Criterion;
use criterion::{criterion_group, criterion_main};
use feophantlib::constants::Nullable;
use feophantlib::engine::get_row;
use feophantlib::engine::get_table;
use feophantlib::engine::io::row_formats::RowData;
use feophantlib::engine::io::FileManager;
use feophantlib::engine::io::LockCacheManager;
use feophantlib::engine::io::RowManager;
use feophantlib::engine::objects::types::BaseSqlTypes;
use feophantlib::engine::objects::types::BaseSqlTypesMapper;
use feophantlib::engine::objects::Attribute;
use feophantlib::engine::objects::SqlTuple;
use feophantlib::engine::objects::Table;
use feophantlib::engine::transactions::TransactionId;
use futures::pin_mut;
use std::sync::Arc;
use tempfile::TempDir;
use tokio::runtime::Builder;
use tokio_stream::StreamExt;

fn get_table() -> Arc<Table> {
Arc::new(Table::new(
uuid::Uuid::new_v4(),
"test_table".to_string(),
vec![
Attribute::new(
"header".to_string(),
BaseSqlTypesMapper::Text,
Nullable::NotNull,
None,
),
Attribute::new(
"id".to_string(),
BaseSqlTypesMapper::Uuid,
Nullable::Null,
None,
),
Attribute::new(
"header3".to_string(),
BaseSqlTypesMapper::Text,
Nullable::NotNull,
None,
),
],
))
}

fn get_row(input: String) -> SqlTuple {
SqlTuple(vec![
Some(BaseSqlTypes::Text(input)),
None,
Some(BaseSqlTypes::Text("blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah".to_string())),
])
}

// Here we have an async function to benchmark
async fn row_manager_mass_insert(row_count: usize) -> Result<(), Box<dyn std::error::Error>> {
let tmp = TempDir::new()?;
Expand Down
4 changes: 2 additions & 2 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ pub use pg_error_codes::PgErrorCodes;
mod pg_error_levels;
pub use pg_error_levels::PgErrorLevels;

mod table_definitions;
pub use table_definitions::TableDefinitions;
pub mod system_tables;
pub use system_tables::SystemTables;
35 changes: 35 additions & 0 deletions src/constants/system_tables.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//! This defines all the system internal tables so we can bootstrap the system.
use super::super::engine::objects::Table;
use std::sync::Arc;

pub mod pg_attribute;
pub mod pg_class;
pub mod pg_constraint;
pub mod pg_index;

#[derive(Copy, Clone)]
pub enum SystemTables {
PgAttribute, //Columns
PgClass, //Tables
PgConstraint,
PgIndex,
}

impl SystemTables {
//TODO Should this be removed?
pub const VALUES: [SystemTables; 4] = [
SystemTables::PgAttribute,
SystemTables::PgClass,
SystemTables::PgConstraint,
SystemTables::PgIndex,
];
pub fn value(self) -> Arc<Table> {
match self {
SystemTables::PgClass => pg_class::get_table(),
SystemTables::PgAttribute => pg_attribute::get_table(),
SystemTables::PgConstraint => pg_constraint::get_table(),
SystemTables::PgIndex => pg_index::get_table(),
}
}
}
76 changes: 76 additions & 0 deletions src/constants/system_tables/pg_attribute.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use crate::constants::Nullable;
use crate::engine::objects::{
types::{BaseSqlTypesMapper, SqlTypeDefinition},
Attribute, Constraint, Index, PrimaryKeyConstraint, Table,
};
use hex_literal::hex;
use std::sync::Arc;
use uuid::Uuid;

pub const id: Uuid = Uuid::from_bytes(hex!("EE89957F3E9F482C836DDA6C349AC632"));
pub const name: &str = "pg_attribute";

pub const column_class_id: &str = "class_id";
pub const column_name: &str = "name";
pub const column_sql_type: &str = "type_name";
pub const column_column_num: &str = "column_num";
pub const column_nullable: &str = "nullable";

pub fn get_columns() -> Vec<Attribute> {
vec![
Attribute::new(
column_class_id.to_string(),
BaseSqlTypesMapper::Uuid,
Nullable::NotNull,
None,
),
Attribute::new(
column_name.to_string(),
BaseSqlTypesMapper::Text,
Nullable::NotNull,
None,
),
Attribute::new(
column_sql_type.to_string(),
BaseSqlTypesMapper::Text, //TODO join to pg_type instead, for now its a string
Nullable::NotNull,
None,
),
Attribute::new(
column_column_num.to_string(),
BaseSqlTypesMapper::Integer,
Nullable::NotNull,
None,
),
Attribute::new(
column_nullable.to_string(),
BaseSqlTypesMapper::Bool,
Nullable::NotNull,
None,
),
]
}

pub fn get_index(attrs: &Vec<Attribute>) -> Arc<Index> {
Arc::new(Index {
id: Uuid::from_bytes(hex!("516B20412CF145A2AD9E39A8BDEB30A8")),
name: name.to_string() + "_name_index",
columns: Arc::new(SqlTypeDefinition::new(&[attrs[1].clone()])),
unique: true,
})
}

pub fn get_table() -> Arc<Table> {
let columns = get_columns();
let index = get_index(&columns);
Arc::new(Table::new(
id,
name.to_string(),
get_columns(),
vec![Constraint::PrimaryKey(PrimaryKeyConstraint {
name: index.name.clone() + "_primary_key",
index: index.clone(),
})],
vec![index],
))
}
55 changes: 55 additions & 0 deletions src/constants/system_tables/pg_class.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use crate::constants::Nullable;
use crate::engine::objects::{
types::{BaseSqlTypesMapper, SqlTypeDefinition},
Attribute, Constraint, Index, PrimaryKeyConstraint, Table,
};
use hex_literal::hex;
use std::sync::Arc;
use uuid::Uuid;

pub const id: Uuid = Uuid::from_bytes(hex!("EE919E33D9054F4889537EBB6CC911EB"));
pub const name: &str = "pg_class";

pub const column_id: &str = "id";
pub const column_name: &str = "name";

pub fn get_columns() -> Vec<Attribute> {
vec![
Attribute::new(
column_id.to_string(),
BaseSqlTypesMapper::Uuid,
Nullable::NotNull,
None,
),
Attribute::new(
column_name.to_string(),
BaseSqlTypesMapper::Text,
Nullable::NotNull,
None,
),
]
}

pub fn get_index(attrs: &Vec<Attribute>) -> Arc<Index> {
Arc::new(Index {
id: Uuid::from_bytes(hex!("516B20412CF145A2AD9E39A8BDEB30A8")),
name: name.to_string() + "_name_index",
columns: Arc::new(SqlTypeDefinition::new(&[attrs[1].clone()])),
unique: true,
})
}

pub fn get_table() -> Arc<Table> {
let columns = get_columns();
let index = get_index(&columns);
Arc::new(Table::new(
id,
name.to_string(),
columns,
vec![Constraint::PrimaryKey(PrimaryKeyConstraint {
name: name.to_string() + "_primary_key",
index: index.clone(),
})],
vec![index],
))
}
76 changes: 76 additions & 0 deletions src/constants/system_tables/pg_constraint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use crate::constants::Nullable;
use crate::engine::objects::{
types::{BaseSqlTypesMapper, SqlTypeDefinition},
Attribute, Constraint, Index, PrimaryKeyConstraint, Table,
};
use hex_literal::hex;
use std::sync::Arc;
use uuid::Uuid;

pub const id: Uuid = Uuid::from_bytes(hex!("DB6AB6BB401B4071BE52763C0C550600"));
pub const name: &str = "pg_constraint";

pub const column_id: &str = "id";
pub const column_class_id: &str = "class_id";
pub const column_index_id: &str = "index_id";
pub const column_name: &str = "name";
pub const column_type: &str = "type";

pub fn get_columns() -> Vec<Attribute> {
vec![
Attribute::new(
column_id.to_string(),
BaseSqlTypesMapper::Uuid,
Nullable::NotNull,
None,
),
Attribute::new(
column_class_id.to_string(),
BaseSqlTypesMapper::Uuid,
Nullable::NotNull,
None,
),
Attribute::new(
column_index_id.to_string(),
BaseSqlTypesMapper::Uuid,
Nullable::NotNull,
None,
),
Attribute::new(
column_name.to_string(),
BaseSqlTypesMapper::Text,
Nullable::NotNull,
None,
),
Attribute::new(
column_type.to_string(),
BaseSqlTypesMapper::Text,
Nullable::NotNull,
None,
),
]
}

pub fn get_index(attrs: &Vec<Attribute>) -> Arc<Index> {
Arc::new(Index {
id: Uuid::from_bytes(hex!("27182DE783AB42D8B5DD43BFC0154F0F")),
name: name.to_string() + "_name_index",
columns: Arc::new(SqlTypeDefinition::new(&[attrs[3].clone()])),
unique: true,
})
}

pub fn get_table() -> Arc<Table> {
let columns = get_columns();
let index = get_index(&columns);
Arc::new(Table::new(
id,
name.to_string(),
columns,
vec![Constraint::PrimaryKey(PrimaryKeyConstraint {
name: name.to_string() + "_primary_key",
index: index.clone(),
})],
vec![index],
))
}
76 changes: 76 additions & 0 deletions src/constants/system_tables/pg_index.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use crate::constants::Nullable;
use crate::engine::objects::{
types::{BaseSqlTypesMapper, SqlTypeDefinition},
Attribute, Constraint, Index, PrimaryKeyConstraint, Table,
};
use hex_literal::hex;
use std::sync::Arc;
use uuid::Uuid;

pub const id: Uuid = Uuid::from_bytes(hex!("3AB3B076A0EA46E186130F088D06FA02"));
pub const name: &str = "pg_index";

pub const column_id: &str = "id";
pub const column_class_id: &str = "class_id";
pub const column_name: &str = "name";
pub const column_attributes: &str = "attributes";
pub const column_unique: &str = "unique";

pub fn get_columns() -> Vec<Attribute> {
vec![
Attribute::new(
column_id.to_string(),
BaseSqlTypesMapper::Uuid,
Nullable::NotNull,
None,
),
Attribute::new(
column_class_id.to_string(),
BaseSqlTypesMapper::Uuid,
Nullable::NotNull,
None,
),
Attribute::new(
column_name.to_string(),
BaseSqlTypesMapper::Text,
Nullable::NotNull,
None,
),
Attribute::new(
column_attributes.to_string(),
BaseSqlTypesMapper::Array(Arc::new(BaseSqlTypesMapper::Integer)),
Nullable::NotNull,
None,
),
Attribute::new(
column_unique.to_string(),
BaseSqlTypesMapper::Bool,
Nullable::NotNull,
None,
),
]
}

pub fn get_index(attrs: &Vec<Attribute>) -> Arc<Index> {
Arc::new(Index {
id: Uuid::from_bytes(hex!("5F59466782874C568F1C0C09E99C9249")),
name: name.to_string() + "_name_index",
columns: Arc::new(SqlTypeDefinition::new(&[attrs[2].clone()])),
unique: true,
})
}

pub fn get_table() -> Arc<Table> {
let columns = get_columns();
let index = get_index(&columns);
Arc::new(Table::new(
id,
name.to_string(),
columns,
vec![Constraint::PrimaryKey(PrimaryKeyConstraint {
name: name.to_string() + "_primary_key",
index: index.clone(),
})],
vec![index],
))
}
Loading

0 comments on commit 028fe2e

Please sign in to comment.