Skip to content

Commit

Permalink
Add a 2-pass approach to cleaning SQL Server indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
DoodleBobBuffPants committed Mar 9, 2021
1 parent 9033185 commit 7f492a5
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,14 @@ protected void doClean() throws SQLException {
jdbcTemplate.execute(statement);
}

// Use a 2-pass approach for cleaning indexes that cannot be dropped until the corresponding table is dropped
// Pass 1
for (String statement : cleanIndexes(tables)) {
jdbcTemplate.execute(statement);
try {
jdbcTemplate.execute(statement);
} catch (SQLException e) {
LOG.debug("Ignoring dropping index. Error: " + e.getMessage());
}
}

// Use a 2-pass approach for cleaning computed columns and functions with SCHEMABINDING due to dependency errors
Expand All @@ -258,7 +264,7 @@ protected void doClean() throws SQLException {
}
}

// Pass 2
// Pass 2 for cleaning computed columns and functions
for (String statement : cleanComputedColumns(tables)) {
jdbcTemplate.execute(statement);
}
Expand Down Expand Up @@ -290,6 +296,11 @@ protected void doClean() throws SQLException {
table.drop();
}

// Pass 2 for cleaning indexes
for (String statement : cleanIndexes(tables)) {
jdbcTemplate.execute(statement);
}

for (String statement : cleanObjects("AGGREGATE", ObjectType.AGGREGATE)) {
jdbcTemplate.execute(statement);
}
Expand Down

0 comments on commit 7f492a5

Please sign in to comment.