Skip to content

Commit 0fa7e1e

Browse files
authored
Merge pull request #136 from halcyon-tech/feature/schema_index_advice
Feature/schema_index_advice
2 parents 1a26ef4 + 774c1d4 commit 0fa7e1e

File tree

5 files changed

+41
-28
lines changed

5 files changed

+41
-28
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,12 @@
481481
},
482482
{
483483
"command": "vscode-db2i.advisedIndexes",
484-
"when": "viewItem == table",
484+
"when": "viewItem == table || viewItem == schema",
485485
"group": "db2idxAdv@1"
486486
},
487487
{
488488
"command": "vscode-db2i.clearAdvisedIndexes",
489-
"when": "viewItem == table",
489+
"when": "viewItem == table || viewItem == schema",
490490
"group": "db2idxAdv@2"
491491
},
492492
{

src/database/schemas.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const typeMap = {
1313
'aliases': [`A`]
1414
};
1515

16-
export default class Database {
16+
export default class Schemas {
1717
/**
1818
* @param schema Not user input
1919
*/
@@ -171,4 +171,14 @@ export default class Database {
171171
static isRoutineType(type: string): boolean {
172172
return type === `function` || type === `procedure`;
173173
}
174+
175+
static clearAdvisedIndexes(schema: string, name?: string) {
176+
let query = `DELETE FROM QSYS2.SYSIXADV WHERE TABLE_SCHEMA = '${schema}'`;
177+
178+
if (name) {
179+
query += `and TABLE_NAME = '${name}'`;
180+
}
181+
182+
return getInstance().getContent().runSQL(query);
183+
}
174184
}

src/database/table.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,6 @@ export default class Table {
3737
return JobManager.runSQL(sql);
3838
}
3939

40-
/**
41-
* @param schema Not user input
42-
* @param name Not user input
43-
*/
44-
static clearAdvisedIndexes(schema: string, name: string) {
45-
const query = `DELETE FROM QSYS2.SYSIXADV WHERE TABLE_SCHEMA = '${schema}' and TABLE_NAME = '${name}'`;
46-
return getInstance().getContent().runSQL(query);
47-
}
48-
4940
static async clearFile(library: string, objectName: string): Promise<void> {
5041
const command = `CLRPFM ${library}/${objectName}`;
5142

src/views/schemaBrowser/schemaBrowser.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export default class schemaBrowser {
151151

152152
vscode.commands.executeCommand(`vscode-db2i.runEditorStatement`, {
153153
content,
154-
type: `statement`,
154+
qualifier: `statement`,
155155
open: false,
156156
});
157157
}
@@ -162,32 +162,44 @@ export default class schemaBrowser {
162162
const content = `SELECT * FROM QSYS2.SYSINDEXSTAT WHERE TABLE_SCHEMA = '${object.schema}' and TABLE_NAME = '${object.name}'`;
163163
vscode.commands.executeCommand(`vscode-db2i.runEditorStatement`, {
164164
content,
165-
type: `statement`,
165+
qualifier: `statement`,
166166
open: false,
167167
});
168168
}
169169
}),
170170

171-
vscode.commands.registerCommand(`vscode-db2i.advisedIndexes`, async (object: SQLObject) => { //table
171+
vscode.commands.registerCommand(`vscode-db2i.advisedIndexes`, async (object: SQLObject|SchemaItem) => { //table
172172
if (object) {
173-
const content = getAdvisedIndexesStatement(object.schema, object.name);
174-
vscode.commands.executeCommand(`vscode-db2i.runEditorStatement`, {
175-
content,
176-
type: `statement`,
177-
open: false,
178-
});
173+
let content: string|undefined;
174+
if (`name` in object) {
175+
content = getAdvisedIndexesStatement(object.schema, object.name);
176+
}
177+
else {
178+
content = getAdvisedIndexesStatement(object.schema);
179+
}
180+
181+
if (content) {
182+
vscode.commands.executeCommand(`vscode-db2i.runEditorStatement`, {
183+
content,
184+
qualifier: `statement`,
185+
open: false,
186+
});
187+
}
179188
}
180189
}),
181190

182-
vscode.commands.registerCommand(`vscode-db2i.clearAdvisedIndexes`, async (object: SQLObject) => {
191+
vscode.commands.registerCommand(`vscode-db2i.clearAdvisedIndexes`, async (object: SQLObject|SchemaItem) => {
183192
if (object) {
184-
const result = await vscode.window.showWarningMessage(`Are you sure you want to clear all of the advised index rows from the Index Advisor for ${object.name}?`, {
193+
const isObject = `name` in object;
194+
let result;
195+
196+
result = await vscode.window.showWarningMessage(`Are you sure you want to clear all of the advised index rows from the Index Advisor for ${object.schema}${isObject ? `${object.name}` : ''}?`, {
185197
modal: true,
186198
}, 'No', 'Yes');
187199

188200
if(result === 'Yes') {
189201
try {
190-
await Table.clearAdvisedIndexes(object.schema, object.name);
202+
await Schemas.clearAdvisedIndexes(object.schema, isObject ? object.name : undefined);
191203
} catch (e) {
192204
vscode.window.showErrorMessage(e.message);
193205
}
@@ -304,7 +316,7 @@ export default class schemaBrowser {
304316
const content = `SELECT * FROM ${Statement.delimName(object.schema)}.${Statement.delimName(object.name)} as a`;
305317
vscode.commands.executeCommand(`vscode-db2i.runEditorStatement`, {
306318
content,
307-
type: `statement`,
319+
qualifier: `statement`,
308320
open: true,
309321
});
310322
}

src/views/schemaBrowser/statements.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
export function getAdvisedIndexesStatement(schema: string, name: string) {
1+
export function getAdvisedIndexesStatement(schema: string, name?: string) {
22
return [
33
`select KEY_COLUMNS_ADVISED, Times_Advised, Most_Expensive_Query, Average_Query_Estimate,`,
44
` Last_Advised, MTI_USED_FOR_STATS, LAST_MTI_USED_FOR_STATS, Table_Size, MTI_USED, MTI_CREATED,`,
55
` LAST_MTI_USED, System_Table_Schema, Estimated_Creation_Time, Logical_Page_Size, INDEX_TYPE,`,
66
` TABLE_NAME, TABLE_SCHEMA, SYSTEM_TABLE_NAME, PARTITION_NAME, LOGICAL_PAGE_SIZE,`,
77
` NLSS_TABLE_NAME, NLSS_TABLE_SCHEMA, MAX_ROW`,
8-
`from qsys2.condidxa`,
9-
`where TABLE_NAME = '${name}' and`,
8+
`from qsys2.condidxa where`,
9+
...(name ? [`TABLE_NAME = '${name}' and`] : []),
1010
` Table_Schema = '${schema}'`,
1111
` order by Times_Advised desc`,
1212
].join(` `);

0 commit comments

Comments
 (0)