mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-21 15:16:01 +00:00
foreign key loading optimalization #451
This commit is contained in:
@@ -57,7 +57,6 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
|
|
||||||
createQuery(resFileName, typeFields) {
|
createQuery(resFileName, typeFields) {
|
||||||
const query = super.createQuery(sql[resFileName], typeFields);
|
const query = super.createQuery(sql[resFileName], typeFields);
|
||||||
// if (query) return query.replace('#REFTABLECOND#', this.driver.__analyserInternals.refTableCond);
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,11 +78,6 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
|
|
||||||
let fkColumns = null;
|
let fkColumns = null;
|
||||||
|
|
||||||
// if (true) {
|
|
||||||
// if (this.containsObjectIdCondition(['tables']) || this.driver.__analyserInternals.refTableCond) {
|
|
||||||
// this.feedback({ analysingMessage: 'Loading foreign keys' });
|
|
||||||
// fkColumns = await this.driver.query(this.pool, this.createQuery('foreignKeys', ['tables']));
|
|
||||||
// } else {
|
|
||||||
this.feedback({ analysingMessage: 'Loading foreign key constraints' });
|
this.feedback({ analysingMessage: 'Loading foreign key constraints' });
|
||||||
const fk_tableConstraints = await this.driver.query(this.pool, this.createQuery('fk_tableConstraints', ['tables']));
|
const fk_tableConstraints = await this.driver.query(this.pool, this.createQuery('fk_tableConstraints', ['tables']));
|
||||||
|
|
||||||
@@ -133,7 +127,6 @@ class Analyser extends DatabaseAnalyser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fkColumns = { rows: fkRows };
|
fkColumns = { rows: fkRows };
|
||||||
// }
|
|
||||||
|
|
||||||
this.feedback({ analysingMessage: 'Loading views' });
|
this.feedback({ analysingMessage: 'Loading views' });
|
||||||
const views = await this.driver.query(this.pool, this.createQuery('views', ['views']));
|
const views = await this.driver.query(this.pool, this.createQuery('views', ['views']));
|
||||||
|
|||||||
@@ -78,8 +78,6 @@ const drivers = driverBases.map(driverBase => ({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('OPTIONS', options);
|
|
||||||
|
|
||||||
const client = new pg.Client(options);
|
const client = new pg.Client(options);
|
||||||
await client.connect();
|
await client.connect();
|
||||||
|
|
||||||
|
|||||||
@@ -7,4 +7,5 @@ select
|
|||||||
basecol.table_name,
|
basecol.table_name,
|
||||||
basecol.ordinal_position
|
basecol.ordinal_position
|
||||||
from information_schema.key_column_usage basecol
|
from information_schema.key_column_usage basecol
|
||||||
|
where ('tables:' || basecol.table_schema || '.' || basecol.table_name) =OBJECT_ID_CONDITION
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -5,4 +5,5 @@ select
|
|||||||
base.constraint_name as "constraint_name",
|
base.constraint_name as "constraint_name",
|
||||||
base.constraint_schema as "constraint_schema"
|
base.constraint_schema as "constraint_schema"
|
||||||
from information_schema.table_constraints base
|
from information_schema.table_constraints base
|
||||||
|
where ('tables:' || base.table_schema || '.' || base.table_name) =OBJECT_ID_CONDITION
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
module.exports = `
|
|
||||||
select
|
|
||||||
fk.constraint_name as "constraint_name",
|
|
||||||
fk.constraint_schema as "constraint_schema",
|
|
||||||
base.table_name as "pure_name",
|
|
||||||
base.table_schema as "schema_name",
|
|
||||||
fk.update_rule as "update_action",
|
|
||||||
fk.delete_rule as "delete_action",
|
|
||||||
ref.table_name as "ref_table_name",
|
|
||||||
ref.table_schema as "ref_schema_name",
|
|
||||||
basecol.column_name as "column_name",
|
|
||||||
refcol.column_name as "ref_column_name"
|
|
||||||
from information_schema.referential_constraints fk
|
|
||||||
inner join information_schema.table_constraints base on fk.constraint_name = base.constraint_name and fk.constraint_schema = base.constraint_schema
|
|
||||||
inner join information_schema.table_constraints ref on fk.unique_constraint_name = ref.constraint_name and fk.unique_constraint_schema = ref.constraint_schema #REFTABLECOND#
|
|
||||||
inner join information_schema.key_column_usage basecol on base.table_name = basecol.table_name and base.constraint_name = basecol.constraint_name
|
|
||||||
inner join information_schema.key_column_usage refcol on ref.table_name = refcol.table_name and ref.constraint_name = refcol.constraint_name and basecol.ordinal_position = refcol.ordinal_position
|
|
||||||
where
|
|
||||||
base.table_schema <> 'information_schema'
|
|
||||||
and base.table_schema <> 'pg_catalog'
|
|
||||||
and base.table_schema !~ '^pg_toast'
|
|
||||||
and ('tables:' || base.table_schema || '.' || base.table_name) =OBJECT_ID_CONDITION
|
|
||||||
order by basecol.ordinal_position
|
|
||||||
`;
|
|
||||||
@@ -4,7 +4,6 @@ const tableList = require('./tableList');
|
|||||||
const viewModifications = require('./viewModifications');
|
const viewModifications = require('./viewModifications');
|
||||||
const matviewModifications = require('./matviewModifications');
|
const matviewModifications = require('./matviewModifications');
|
||||||
const primaryKeys = require('./primaryKeys');
|
const primaryKeys = require('./primaryKeys');
|
||||||
const foreignKeys = require('./foreignKeys');
|
|
||||||
const views = require('./views');
|
const views = require('./views');
|
||||||
const matviews = require('./matviews');
|
const matviews = require('./matviews');
|
||||||
const routines = require('./routines');
|
const routines = require('./routines');
|
||||||
@@ -26,7 +25,6 @@ module.exports = {
|
|||||||
tableList,
|
tableList,
|
||||||
viewModifications,
|
viewModifications,
|
||||||
primaryKeys,
|
primaryKeys,
|
||||||
foreignKeys,
|
|
||||||
fk_keyColumnUsage,
|
fk_keyColumnUsage,
|
||||||
fk_referentialConstraints,
|
fk_referentialConstraints,
|
||||||
fk_tableConstraints,
|
fk_tableConstraints,
|
||||||
|
|||||||
@@ -140,9 +140,7 @@ const postgresDriverBase = {
|
|||||||
return connection;
|
return connection;
|
||||||
},
|
},
|
||||||
|
|
||||||
__analyserInternals: {
|
__analyserInternals: {},
|
||||||
refTableCond: '',
|
|
||||||
},
|
|
||||||
|
|
||||||
getNewObjectTemplates() {
|
getNewObjectTemplates() {
|
||||||
return [
|
return [
|
||||||
@@ -212,9 +210,7 @@ const cockroachDriver = {
|
|||||||
dropColumnDependencies: ['primaryKey', 'dependencies'],
|
dropColumnDependencies: ['primaryKey', 'dependencies'],
|
||||||
dropPrimaryKey: false,
|
dropPrimaryKey: false,
|
||||||
},
|
},
|
||||||
__analyserInternals: {
|
__analyserInternals: {},
|
||||||
refTableCond: 'and fk.referenced_table_name = ref.table_name',
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @type {import('dbgate-types').EngineDriver} */
|
/** @type {import('dbgate-types').EngineDriver} */
|
||||||
@@ -225,7 +221,6 @@ const redshiftDriver = {
|
|||||||
stringAgg: false,
|
stringAgg: false,
|
||||||
},
|
},
|
||||||
__analyserInternals: {
|
__analyserInternals: {
|
||||||
refTableCond: '',
|
|
||||||
skipIndexes: true,
|
skipIndexes: true,
|
||||||
},
|
},
|
||||||
engine: 'redshift@dbgate-plugin-postgres',
|
engine: 'redshift@dbgate-plugin-postgres',
|
||||||
|
|||||||
Reference in New Issue
Block a user