mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 10:53:57 +00:00
postgre sql indexes analysis - partialy working
This commit is contained in:
@@ -6,6 +6,6 @@ module.exports = `
|
|||||||
INDEX_TYPE AS indexType,
|
INDEX_TYPE AS indexType,
|
||||||
NON_UNIQUE AS nonUnique
|
NON_UNIQUE AS nonUnique
|
||||||
FROM INFORMATION_SCHEMA.STATISTICS
|
FROM INFORMATION_SCHEMA.STATISTICS
|
||||||
WHERE TABLE_SCHEMA = '#DATABASE#' AND TABLE_NAME =OBJECT_ID_CONDITION AND INDEX_NAME != 'PRIMARY' AND INDEX_NAME NOT LIKE 'IFK_%'
|
WHERE TABLE_SCHEMA = '#DATABASE#' AND TABLE_NAME =OBJECT_ID_CONDITION AND INDEX_NAME != 'PRIMARY'
|
||||||
ORDER BY SEQ_IN_INDEX
|
ORDER BY SEQ_IN_INDEX
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
? await this.driver.query(this.pool, this.createQuery('matviewColumns', ['matviews']))
|
? await this.driver.query(this.pool, this.createQuery('matviewColumns', ['matviews']))
|
||||||
: null;
|
: null;
|
||||||
const routines = await this.driver.query(this.pool, this.createQuery('routines', ['procedures', 'functions']));
|
const routines = await this.driver.query(this.pool, this.createQuery('routines', ['procedures', 'functions']));
|
||||||
|
const indexes = await this.driver.query(this.pool, this.createQuery('indexes', ['tables']));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
tables: tables.rows.map(table => {
|
tables: tables.rows.map(table => {
|
||||||
@@ -104,6 +105,13 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
refSchemaName: x.ref_schema_name,
|
refSchemaName: x.ref_schema_name,
|
||||||
}))
|
}))
|
||||||
),
|
),
|
||||||
|
indexes: indexes.rows
|
||||||
|
.filter(x => x.table_name == table.pure_name && x.schema_name == table.schema_name)
|
||||||
|
.map(idx => ({
|
||||||
|
constraintName: idx.index_name,
|
||||||
|
isUnique: idx.is_unique,
|
||||||
|
columns: idx.column_names.split('|').map(columnName => ({ columnName })),
|
||||||
|
})),
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
views: views.rows.map(view => ({
|
views: views.rows.map(view => ({
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ const matviews = require('./matviews');
|
|||||||
const routines = require('./routines');
|
const routines = require('./routines');
|
||||||
const routineModifications = require('./routineModifications');
|
const routineModifications = require('./routineModifications');
|
||||||
const matviewColumns = require('./matviewColumns');
|
const matviewColumns = require('./matviewColumns');
|
||||||
|
const indexes = require('./indexes');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
columns,
|
columns,
|
||||||
@@ -24,4 +25,5 @@ module.exports = {
|
|||||||
matviews,
|
matviews,
|
||||||
matviewModifications,
|
matviewModifications,
|
||||||
matviewColumns,
|
matviewColumns,
|
||||||
|
indexes,
|
||||||
};
|
};
|
||||||
|
|||||||
35
plugins/dbgate-plugin-postgres/src/backend/sql/indexes.js
Normal file
35
plugins/dbgate-plugin-postgres/src/backend/sql/indexes.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
module.exports = `
|
||||||
|
select
|
||||||
|
t.relname as "table_name",
|
||||||
|
c.nspname as "schema_name",
|
||||||
|
i.relname as "index_name",
|
||||||
|
ix.indisprimary as "is_primary",
|
||||||
|
ix.indisunique as "is_unique",
|
||||||
|
array_to_string(array_agg(a.attname), '|') as "column_names"
|
||||||
|
from
|
||||||
|
pg_class t,
|
||||||
|
pg_class i,
|
||||||
|
pg_index ix,
|
||||||
|
pg_attribute a,
|
||||||
|
pg_namespace c
|
||||||
|
where
|
||||||
|
t.oid = ix.indrelid
|
||||||
|
and i.oid = ix.indexrelid
|
||||||
|
and a.attrelid = t.oid
|
||||||
|
and a.attnum = ANY(ix.indkey)
|
||||||
|
and t.relkind = 'r'
|
||||||
|
and ix.indisprimary = false
|
||||||
|
and t.relnamespace = c.oid
|
||||||
|
and c.nspname != 'pg_catalog'
|
||||||
|
and ('tables:' || c.nspname || '.' || t.relname) =OBJECT_ID_CONDITION
|
||||||
|
group by
|
||||||
|
i.oid,
|
||||||
|
t.relname,
|
||||||
|
i.relname,
|
||||||
|
c.nspname,
|
||||||
|
ix.indisprimary,
|
||||||
|
ix.indisunique
|
||||||
|
order by
|
||||||
|
t.relname,
|
||||||
|
i.relname
|
||||||
|
`;
|
||||||
Reference in New Issue
Block a user