@query-doctor/core 0.1.8 → 0.1.10

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
@@ -189,6 +189,23 @@ function parseNudges(node, stack) {
189
189
  });
190
190
  }
191
191
  }
192
+ if (is(node, "A_Expr")) {
193
+ if (node.A_Expr.kind === "AEXPR_IN") {
194
+ let list;
195
+ if (node.A_Expr.lexpr && is(node.A_Expr.lexpr, "List")) {
196
+ list = node.A_Expr.lexpr.List;
197
+ } else if (node.A_Expr.rexpr && is(node.A_Expr.rexpr, "List")) {
198
+ list = node.A_Expr.rexpr.List;
199
+ }
200
+ if (list?.items && list.items.length >= 10) {
201
+ nudges.push({
202
+ kind: "REPLACE_LARGE_IN_TUPLE_WITH_ANY_ARRAY",
203
+ message: "`in (...)` queries with large tuples can often be replaced with `= ANY($1)` using a single parameter",
204
+ severity: "INFO"
205
+ });
206
+ }
207
+ }
208
+ }
192
209
  return nudges;
193
210
  }
194
211
  function containsColumnRef(args) {
@@ -1165,6 +1182,24 @@ var _IndexOptimizer = class _IndexOptimizer {
1165
1182
  await this.dropExistingIndexes(tx);
1166
1183
  });
1167
1184
  }
1185
+ /**
1186
+ * Given the current indexes in the optimizer, transform them in some
1187
+ * way to change which indexes will be assumed to exist when optimizing
1188
+ *
1189
+ * @example
1190
+ * ```
1191
+ * // resets indexes
1192
+ * optimizer.transformIndexes(() => [])
1193
+ *
1194
+ * // adds new index
1195
+ * optimizer.transformIndexes(indexes => [...indexes, newIndex])
1196
+ * ```
1197
+ */
1198
+ transformIndexes(f) {
1199
+ const newIndexes = f(this.existingIndexes);
1200
+ this.existingIndexes = newIndexes;
1201
+ return this;
1202
+ }
1168
1203
  /**
1169
1204
  * Postgres has a limit of 63 characters for index names.
1170
1205
  * So we use this to make sure we don't derive it from a list of columns that can