Skip to content

Commit

Permalink
store: pass list of indexes when pruning a subgraph
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyasmohd authored and lutter committed Feb 11, 2025
1 parent 809eefb commit cd6d04c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
16 changes: 12 additions & 4 deletions store/postgres/src/relational/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,16 @@ pub struct IndexList {
pub(crate) indexes: HashMap<String, Vec<CreateIndex>>,
}

pub fn load_indexes_from_table(
conn: &mut PgConnection,
table: &Arc<Table>,
schema_name: &str,
) -> Result<Vec<CreateIndex>, StoreError> {
let table_name = table.name.as_str();
let indexes = catalog::indexes_for_table(conn, schema_name, table_name)?;
Ok(indexes.into_iter().map(CreateIndex::parse).collect())
}

impl IndexList {
pub fn load(
conn: &mut PgConnection,
Expand All @@ -746,10 +756,8 @@ impl IndexList {
let schema_name = site.namespace.clone();
let layout = store.layout(conn, site)?;
for (_, table) in &layout.tables {
let table_name = table.name.as_str();
let indexes = catalog::indexes_for_table(conn, schema_name.as_str(), table_name)?;
let collect: Vec<CreateIndex> = indexes.into_iter().map(CreateIndex::parse).collect();
list.indexes.insert(table_name.to_string(), collect);
let indexes = load_indexes_from_table(conn, table, schema_name.as_str())?;
list.indexes.insert(table.name.to_string(), indexes);
}
Ok(list)
}
Expand Down
15 changes: 12 additions & 3 deletions store/postgres/src/relational/prune.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fmt::Write, sync::Arc, time::Instant};
use std::{collections::HashMap, fmt::Write, sync::Arc, time::Instant};

use diesel::{
connection::SimpleConnection,
Expand All @@ -24,7 +24,10 @@ use crate::{
relational::{Table, VID_COLUMN},
};

use super::{Catalog, Layout, Namespace};
use super::{
index::{load_indexes_from_table, IndexList},
Catalog, Layout, Namespace,
};

// Additions to `Table` that are useful for pruning
impl Table {
Expand Down Expand Up @@ -94,9 +97,15 @@ impl TablePair {
if catalog::table_exists(conn, dst_nsp.as_str(), &dst.name)? {
writeln!(query, "truncate table {};", dst.qualified_name)?;
} else {
let mut list = IndexList {
indexes: HashMap::new(),
};
let indexes = load_indexes_from_table(conn, &src, dst_nsp.as_str())?;
list.indexes.insert(src.name.to_string(), indexes);

// In case of pruning we don't do delayed creation of indexes,
// as the asumption is that there is not that much data inserted.
dst.as_ddl(schema, catalog, None, &mut query)?;
dst.as_ddl(schema, catalog, Some(&list), &mut query)?;
}
conn.batch_execute(&query)?;

Expand Down

0 comments on commit cd6d04c

Please sign in to comment.