@query-doctor/core 0.2.0 → 0.2.1
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 +25 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +25 -13
- package/dist/index.js.map +1 -1
- package/dist/optimizer/genalgo.d.ts.map +1 -1
- package/dist/sql/builder.d.ts +2 -1
- package/dist/sql/builder.d.ts.map +1 -1
- package/dist/sql/pg-identifier.d.ts +1 -1
- package/dist/sql/pg-identifier.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -879,7 +879,13 @@ var _PgIdentifier = class _PgIdentifier {
|
|
|
879
879
|
*/
|
|
880
880
|
static fromParts(...identifiers) {
|
|
881
881
|
return new _PgIdentifier(
|
|
882
|
-
identifiers.map((identifier) =>
|
|
882
|
+
identifiers.map((identifier) => {
|
|
883
|
+
if (typeof identifier === "string") {
|
|
884
|
+
return _PgIdentifier.fromString(identifier);
|
|
885
|
+
} else {
|
|
886
|
+
return identifier;
|
|
887
|
+
}
|
|
888
|
+
}).join("."),
|
|
883
889
|
false
|
|
884
890
|
);
|
|
885
891
|
}
|
|
@@ -1092,7 +1098,7 @@ var _IndexOptimizer = class _IndexOptimizer {
|
|
|
1092
1098
|
}
|
|
1093
1099
|
for (const permutation of toCreate) {
|
|
1094
1100
|
const createIndex = PostgresQueryBuilder.createIndex(
|
|
1095
|
-
|
|
1101
|
+
permutation.definition,
|
|
1096
1102
|
permutation.name
|
|
1097
1103
|
).introspect().build();
|
|
1098
1104
|
await tx.exec(createIndex);
|
|
@@ -1122,7 +1128,11 @@ var _IndexOptimizer = class _IndexOptimizer {
|
|
|
1122
1128
|
finalCost,
|
|
1123
1129
|
newIndexes: finalIndexes.newIndexes,
|
|
1124
1130
|
existingIndexes: baseIndexes.existingIndexes,
|
|
1125
|
-
triedIndexes: new Map(
|
|
1131
|
+
triedIndexes: new Map(
|
|
1132
|
+
// TODO: don't prematurely stringify PgIdentifier here
|
|
1133
|
+
// (requires more work)
|
|
1134
|
+
toCreate.map((index) => [index.name.toString(), index])
|
|
1135
|
+
),
|
|
1126
1136
|
baseExplainPlan: baseExplain.Plan,
|
|
1127
1137
|
explainPlan: finalExplain.Plan
|
|
1128
1138
|
};
|
|
@@ -1156,7 +1166,8 @@ var _IndexOptimizer = class _IndexOptimizer {
|
|
|
1156
1166
|
* overflow that limit.
|
|
1157
1167
|
*/
|
|
1158
1168
|
indexName() {
|
|
1159
|
-
|
|
1169
|
+
const indexName = _IndexOptimizer.prefix + Math.random().toString(36).substring(2, 16);
|
|
1170
|
+
return PgIdentifier.fromString(indexName);
|
|
1160
1171
|
}
|
|
1161
1172
|
// TODO: this doesn't belong in the optimizer
|
|
1162
1173
|
indexAlreadyExists(table, columns) {
|
|
@@ -1187,7 +1198,7 @@ var _IndexOptimizer = class _IndexOptimizer {
|
|
|
1187
1198
|
continue;
|
|
1188
1199
|
}
|
|
1189
1200
|
const indexName = this.indexName();
|
|
1190
|
-
const definition = this.toDefinition(
|
|
1201
|
+
const definition = this.toDefinition({ table, schema, columns: columns2 }).raw;
|
|
1191
1202
|
iter = permutations.next(PROCEED);
|
|
1192
1203
|
nextStage.push({
|
|
1193
1204
|
name: indexName,
|
|
@@ -1200,18 +1211,19 @@ var _IndexOptimizer = class _IndexOptimizer {
|
|
|
1200
1211
|
}
|
|
1201
1212
|
return nextStage;
|
|
1202
1213
|
}
|
|
1203
|
-
toDefinition(
|
|
1214
|
+
toDefinition({
|
|
1215
|
+
schema,
|
|
1216
|
+
table,
|
|
1217
|
+
columns
|
|
1218
|
+
}) {
|
|
1204
1219
|
const make = (col, order, where, keyword) => {
|
|
1205
1220
|
let fullyQualifiedTable;
|
|
1206
|
-
if (
|
|
1207
|
-
fullyQualifiedTable =
|
|
1221
|
+
if (schema.toString() === "public") {
|
|
1222
|
+
fullyQualifiedTable = table;
|
|
1208
1223
|
} else {
|
|
1209
|
-
fullyQualifiedTable = PgIdentifier.fromParts(
|
|
1210
|
-
permuted.schema,
|
|
1211
|
-
permuted.table
|
|
1212
|
-
);
|
|
1224
|
+
fullyQualifiedTable = PgIdentifier.fromParts(schema, table);
|
|
1213
1225
|
}
|
|
1214
|
-
const baseColumn = `${fullyQualifiedTable}(${
|
|
1226
|
+
const baseColumn = `${fullyQualifiedTable}(${columns.map((c) => {
|
|
1215
1227
|
const column = PgIdentifier.fromString(c.column);
|
|
1216
1228
|
const direction = c.sort && this.sortDirection(c.sort);
|
|
1217
1229
|
const nulls = c.sort && this.nullsOrder(c.sort);
|