@query-doctor/core 0.1.11 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +24 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +24 -9
- package/dist/index.js.map +1 -1
- package/dist/optimizer/genalgo.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1220,26 +1220,31 @@ var _IndexOptimizer = class _IndexOptimizer {
|
|
|
1220
1220
|
indexesToCreate(rootCandidates) {
|
|
1221
1221
|
const permutedIndexes = this.tableColumnIndexCandidates(rootCandidates);
|
|
1222
1222
|
const nextStage = [];
|
|
1223
|
-
for (const
|
|
1223
|
+
for (const permutation of permutedIndexes.values()) {
|
|
1224
|
+
const { table: rawTable, schema: rawSchema, columns } = permutation;
|
|
1224
1225
|
const permutations = permuteWithFeedback(columns);
|
|
1225
1226
|
let iter = permutations.next(PROCEED);
|
|
1226
1227
|
while (!iter.done) {
|
|
1227
1228
|
const columns2 = iter.value;
|
|
1228
|
-
const
|
|
1229
|
+
const schema = PgIdentifier.fromString(rawSchema);
|
|
1230
|
+
const table = PgIdentifier.fromString(rawTable);
|
|
1231
|
+
const existingIndex = this.indexAlreadyExists(
|
|
1232
|
+
table.toString(),
|
|
1233
|
+
columns2
|
|
1234
|
+
);
|
|
1229
1235
|
if (existingIndex) {
|
|
1230
1236
|
iter = permutations.next(PROCEED);
|
|
1231
1237
|
continue;
|
|
1232
1238
|
}
|
|
1233
1239
|
const indexName = this.indexName();
|
|
1234
|
-
const
|
|
1235
|
-
const indexDefinitionClean = `${shortenedSchema}"${table}"(${columns2.map((c) => `"${c.column}"`).join(", ")})`;
|
|
1240
|
+
const definition = this.toDefinition(permutation).raw;
|
|
1236
1241
|
iter = permutations.next(PROCEED);
|
|
1237
1242
|
nextStage.push({
|
|
1238
1243
|
name: indexName,
|
|
1239
|
-
schema,
|
|
1240
|
-
table,
|
|
1244
|
+
schema: schema.toString(),
|
|
1245
|
+
table: table.toString(),
|
|
1241
1246
|
columns: columns2,
|
|
1242
|
-
definition
|
|
1247
|
+
definition
|
|
1243
1248
|
});
|
|
1244
1249
|
}
|
|
1245
1250
|
}
|
|
@@ -1247,10 +1252,20 @@ var _IndexOptimizer = class _IndexOptimizer {
|
|
|
1247
1252
|
}
|
|
1248
1253
|
toDefinition(permuted) {
|
|
1249
1254
|
const make = (col, order, where, keyword) => {
|
|
1250
|
-
|
|
1255
|
+
let fullyQualifiedTable;
|
|
1256
|
+
if (permuted.schema.toString() === "public") {
|
|
1257
|
+
fullyQualifiedTable = PgIdentifier.fromString(permuted.table);
|
|
1258
|
+
} else {
|
|
1259
|
+
fullyQualifiedTable = PgIdentifier.fromParts(
|
|
1260
|
+
permuted.schema,
|
|
1261
|
+
permuted.table
|
|
1262
|
+
);
|
|
1263
|
+
}
|
|
1264
|
+
const baseColumn = `${fullyQualifiedTable}(${permuted.columns.map((c) => {
|
|
1265
|
+
const column = PgIdentifier.fromString(c.column);
|
|
1251
1266
|
const direction = c.sort && this.sortDirection(c.sort);
|
|
1252
1267
|
const nulls = c.sort && this.nullsOrder(c.sort);
|
|
1253
|
-
let sort = col(
|
|
1268
|
+
let sort = col(column.toString());
|
|
1254
1269
|
if (direction) {
|
|
1255
1270
|
sort += ` ${order(direction)}`;
|
|
1256
1271
|
}
|