@query-doctor/core 0.1.10 → 0.1.12
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
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,15 @@ var _IndexOptimizer = class _IndexOptimizer {
|
|
|
1247
1252
|
}
|
|
1248
1253
|
toDefinition(permuted) {
|
|
1249
1254
|
const make = (col, order, where, keyword) => {
|
|
1250
|
-
const
|
|
1255
|
+
const fullyQualifiedTable = PgIdentifier.fromParts(
|
|
1256
|
+
permuted.schema,
|
|
1257
|
+
permuted.table
|
|
1258
|
+
);
|
|
1259
|
+
const baseColumn = `${fullyQualifiedTable}(${permuted.columns.map((c) => {
|
|
1260
|
+
const column = PgIdentifier.fromString(c.column);
|
|
1251
1261
|
const direction = c.sort && this.sortDirection(c.sort);
|
|
1252
1262
|
const nulls = c.sort && this.nullsOrder(c.sort);
|
|
1253
|
-
let sort = col(
|
|
1263
|
+
let sort = col(column.toString());
|
|
1254
1264
|
if (direction) {
|
|
1255
1265
|
sort += ` ${order(direction)}`;
|
|
1256
1266
|
}
|
|
@@ -1555,6 +1565,16 @@ var _Statistics = class _Statistics {
|
|
|
1555
1565
|
restoreStats(tx) {
|
|
1556
1566
|
return this.restoreStats17(tx);
|
|
1557
1567
|
}
|
|
1568
|
+
approximateTotalRows() {
|
|
1569
|
+
if (!this.exportedMetadata) {
|
|
1570
|
+
return 0;
|
|
1571
|
+
}
|
|
1572
|
+
let totalRows = 0;
|
|
1573
|
+
for (const table of this.exportedMetadata) {
|
|
1574
|
+
totalRows += table.reltuples;
|
|
1575
|
+
}
|
|
1576
|
+
return totalRows;
|
|
1577
|
+
}
|
|
1558
1578
|
/**
|
|
1559
1579
|
* We have to cast stavaluesN to the correct type
|
|
1560
1580
|
* This derives that type for us so it can be used in `array_in`
|