@@ -17,10 +17,10 @@ import {
1717 UnsupportedJoinTypeError ,
1818} from "../../errors.js"
1919import { ensureIndexForField } from "../../indexes/auto-index.js"
20- import { PropRef } from "../ir.js"
20+ import { PropRef , followRef } from "../ir.js"
2121import { inArray } from "../builder/functions.js"
2222import { compileExpression } from "./evaluators.js"
23- import { compileQuery , followRef } from "./index.js"
23+ import type { CompileQueryFn } from "./index.js"
2424import type { OrderByOptimizationInfo } from "./order-by.js"
2525import type {
2626 BasicExpression ,
@@ -62,7 +62,8 @@ export function processJoins(
6262 callbacks : Record < string , LazyCollectionCallbacks > ,
6363 lazyCollections : Set < string > ,
6464 optimizableOrderByCollections : Record < string , OrderByOptimizationInfo > ,
65- rawQuery : QueryIR
65+ rawQuery : QueryIR ,
66+ onCompileSubquery : CompileQueryFn
6667) : NamespacedAndKeyedStream {
6768 let resultPipeline = pipeline
6869
@@ -81,7 +82,8 @@ export function processJoins(
8182 callbacks ,
8283 lazyCollections ,
8384 optimizableOrderByCollections ,
84- rawQuery
85+ rawQuery ,
86+ onCompileSubquery
8587 )
8688 }
8789
@@ -105,7 +107,8 @@ function processJoin(
105107 callbacks : Record < string , LazyCollectionCallbacks > ,
106108 lazyCollections : Set < string > ,
107109 optimizableOrderByCollections : Record < string , OrderByOptimizationInfo > ,
108- rawQuery : QueryIR
110+ rawQuery : QueryIR ,
111+ onCompileSubquery : CompileQueryFn
109112) : NamespacedAndKeyedStream {
110113 // Get the joined table alias and input stream
111114 const {
@@ -121,7 +124,8 @@ function processJoin(
121124 lazyCollections ,
122125 optimizableOrderByCollections ,
123126 cache ,
124- queryMapping
127+ queryMapping ,
128+ onCompileSubquery
125129 )
126130
127131 // Add the joined table to the tables map
@@ -392,7 +396,8 @@ function processJoinSource(
392396 lazyCollections : Set < string > ,
393397 optimizableOrderByCollections : Record < string , OrderByOptimizationInfo > ,
394398 cache : QueryCache ,
395- queryMapping : QueryMapping
399+ queryMapping : QueryMapping ,
400+ onCompileSubquery : CompileQueryFn
396401) : { alias : string ; input : KeyedStream ; collectionId : string } {
397402 switch ( from . type ) {
398403 case `collectionRef` : {
@@ -407,7 +412,7 @@ function processJoinSource(
407412 const originalQuery = queryMapping . get ( from . query ) || from . query
408413
409414 // Recursively compile the sub-query with cache
410- const subQueryResult = compileQuery (
415+ const subQueryResult = onCompileSubquery (
411416 originalQuery ,
412417 allInputs ,
413418 collections ,
0 commit comments