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

@@ -579,6 +579,12 @@
};
});
}
function formatRowCount(value) {
const num = parseInt(value);
if (_.isNaN(num)) return value;
return num.toLocaleString();
}
</script>
<script lang="ts">
@@ -627,7 +633,7 @@
showPinnedInsteadOfUnpin={passProps?.showPinnedInsteadOfUnpin}
onPin={isPinned ? null : () => pinnedTables.update(list => [...list, data])}
onUnpin={isPinned ? () => pinnedTables.update(list => list.filter(x => !testEqual(x, data))) : null}
extInfo={data.tableRowCount != null ? `${data.tableRowCount} rows` : null}
extInfo={data.tableRowCount != null ? `${formatRowCount(data.tableRowCount)} rows` : null}
on:click={() => handleClick()}
on:middleclick={() => handleClick(true)}
on:expand

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;
}
}

View File

@@ -2,6 +2,7 @@ const columns = require('./columns');
const foreignKeys = require('./foreignKeys');
const primaryKeys = require('./primaryKeys');
const tables = require('./tables');
const tableSizes = require('./tableSizes');
const modifications = require('./modifications');
const loadSqlCode = require('./loadSqlCode');
const views = require('./views');
@@ -24,4 +25,5 @@ module.exports = {
getSchemas,
indexes,
indexcols,
tableSizes,
};

View File

@@ -0,0 +1,15 @@
module.exports = `
SELECT distinct
t.object_id as objectId,
p.rows AS tableRowCount
FROM
sys.tables t
INNER JOIN
sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN
sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
WHERE
t.NAME NOT LIKE 'dt%'
AND t.is_ms_shipped = 0
AND i.OBJECT_ID > 255
`;