Remove superfluous autoprewarm check
authorMelanie Plageman <melanieplageman@gmail.com>
Fri, 4 Apr 2025 19:25:17 +0000 (15:25 -0400)
committerMelanie Plageman <melanieplageman@gmail.com>
Fri, 4 Apr 2025 19:28:39 +0000 (15:28 -0400)
autoprewarm_database_main() prewarms blocks from the same database. It
is passed an array of sorted BlockInfoRecords and a start and stop index
into the array. The range represented should include only blocks
belonging to global objects or blocks from a single database. Remove an
unnecessary check that the current block is from the same database and
add an assert to ensure this invariant remains. Doing so removes a
special case that makes future refactoring to accommodate read
streamifying autoprewarm easier.

Noticed off-list by Andres Freund

contrib/pg_prewarm/autoprewarm.c

index 760b1548eff93b61e760331868e9567a6195721f..5f6dca57cddadffe36a6b1267a41d256d01e3a5e 100644 (file)
@@ -463,12 +463,10 @@ autoprewarm_database_main(Datum main_arg)
        CHECK_FOR_INTERRUPTS();
 
        /*
-        * Quit if we've reached records for another database. If previous
-        * blocks are of some global objects, then continue pre-warming.
+        * All blocks between prewarm_start_idx and prewarm_stop_idx should
+        * belong either to global objects or the same database.
         */
-       if (old_blk != NULL && old_blk->database != blk->database &&
-           old_blk->database != 0)
-           break;
+       Assert(blk->database == apw_state->database || blk->database == 0);
 
        /*
         * As soon as we encounter a block of a new relation, close the old