@@ -442,67 +442,21 @@ policy_refresh_cagg_execute(int32 job_id, Jsonb *config)
442442 PGC_S_SESSION );
443443 }
444444
445- ContinuousAggRefreshContext context = { .callctx = CAGG_REFRESH_POLICY , .job_id = job_id };
446-
447- /* Try to split window range into a list of ranges */
448- List * refresh_window_list =
449- continuous_agg_split_refresh_window (policy_data .cagg ,
450- & policy_data .refresh_window ,
451- policy_data .buckets_per_batch ,
452- policy_data .refresh_newest_first );
453- if (refresh_window_list == NIL )
454- {
455- refresh_window_list = lappend (refresh_window_list , & policy_data .refresh_window );
456- }
457- else
458- {
459- context .callctx = CAGG_REFRESH_POLICY_BATCHED ;
460- }
461-
462- context .number_of_batches = list_length (refresh_window_list );
463-
464- ListCell * lc ;
465- int32 processing_batch = 0 ;
466- foreach (lc , refresh_window_list )
467- {
468- InternalTimeRange * refresh_window = (InternalTimeRange * ) lfirst (lc );
469- elog (DEBUG1 ,
470- "refreshing continuous aggregate \"%s\" from %s to %s" ,
471- NameStr (policy_data .cagg -> data .user_view_name ),
472- ts_internal_to_time_string (refresh_window -> start , refresh_window -> type ),
473- ts_internal_to_time_string (refresh_window -> end , refresh_window -> type ));
474-
475- context .processing_batch = ++ processing_batch ;
476-
477- /* extend_last_bucket must only apply to the boundary batch — the one
478- * whose window abuts the adjacent policy. For newest-first ordering
479- * that is batch 1; for oldest-first it is the final batch.
480- * In non-batched mode (single batch) the one batch is always the boundary. */
481- bool apply_extend =
482- extend_last_bucket &&
483- (policy_data .refresh_newest_first ? processing_batch == 1 :
484- processing_batch == context .number_of_batches );
485-
486- continuous_agg_refresh_internal (policy_data .cagg ,
487- refresh_window ,
488- context ,
489- refresh_window -> start_isnull ,
490- refresh_window -> end_isnull ,
491- (context .callctx != CAGG_REFRESH_POLICY_BATCHED ),
492- false, /* force */
493- apply_extend );
494- DEBUG_ERROR_INJECTION (psprintf ("cagg_policy_batch_%d_after_refresh" , processing_batch ));
495- if (processing_batch >= policy_data .max_batches_per_execution &&
496- processing_batch < context .number_of_batches &&
497- policy_data .max_batches_per_execution > 0 )
498- {
499- elog (LOG ,
500- "reached maximum number of batches per execution (%d), batches not processed (%d)" ,
501- policy_data .max_batches_per_execution ,
502- context .number_of_batches - processing_batch );
503- break ;
504- }
505- }
445+ ContinuousAggRefreshContext context = {
446+ .callctx = CAGG_REFRESH_POLICY ,
447+ .job_id = job_id ,
448+ .buckets_per_batch = policy_data .buckets_per_batch ,
449+ .max_batches_per_execution = policy_data .max_batches_per_execution ,
450+ .refresh_newest_first = policy_data .refresh_newest_first ,
451+ };
452+
453+ continuous_agg_refresh_internal (policy_data .cagg ,
454+ & policy_data .refresh_window ,
455+ context ,
456+ policy_data .refresh_window .start_isnull ,
457+ policy_data .refresh_window .end_isnull ,
458+ false, /* force */
459+ extend_last_bucket );
506460
507461 if (!policy_data .include_tiered_data_isnull )
508462 {
@@ -553,6 +507,7 @@ policy_refresh_cagg_execute(int32 job_id, Jsonb *config)
553507 }
554508
555509 /* Process each chunk in its own transaction */
510+ ListCell * lc ;
556511 foreach (lc , chunkid_lst )
557512 {
558513 PushActiveSnapshot (GetTransactionSnapshot ());
0 commit comments