@@ -409,16 +409,18 @@ impl Coordinator {
409409 /// Because of this, we have usually "missed" the opportunity to plan them
410410 /// through the normal statement execution life cycle (the exception being
411411 /// during bootstrapping).
412+ ///
413+ /// The caller needs to provide a `CatalogItemId` and `GlobalId` for the sub-source.
412414 pub ( crate ) async fn plan_subsource (
413415 & mut self ,
414416 session : & Session ,
415417 params : & mz_sql:: plan:: Params ,
416418 subsource_stmt : CreateSubsourceStatement < mz_sql:: names:: Aug > ,
419+ item_id : CatalogItemId ,
420+ global_id : GlobalId ,
417421 ) -> Result < CreateSourcePlanBundle , AdapterError > {
418422 let catalog = self . catalog ( ) . for_session ( session) ;
419423 let resolved_ids = mz_sql:: names:: visit_dependencies ( & catalog, & subsource_stmt) ;
420- let id_ts = self . get_catalog_write_ts ( ) . await ;
421- let ( item_id, global_id) = self . catalog_mut ( ) . allocate_user_id ( id_ts) . await ?;
422424
423425 let plan = self . plan_statement (
424426 session,
@@ -467,9 +469,15 @@ impl Coordinator {
467469 let ingestion_id = source. global_id ( ) ;
468470 let subsource_stmts = generate_subsource_statements ( & scx, source_name, subsources) ?;
469471
472+ let id_ts = self . get_catalog_write_ts ( ) . await ;
473+ let mut ids = self
474+ . catalog_mut ( )
475+ . allocate_user_ids ( u64:: cast_from ( subsource_stmts. len ( ) ) , id_ts)
476+ . await ?;
470477 for subsource_stmt in subsource_stmts {
478+ let ( item_id, global_id) = ids. pop ( ) . unwrap ( ) ;
471479 let s = self
472- . plan_subsource ( session, & params, subsource_stmt)
480+ . plan_subsource ( session, & params, subsource_stmt, item_id , global_id )
473481 . await ?;
474482 subsource_plans. push ( s) ;
475483 }
@@ -539,8 +547,10 @@ impl Coordinator {
539547 // guaranteeing that the shard ID is discoverable is to create this
540548 // collection first.
541549 assert_none ! ( progress_stmt. of_source) ;
550+ let id_ts = self . get_catalog_write_ts ( ) . await ;
551+ let ( item_id, global_id) = self . catalog_mut ( ) . allocate_user_id ( id_ts) . await ?;
542552 let progress_plan = self
543- . plan_subsource ( ctx. session ( ) , & params, progress_stmt)
553+ . plan_subsource ( ctx. session ( ) , & params, progress_stmt, item_id , global_id )
544554 . await ?;
545555 let progress_full_name = self
546556 . catalog ( )
@@ -599,8 +609,16 @@ impl Coordinator {
599609 } ) ;
600610
601611 // 3. Finally, plan all the subsources
612+ let id_ts = self . get_catalog_write_ts ( ) . await ;
613+ let mut ids = self
614+ . catalog_mut ( )
615+ . allocate_user_ids ( u64:: cast_from ( subsource_stmts. len ( ) ) , id_ts)
616+ . await ?;
602617 for stmt in subsource_stmts {
603- let plan = self . plan_subsource ( ctx. session ( ) , & params, stmt) . await ?;
618+ let ( item_id, global_id) = ids. pop ( ) . unwrap ( ) ;
619+ let plan = self
620+ . plan_subsource ( ctx. session ( ) , & params, stmt, item_id, global_id)
621+ . await ?;
604622 create_source_plans. push ( plan) ;
605623 }
606624
0 commit comments