From ee7198a9137cfcd720efc974a41c7a420ae891af Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Thu, 2 Jun 2022 12:02:54 +0200 Subject: [PATCH] analyse mysql views optimalization #273 --- .../src/backend/Analyser.js | 22 ++++++++++++------- .../src/backend/sql/index.js | 2 ++ .../src/backend/sql/viewTexts.js | 7 ++++++ 3 files changed, 23 insertions(+), 8 deletions(-) create mode 100644 plugins/dbgate-plugin-mysql/src/backend/sql/viewTexts.js diff --git a/plugins/dbgate-plugin-mysql/src/backend/Analyser.js b/plugins/dbgate-plugin-mysql/src/backend/Analyser.js index a09e5a04..f0f8edae 100644 --- a/plugins/dbgate-plugin-mysql/src/backend/Analyser.js +++ b/plugins/dbgate-plugin-mysql/src/backend/Analyser.js @@ -56,15 +56,21 @@ class Analyser extends DatabaseAnalyser { async getViewTexts(allViewNames) { const res = {}; - for (const viewName of this.getRequestedViewNames(allViewNames)) { - try { - const resp = await this.driver.query(this.pool, `SHOW CREATE VIEW \`${viewName}\``); - res[viewName] = resp.rows[0]['Create View']; - } catch (err) { - console.log('ERROR', err); - res[viewName] = `${err}`; - } + + const views = await this.safeQuery(this.createQuery('viewTexts', ['views'])); + for (const view of views.rows) { + res[view.pureName] = `CREATE VIEW \`${view.pureName}\` AS ${view.viewDefinition}`; } + + // for (const viewName of this.getRequestedViewNames(allViewNames)) { + // try { + // const resp = await this.driver.query(this.pool, `SHOW CREATE VIEW \`${viewName}\``); + // res[viewName] = resp.rows[0]['Create View']; + // } catch (err) { + // console.log('ERROR', err); + // res[viewName] = `${err}`; + // } + // } return res; } diff --git a/plugins/dbgate-plugin-mysql/src/backend/sql/index.js b/plugins/dbgate-plugin-mysql/src/backend/sql/index.js index 37771370..4839071e 100644 --- a/plugins/dbgate-plugin-mysql/src/backend/sql/index.js +++ b/plugins/dbgate-plugin-mysql/src/backend/sql/index.js @@ -9,6 +9,7 @@ const programmables = require('./programmables'); const procedureModifications = require('./procedureModifications'); const functionModifications = require('./functionModifications'); const uniqueNames = require('./uniqueNames'); +const viewTexts = require('./viewTexts'); module.exports = { columns, @@ -22,4 +23,5 @@ module.exports = { functionModifications, indexes, uniqueNames, + viewTexts, }; diff --git a/plugins/dbgate-plugin-mysql/src/backend/sql/viewTexts.js b/plugins/dbgate-plugin-mysql/src/backend/sql/viewTexts.js new file mode 100644 index 00000000..a62be5ea --- /dev/null +++ b/plugins/dbgate-plugin-mysql/src/backend/sql/viewTexts.js @@ -0,0 +1,7 @@ +module.exports = ` +select + TABLE_NAME as pureName, + VIEW_DEFINITION as viewDefinition +from information_schema.views +where TABLE_SCHEMA = '#DATABASE#' and TABLE_NAME =OBJECT_ID_CONDITION; +`;