Skip to content

Commit

Permalink
Merge pull request #308 from wmanley/sqlite-indexes
Browse files Browse the repository at this point in the history
Storage: Add Indexes for common queries
  • Loading branch information
hendrikvanantwerpen authored Aug 9, 2023
2 parents ee490e9 + ddafce4 commit a4a726d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Douglas Creager <[email protected]>
Hendrik van Antwerpen <[email protected]>
Akshay <[email protected]>
blusk <[email protected]>
William Manley <[email protected]>
18 changes: 17 additions & 1 deletion stack-graphs/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ const SCHEMA: &str = r#"
) STRICT;
"#;

const INDEXES: &str = r#"
CREATE INDEX IF NOT EXISTS idx_graphs_file ON graphs(file);
CREATE INDEX IF NOT EXISTS idx_file_paths_local_id ON file_paths(file, local_id);
CREATE INDEX IF NOT EXISTS idx_root_paths_symbol_stack ON root_paths(symbol_stack);
"#;

const PRAGMAS: &str = r#"
PRAGMA journal_mode = WAL;
PRAGMA foreign_keys = false;
Expand Down Expand Up @@ -147,6 +153,7 @@ impl SQLiteWriter {
pub fn open_in_memory() -> Result<Self> {
let mut conn = Connection::open_in_memory()?;
Self::init(&mut conn)?;
init_indexes(&mut conn)?;
Ok(Self { conn })
}

Expand All @@ -161,6 +168,7 @@ impl SQLiteWriter {
} else {
check_version(&conn)?;
}
init_indexes(&mut conn)?;
Ok(Self { conn })
}

Expand Down Expand Up @@ -432,9 +440,10 @@ impl SQLiteReader {
path.as_ref().to_string_lossy().to_string(),
));
}
let conn = Connection::open(path)?;
let mut conn = Connection::open(path)?;
set_pragmas_and_functions(&conn)?;
check_version(&conn)?;
init_indexes(&mut conn)?;
Ok(Self {
conn,
loaded_graphs: HashSet::new(),
Expand Down Expand Up @@ -781,6 +790,13 @@ fn set_pragmas_and_functions(conn: &Connection) -> Result<()> {
Ok(())
}

fn init_indexes(conn: &mut Connection) -> Result<()> {
let tx = conn.transaction()?;
tx.execute_batch(INDEXES)?;
tx.commit()?;
Ok(())
}

fn status_for_file<T: AsRef<str>>(
conn: &Connection,
file: &str,
Expand Down

0 comments on commit a4a726d

Please sign in to comment.