foreign key loading optimalization #451

This commit is contained in:
Jan Prochazka
2023-01-21 09:34:29 +01:00
parent 451f671426
commit 3dfae351a6
7 changed files with 4 additions and 42 deletions

View File

@@ -57,7 +57,6 @@ class Analyser extends DatabaseAnalyser {
createQuery(resFileName, typeFields) {
const query = super.createQuery(sql[resFileName], typeFields);
// if (query) return query.replace('#REFTABLECOND#', this.driver.__analyserInternals.refTableCond);
return query;
}
@@ -79,11 +78,6 @@ class Analyser extends DatabaseAnalyser {
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' });
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 };
// }
this.feedback({ analysingMessage: 'Loading views' });
const views = await this.driver.query(this.pool, this.createQuery('views', ['views']));

View File

@@ -78,8 +78,6 @@ const drivers = driverBases.map(driverBase => ({
};
}
console.log('OPTIONS', options);
const client = new pg.Client(options);
await client.connect();

View File

@@ -7,4 +7,5 @@ select
basecol.table_name,
basecol.ordinal_position
from information_schema.key_column_usage basecol
where ('tables:' || basecol.table_schema || '.' || basecol.table_name) =OBJECT_ID_CONDITION
`;

View File

@@ -5,4 +5,5 @@ select
base.constraint_name as "constraint_name",
base.constraint_schema as "constraint_schema"
from information_schema.table_constraints base
where ('tables:' || base.table_schema || '.' || base.table_name) =OBJECT_ID_CONDITION
`;

View File

@@ -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
`;

View File

@@ -4,7 +4,6 @@ const tableList = require('./tableList');
const viewModifications = require('./viewModifications');
const matviewModifications = require('./matviewModifications');
const primaryKeys = require('./primaryKeys');
const foreignKeys = require('./foreignKeys');
const views = require('./views');
const matviews = require('./matviews');
const routines = require('./routines');
@@ -26,7 +25,6 @@ module.exports = {
tableList,
viewModifications,
primaryKeys,
foreignKeys,
fk_keyColumnUsage,
fk_referentialConstraints,
fk_tableConstraints,

View File

@@ -140,9 +140,7 @@ const postgresDriverBase = {
return connection;
},
__analyserInternals: {
refTableCond: '',
},
__analyserInternals: {},
getNewObjectTemplates() {
return [
@@ -212,9 +210,7 @@ const cockroachDriver = {
dropColumnDependencies: ['primaryKey', 'dependencies'],
dropPrimaryKey: false,
},
__analyserInternals: {
refTableCond: 'and fk.referenced_table_name = ref.table_name',
},
__analyserInternals: {},
};
/** @type {import('dbgate-types').EngineDriver} */
@@ -225,7 +221,6 @@ const redshiftDriver = {
stringAgg: false,
},
__analyserInternals: {
refTableCond: '',
skipIndexes: true,
},
engine: 'redshift@dbgate-plugin-postgres',