@@ -142,14 +142,15 @@ func (b *iteratorBuilder) buildIteratorFromRelation(r *schema.Relation, withSubR
142142 }
143143 return NewAliasIterator (r .Name (), baseIt ), nil
144144 }
145- union := NewUnionIterator ( )
145+ subIts := make ([] Iterator , 0 , len ( r . BaseRelations ()) )
146146 for _ , br := range r .BaseRelations () {
147147 it , err := b .buildBaseDatastoreIterator (br , withSubRelations )
148148 if err != nil {
149149 return nil , err
150150 }
151- union . addSubIterator ( it )
151+ subIts = append ( subIts , it )
152152 }
153+ union := NewUnionIterator (subIts ... )
153154 return NewAliasIterator (r .Name (), union ), nil
154155}
155156
@@ -180,26 +181,26 @@ func (b *iteratorBuilder) buildIteratorFromOperation(p *schema.Permission, op sc
180181 return b .buildIteratorFromSchemaInternal (p .Parent ().Name (), perm .RelationName (), true )
181182
182183 case * schema.UnionOperation :
183- union := NewUnionIterator ( )
184+ subIts := make ([] Iterator , 0 , len ( perm . Children ()) )
184185 for _ , op := range perm .Children () {
185186 it , err := b .buildIteratorFromOperation (p , op )
186187 if err != nil {
187188 return nil , err
188189 }
189- union . addSubIterator ( it )
190+ subIts = append ( subIts , it )
190191 }
191- return union , nil
192+ return NewUnionIterator ( subIts ... ) , nil
192193
193194 case * schema.IntersectionOperation :
194- inter := NewIntersectionIterator ( )
195+ subIts := make ([] Iterator , 0 , len ( perm . Children ()) )
195196 for _ , op := range perm .Children () {
196197 it , err := b .buildIteratorFromOperation (p , op )
197198 if err != nil {
198199 return nil , err
199200 }
200- inter . addSubIterator ( it )
201+ subIts = append ( subIts , it )
201202 }
202- return inter , nil
203+ return NewIntersectionIterator ( subIts ... ) , nil
203204
204205 case * schema.ExclusionOperation :
205206 mainIt , err := b .buildIteratorFromOperation (p , perm .Left ())
@@ -290,7 +291,7 @@ func (b *iteratorBuilder) buildBaseDatastoreIterator(br *schema.BaseRelation, wi
290291
291292// buildArrowIterators creates a union of arrow iterators for the given relation and right-hand side
292293func (b * iteratorBuilder ) buildArrowIterators (rel * schema.Relation , rightSide string ) (Iterator , error ) {
293- union := NewUnionIterator ( )
294+ subIts := make ([] Iterator , 0 , len ( rel . BaseRelations ()) )
294295 hasMultipleBaseRelations := len (rel .BaseRelations ()) > 1
295296 var lastNotFoundError error
296297
@@ -306,7 +307,7 @@ func (b *iteratorBuilder) buildArrowIterators(rel *schema.Relation, rightSide st
306307 // applies to some of them. If there's only one base relation, we should error.
307308 if errors .As (err , & RelationNotFoundError {}) {
308309 if hasMultipleBaseRelations {
309- union . addSubIterator ( NewEmptyFixedIterator ())
310+ subIts = append ( subIts , NewFixedIterator ())
310311 continue
311312 }
312313 lastNotFoundError = err
@@ -317,28 +318,28 @@ func (b *iteratorBuilder) buildArrowIterators(rel *schema.Relation, rightSide st
317318 // Use NewSchemaArrow only for BaseRelations without subrelations.
318319 // BaseRelations with subrelations (like folder#parent) should use regular arrows
319320 // because they need strict subrelation matching.
320- var arrow * ArrowIterator
321+ var arrow Iterator
321322 if br .Subrelation () != "" && br .Subrelation () != tuple .Ellipsis {
322323 // Has a specific subrelation: use regular arrow (no ellipsis queries)
323324 arrow = NewArrowIterator (left , right )
324325 } else {
325326 // No subrelation or ellipsis: use schema arrow (with ellipsis queries)
326327 arrow = NewSchemaArrow (left , right )
327328 }
328- union . addSubIterator ( arrow )
329+ subIts = append ( subIts , arrow )
329330 }
330331
331332 // If we have no sub-iterators and only have a not-found error, return that error
332- if len (union . Subiterators () ) == 0 && lastNotFoundError != nil {
333+ if len (subIts ) == 0 && lastNotFoundError != nil {
333334 return nil , lastNotFoundError
334335 }
335336
336- return union , nil
337+ return NewUnionIterator ( subIts ... ) , nil
337338}
338339
339340// buildIntersectionArrowIterators creates a union of intersection arrow iterators for the given relation and right-hand side
340341func (b * iteratorBuilder ) buildIntersectionArrowIterators (rel * schema.Relation , rightSide string ) (Iterator , error ) {
341- union := NewUnionIterator ( )
342+ subIts := make ([] Iterator , 0 , len ( rel . BaseRelations ()) )
342343 hasMultipleBaseRelations := len (rel .BaseRelations ()) > 1
343344 var lastNotFoundError error
344345
@@ -354,7 +355,7 @@ func (b *iteratorBuilder) buildIntersectionArrowIterators(rel *schema.Relation,
354355 // applies to some of them. If there's only one base relation, we should error.
355356 if errors .As (err , & RelationNotFoundError {}) {
356357 if hasMultipleBaseRelations {
357- union . addSubIterator ( NewEmptyFixedIterator ())
358+ subIts = append ( subIts , NewFixedIterator ())
358359 continue
359360 }
360361 lastNotFoundError = err
@@ -363,15 +364,15 @@ func (b *iteratorBuilder) buildIntersectionArrowIterators(rel *schema.Relation,
363364 return nil , err
364365 }
365366 intersectionArrow := NewIntersectionArrowIterator (left , right )
366- union . addSubIterator ( intersectionArrow )
367+ subIts = append ( subIts , intersectionArrow )
367368 }
368369
369370 // If we have no sub-iterators and only have a not-found error, return that error
370- if len (union . Subiterators () ) == 0 && lastNotFoundError != nil {
371+ if len (subIts ) == 0 && lastNotFoundError != nil {
371372 return nil , lastNotFoundError
372373 }
373374
374- return union , nil
375+ return NewUnionIterator ( subIts ... ) , nil
375376}
376377
377378func functionTypeString (ft schema.FunctionType ) string {
0 commit comments