@@ -422,74 +422,18 @@ policy_refresh_cagg_execute(int32 job_id, Jsonb *config)
422422 PGC_S_SESSION );
423423 }
424424
425- ContinuousAggRefreshContext context = { .callctx = CAGG_REFRESH_POLICY , .job_id = job_id };
426-
427- /* Try to split window range into a list of ranges */
428- List * refresh_window_list = continuous_agg_split_refresh_window (policy_data .cagg ,
429- & policy_data .refresh_window ,
430- policy_data .buckets_per_batch );
431- if (refresh_window_list == NIL )
432- {
433- refresh_window_list = lappend (refresh_window_list , & policy_data .refresh_window );
434- }
435- else
436- {
437- context .callctx = CAGG_REFRESH_POLICY_BATCHED ;
438- }
439-
440- context .number_of_batches = list_length (refresh_window_list );
441-
442- /*
443- * The list is always built oldest-first. When refresh_newest_first is true we
444- * iterate from the last element down to the first using index-based access so
445- * that no reversal copy of the list is needed.
446- */
447- int32 processing_batch = 0 ;
448- int32 nbatches = list_length (refresh_window_list );
449- int32 batch_start = policy_data .refresh_newest_first ? nbatches - 1 : 0 ;
450- int32 batch_end = policy_data .refresh_newest_first ? -1 : nbatches ;
451- int32 batch_step = policy_data .refresh_newest_first ? -1 : 1 ;
452- for (int32 batch_idx = batch_start ; batch_idx != batch_end ; batch_idx += batch_step )
453- {
454- InternalTimeRange * refresh_window =
455- (InternalTimeRange * ) list_nth (refresh_window_list , batch_idx );
456- elog (DEBUG1 ,
457- "refreshing continuous aggregate \"%s\" from %s to %s" ,
458- NameStr (policy_data .cagg -> data .user_view_name ),
459- ts_internal_to_time_string (refresh_window -> start , refresh_window -> type ),
460- ts_internal_to_time_string (refresh_window -> end , refresh_window -> type ));
461-
462- context .processing_batch = ++ processing_batch ;
463-
464- /* extend_last_bucket must only apply to the boundary batch — the one
465- * whose window abuts the adjacent policy. For newest-first ordering
466- * that is batch 1; for oldest-first it is the final batch.
467- * In non-batched mode (single batch) the one batch is always the boundary. */
468- bool apply_extend =
469- extend_last_bucket &&
470- (policy_data .refresh_newest_first ? processing_batch == 1 :
471- processing_batch == context .number_of_batches );
472-
473- continuous_agg_refresh_internal (policy_data .cagg ,
474- refresh_window ,
475- context ,
476- refresh_window -> start_isnull ,
477- refresh_window -> end_isnull ,
478- (context .callctx != CAGG_REFRESH_POLICY_BATCHED ),
479- false, /* force */
480- apply_extend );
481- DEBUG_ERROR_INJECTION (psprintf ("cagg_policy_batch_%d_after_refresh" , processing_batch ));
482- if (processing_batch >= policy_data .max_batches_per_execution &&
483- processing_batch < context .number_of_batches &&
484- policy_data .max_batches_per_execution > 0 )
485- {
486- elog (LOG ,
487- "reached maximum number of batches per execution (%d), batches not processed (%d)" ,
488- policy_data .max_batches_per_execution ,
489- context .number_of_batches - processing_batch );
490- break ;
491- }
492- }
425+ ContinuousAggRefreshContext context = {
426+ .callctx = CAGG_REFRESH_POLICY ,
427+ .job_id = job_id ,
428+ .buckets_per_batch = policy_data .buckets_per_batch ,
429+ .max_batches_per_execution = policy_data .max_batches_per_execution ,
430+ .refresh_newest_first = policy_data .refresh_newest_first ,
431+ };
432+
433+ continuous_agg_refresh_batched (policy_data .cagg ,
434+ & policy_data .refresh_window ,
435+ context ,
436+ extend_last_bucket );
493437
494438 if (!policy_data .include_tiered_data_isnull )
495439 {
0 commit comments