Skip to content

Commit b27cc72

Browse files
committed
store: IndexList.indexes_for_table: split concurrent and if_not_exists
At the end of copying, we do not want to create indexes concurrently, but we do want the creation to be idempotent, i.e., have a 'if not exists' clause
1 parent eba4844 commit b27cc72

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

store/postgres/src/copy.rs

+1
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,7 @@ impl Connection {
731731
&table.dst,
732732
true,
733733
false,
734+
true,
734735
)?;
735736

736737
for (_, sql) in arr {

store/postgres/src/relational/ddl.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,14 @@ impl Table {
408408
if index_def.is_some() && ENV_VARS.postpone_attribute_index_creation {
409409
let arr = index_def
410410
.unwrap()
411-
.indexes_for_table(&self.nsp, &self.name.to_string(), &self, false, false)
411+
.indexes_for_table(
412+
&self.nsp,
413+
&self.name.to_string(),
414+
&self,
415+
false,
416+
false,
417+
false,
418+
)
412419
.map_err(|_| fmt::Error)?;
413420
for (_, sql) in arr {
414421
writeln!(out, "{};", sql).expect("properly formated index statements")

store/postgres/src/relational/ddl_tests.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -408,14 +408,28 @@ fn postponed_indexes_with_block_column() {
408408

409409
let dst_nsp = Namespace::new("sgd2".to_string()).unwrap();
410410
let arr = index_list()
411-
.indexes_for_table(&dst_nsp, &table.name.to_string(), &table, true, false)
411+
.indexes_for_table(
412+
&dst_nsp,
413+
&table.name.to_string(),
414+
&table,
415+
true,
416+
false,
417+
false,
418+
)
412419
.unwrap();
413420
assert_eq!(1, arr.len());
414421
assert!(!arr[0].1.contains(BLOCK_IDX));
415422
assert!(arr[0].1.contains(ATTR_IDX));
416423

417424
let arr = index_list()
418-
.indexes_for_table(&dst_nsp, &table.name.to_string(), &table, false, false)
425+
.indexes_for_table(
426+
&dst_nsp,
427+
&table.name.to_string(),
428+
&table,
429+
false,
430+
false,
431+
false,
432+
)
419433
.unwrap();
420434
assert_eq!(0, arr.len());
421435
}

store/postgres/src/relational/index.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,8 @@ impl IndexList {
784784
table_name: &String,
785785
dest_table: &Table,
786786
postponed: bool,
787-
concurrent_if_not_exist: bool,
787+
concurrent: bool,
788+
if_not_exists: bool,
788789
) -> Result<Vec<(Option<String>, String)>, Error> {
789790
let mut arr = vec![];
790791
if let Some(vec) = self.indexes.get(table_name) {
@@ -805,7 +806,7 @@ impl IndexList {
805806
{
806807
if let Ok(sql) = ci
807808
.with_nsp(namespace.to_string())?
808-
.to_sql(concurrent_if_not_exist, concurrent_if_not_exist)
809+
.to_sql(concurrent, if_not_exists)
809810
{
810811
arr.push((ci.name(), sql))
811812
}
@@ -829,7 +830,7 @@ impl IndexList {
829830
let namespace = &layout.catalog.site.namespace;
830831
for table in layout.tables.values() {
831832
for (ind_name, create_query) in
832-
self.indexes_for_table(namespace, &table.name.to_string(), table, true, true)?
833+
self.indexes_for_table(namespace, &table.name.to_string(), table, true, true, true)?
833834
{
834835
if let Some(index_name) = ind_name {
835836
let table_name = table.name.clone();

0 commit comments

Comments
 (0)