prisma-sql 1.75.12 → 1.76.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.js CHANGED
@@ -2292,8 +2292,6 @@ function resolveIncludeRelations(includeSpec, model, schemas) {
2292
2292
  }
2293
2293
  return results;
2294
2294
  }
2295
-
2296
- // src/builder/select/strategy-estimator.ts
2297
2295
  var globalRelationStats;
2298
2296
  var globalRoundtripRowEquivalent = 73;
2299
2297
  var CORRELATED_S_BOUNDED = 0.5;
@@ -2322,11 +2320,14 @@ function getFanOut(modelName, relName) {
2322
2320
  if (!relStat || relStat.coverage < MIN_STATS_COVERAGE) return DEFAULT_FAN;
2323
2321
  return relStat.avg;
2324
2322
  }
2323
+ var DYNAMIC_TAKE_ESTIMATE = 10;
2325
2324
  function readTake(relArgs) {
2326
2325
  if (!isPlainObject(relArgs)) return Infinity;
2327
2326
  const obj = relArgs;
2328
2327
  if ("take" in obj && typeof obj.take === "number" && obj.take > 0)
2329
2328
  return obj.take;
2329
+ if ("take" in obj && obj.take != null && isDynamicParameter(obj.take))
2330
+ return DYNAMIC_TAKE_ESTIMATE;
2330
2331
  return Infinity;
2331
2332
  }
2332
2333
  function hasWhereClause(relArgs) {
@@ -2340,7 +2341,7 @@ function isListField(field) {
2340
2341
  function hasPaginationArgs(value) {
2341
2342
  if (!isPlainObject(value)) return false;
2342
2343
  const obj = value;
2343
- return "take" in obj && obj.take != null || "skip" in obj && typeof obj.skip === "number" && obj.skip > 0;
2344
+ return "take" in obj && obj.take != null || "skip" in obj && obj.skip != null && (typeof obj.skip === "number" && obj.skip > 0 || isDynamicParameter(obj.skip));
2344
2345
  }
2345
2346
  function buildCostTree(includeSpec, model, schemas, depth = 0) {
2346
2347
  if (depth > LIMITS.MAX_INCLUDE_DEPTH) return [];
@@ -2462,7 +2463,16 @@ function hasChildPaginationAnywhere(includeSpec, model, schemas, depth = 0) {
2462
2463
  return false;
2463
2464
  }
2464
2465
  function pickIncludeStrategy(params) {
2465
- const { includeSpec, model, schemas, method, takeValue, canFlatJoin, debug } = params;
2466
+ const {
2467
+ includeSpec,
2468
+ model,
2469
+ schemas,
2470
+ method,
2471
+ takeValue,
2472
+ canFlatJoin,
2473
+ hasChildPagination,
2474
+ debug
2475
+ } = params;
2466
2476
  if (Object.keys(includeSpec).length === 0) return "where-in";
2467
2477
  if (canFlatJoin && hasOnlyToOneRelations(includeSpec, model)) {
2468
2478
  if (debug)
@@ -2482,6 +2492,35 @@ function pickIncludeStrategy(params) {
2482
2492
  }
2483
2493
  const costTree = buildCostTree(includeSpec, model, schemas);
2484
2494
  const treeDepth = maxDepthFromTree(costTree);
2495
+ if (hasChildPagination && treeDepth >= 2) {
2496
+ if (debug)
2497
+ console.log(
2498
+ ` [strategy] ${model.name}: childPagination + depth=${treeDepth} \u2265 2 \u2192 fallback`
2499
+ );
2500
+ return "fallback";
2501
+ }
2502
+ if (hasChildPagination && treeDepth === 1) {
2503
+ if (anyChildHasWhere(costTree)) {
2504
+ if (debug)
2505
+ console.log(
2506
+ ` [strategy] ${model.name}: childPagination + depth=1 + childWhere \u2192 where-in`
2507
+ );
2508
+ return "where-in";
2509
+ }
2510
+ const hasSelectNarrowing = isPlainObject(params.args) && isPlainObject(params.args.select);
2511
+ if (hasSelectNarrowing) {
2512
+ if (debug)
2513
+ console.log(
2514
+ ` [strategy] ${model.name}: childPagination + depth=1 + selectNarrowing \u2192 fallback`
2515
+ );
2516
+ return "fallback";
2517
+ }
2518
+ if (debug)
2519
+ console.log(
2520
+ ` [strategy] ${model.name}: childPagination + depth=1 \u2192 where-in`
2521
+ );
2522
+ return "where-in";
2523
+ }
2485
2524
  if (treeDepth === 1 && anyChildHasWhere(costTree)) {
2486
2525
  if (debug)
2487
2526
  console.log(` [strategy] ${model.name}: depth-1 + childWhere \u2192 where-in`);
@@ -4826,14 +4865,17 @@ function constructFinalSql(spec) {
4826
4865
  if (dialect === "postgres" && hasIncludes) {
4827
4866
  const canFlatJoin = canUseFlatJoinForAll(includeSpec, model, schemas);
4828
4867
  canUseLateralJoin(includeSpec, model, schemas);
4829
- hasChildPaginationAnywhere(includeSpec, model, schemas);
4868
+ const hasChildPag = hasChildPaginationAnywhere(includeSpec, model, schemas);
4830
4869
  const strategy = pickIncludeStrategy({
4831
4870
  includeSpec,
4832
4871
  model,
4833
4872
  schemas,
4834
4873
  method,
4874
+ args,
4835
4875
  takeValue,
4836
- canFlatJoin});
4876
+ canFlatJoin,
4877
+ hasChildPagination: hasChildPag
4878
+ });
4837
4879
  if (strategy === "flat-join") {
4838
4880
  const flatResult = buildFlatJoinSql(spec);
4839
4881
  if (flatResult.sql) {
@@ -7932,7 +7974,7 @@ function planQueryStrategy(params) {
7932
7974
  const takeValue = isPlainObject(args) && typeof args.take === "number" ? args.take : null;
7933
7975
  const canFlatJoin = canUseFlatJoinForAll(includeSpec, model, allModels);
7934
7976
  canUseLateralJoin(includeSpec, model, allModels);
7935
- hasChildPaginationAnywhere(
7977
+ const hasChildPag = hasChildPaginationAnywhere(
7936
7978
  includeSpec,
7937
7979
  model,
7938
7980
  allModels
@@ -7942,8 +7984,10 @@ function planQueryStrategy(params) {
7942
7984
  model,
7943
7985
  schemas: allModels,
7944
7986
  method: params.method,
7987
+ args,
7945
7988
  takeValue,
7946
7989
  canFlatJoin,
7990
+ hasChildPagination: hasChildPag,
7947
7991
  debug
7948
7992
  });
7949
7993
  if (debug) {