Skip to content

Commit

Permalink
0003817: Initial load use estimated counts
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Dec 6, 2018
1 parent 10cbda7 commit ff8b633
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Expand Up @@ -22,6 +22,8 @@

import javax.sql.DataSource;

import org.apache.commons.lang.StringUtils;
import org.jumpmind.db.model.Table;
import org.jumpmind.db.platform.DatabaseNamesConstants;
import org.jumpmind.db.platform.IDdlBuilder;
import org.jumpmind.db.sql.SqlTemplateSettings;
Expand All @@ -47,4 +49,14 @@ protected IDdlBuilder createDdlBuilder() {
public String getName() {
return DatabaseNamesConstants.MSSQL2008;
}

@Override
public long getEstimatedRowCount(Table table) {
String catalog = StringUtils.isNotBlank(table.getCatalog()) ? table.getCatalog() + "." : "";
return getSqlTemplateDirty().queryForLong("select sum(p.rows) from " + catalog + "sys.tables t inner join " +
catalog + "sys.partitions p on t.object_id = p.object_id and p.index_id IN (0, 1) " +
"where t.name = ? and schema_name(t.schema_id) = ?",
table.getName(), table.getSchema());
}

}
Expand Up @@ -4,6 +4,7 @@

import org.apache.commons.lang.StringUtils;
import org.jumpmind.db.model.Column;
import org.jumpmind.db.model.Table;
import org.jumpmind.db.platform.AbstractJdbcDatabasePlatform;
import org.jumpmind.db.platform.DatabaseNamesConstants;
import org.jumpmind.db.platform.PermissionResult;
Expand Down Expand Up @@ -111,6 +112,11 @@ public PermissionResult getExecuteSymPermission() {

return result;
}

}

@Override
public long getEstimatedRowCount(Table table) {
return getSqlTemplateDirty().queryForLong("select num_rows from all_tables where table_name = ? and owner = ?",
table.getName(), table.getSchema());
}

}

0 comments on commit ff8b633

Please sign in to comment.