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