Skip to content

Commit a640781

Browse files
boring-joeypaescujjaadsnickrum
authored
Fix for slow query on MS SQL (directus#22522)
* Fix for slow query on MS SQL * Temporary activation of blackbox tests * Fix for schema name index problem on Azure SQL * disabled blackbox tests again * formatter fix * another formatter fix * Directly await schema id query * Update contributors.yml * Add changeset --------- Co-authored-by: Pascal Jufer <[email protected]> Co-authored-by: Jan Arends <[email protected]> Co-authored-by: Nicola Krumschmidt <[email protected]>
1 parent 320804c commit a640781

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

.changeset/proud-games-explain.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@directus/schema": patch
3+
---
4+
5+
Fixed performance issues with schema introspection on MS SQL

contributors.yml

+1
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,4 @@
131131
- sharkfin009
132132
- npostulart
133133
- alejandrocortell
134+
- boring-joey

packages/schema/src/dialects/mssql.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,14 @@ export default class MSSQL implements SchemaInspector {
275275
async columnInfo(table?: string, column?: string) {
276276
const dbName = this.knex.client.database();
277277

278+
const schemaIdResult = await this.knex.select('schema_id').from('sys.schemas').where({ name: this.schema }).first();
279+
280+
const schemaId = schemaIdResult.schema_id;
281+
282+
if (!schemaId) {
283+
throw new Error(`Schema '${this.schema}' not found.`);
284+
}
285+
278286
const query = this.knex
279287
.select(
280288
this.knex.raw(`
@@ -336,7 +344,7 @@ export default class MSSQL implements SchemaInspector {
336344
AND ISNULL([i].[index_column_count], 1) = 1
337345
AND ISNULL([i].[index_priority], 1) = 1`,
338346
)
339-
.where({ 's.name': this.schema });
347+
.where({ 's.schema_id': schemaId });
340348

341349
if (table) {
342350
query.andWhere({ 'o.name': table });

0 commit comments

Comments
 (0)