Skip to content

Commit cd6d04c

Browse files
shiyasmohdlutter
authored andcommitted
store: pass list of indexes when pruning a subgraph
1 parent 809eefb commit cd6d04c

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

store/postgres/src/relational/index.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,16 @@ pub struct IndexList {
734734
pub(crate) indexes: HashMap<String, Vec<CreateIndex>>,
735735
}
736736

737+
pub fn load_indexes_from_table(
738+
conn: &mut PgConnection,
739+
table: &Arc<Table>,
740+
schema_name: &str,
741+
) -> Result<Vec<CreateIndex>, StoreError> {
742+
let table_name = table.name.as_str();
743+
let indexes = catalog::indexes_for_table(conn, schema_name, table_name)?;
744+
Ok(indexes.into_iter().map(CreateIndex::parse).collect())
745+
}
746+
737747
impl IndexList {
738748
pub fn load(
739749
conn: &mut PgConnection,
@@ -746,10 +756,8 @@ impl IndexList {
746756
let schema_name = site.namespace.clone();
747757
let layout = store.layout(conn, site)?;
748758
for (_, table) in &layout.tables {
749-
let table_name = table.name.as_str();
750-
let indexes = catalog::indexes_for_table(conn, schema_name.as_str(), table_name)?;
751-
let collect: Vec<CreateIndex> = indexes.into_iter().map(CreateIndex::parse).collect();
752-
list.indexes.insert(table_name.to_string(), collect);
759+
let indexes = load_indexes_from_table(conn, table, schema_name.as_str())?;
760+
list.indexes.insert(table.name.to_string(), indexes);
753761
}
754762
Ok(list)
755763
}

store/postgres/src/relational/prune.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{fmt::Write, sync::Arc, time::Instant};
1+
use std::{collections::HashMap, fmt::Write, sync::Arc, time::Instant};
22

33
use diesel::{
44
connection::SimpleConnection,
@@ -24,7 +24,10 @@ use crate::{
2424
relational::{Table, VID_COLUMN},
2525
};
2626

27-
use super::{Catalog, Layout, Namespace};
27+
use super::{
28+
index::{load_indexes_from_table, IndexList},
29+
Catalog, Layout, Namespace,
30+
};
2831

2932
// Additions to `Table` that are useful for pruning
3033
impl Table {
@@ -94,9 +97,15 @@ impl TablePair {
9497
if catalog::table_exists(conn, dst_nsp.as_str(), &dst.name)? {
9598
writeln!(query, "truncate table {};", dst.qualified_name)?;
9699
} else {
100+
let mut list = IndexList {
101+
indexes: HashMap::new(),
102+
};
103+
let indexes = load_indexes_from_table(conn, &src, dst_nsp.as_str())?;
104+
list.indexes.insert(src.name.to_string(), indexes);
105+
97106
// In case of pruning we don't do delayed creation of indexes,
98107
// as the asumption is that there is not that much data inserted.
99-
dst.as_ddl(schema, catalog, None, &mut query)?;
108+
dst.as_ddl(schema, catalog, Some(&list), &mut query)?;
100109
}
101110
conn.batch_execute(&query)?;
102111

0 commit comments

Comments
 (0)