row numbers in mssql

This commit is contained in:
Jan Prochazka
2022-02-10 18:35:26 +01:00
parent 849eff9e5b
commit 2ec962e2f1
4 changed files with 36 additions and 1 deletions

View File

@@ -75,9 +75,12 @@ class MsSqlAnalyser extends DatabaseAnalyser {
const indexesRows = await this.driver.query(this.pool, this.createQuery('indexes', ['tables']));
const indexcolsRows = await this.driver.query(this.pool, this.createQuery('indexcols', ['tables']));
const defaultSchemaRows = await this.driver.query(this.pool, 'SELECT SCHEMA_NAME() as name');
const tableSizes = await this.driver.query(this.pool, this.createQuery('tableSizes'));
const schemas = schemaRows.rows;
const tableSizesDict = _.mapValues(_.keyBy(tableSizes.rows, 'objectId'), 'tableRowCount');
const sqlCodeRows = await this.driver.query(
this.pool,
this.createQuery('loadSqlCode', ['views', 'procedures', 'functions', 'triggers'])
@@ -120,6 +123,7 @@ class MsSqlAnalyser extends DatabaseAnalyser {
..._.pick(col, ['columnName']),
})),
})),
tableRowCount: tableSizesDict[row.objectId],
}));
const views = viewsRows.rows.map(row => ({
@@ -157,6 +161,7 @@ class MsSqlAnalyser extends DatabaseAnalyser {
async _getFastSnapshot() {
const modificationsQueryData = await this.driver.query(this.pool, this.createQuery('modifications'));
const tableSizes = await this.driver.query(this.pool, this.createQuery('tableSizes'));
const res = DatabaseAnalyser.createEmptyStructure();
for (const item of modificationsQueryData.rows) {
@@ -171,6 +176,13 @@ class MsSqlAnalyser extends DatabaseAnalyser {
pureName,
});
}
for (const tableSize of tableSizes.rows) {
const table = (res.tables || []).find(x => x.objectId == tableSize.objectId);
if (table) {
table.tableRowCount = tableSize.tableRowCount;
}
}
return res;
}
}