Index: src/wp-admin/network/upgrade.php
===================================================================
--- src/wp-admin/network/upgrade.php	(revision 38350)
+++ src/wp-admin/network/upgrade.php	(working copy)
@@ -55,14 +55,24 @@
 			update_site_option( 'wpmu_upgrade_site', $wp_db_version );
 		}
 
-		$blogs = $wpdb->get_results( "SELECT blog_id FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' AND spam = '0' AND deleted = '0' AND archived = '0' ORDER BY blog_id DESC LIMIT {$n}, 5", ARRAY_A );
+		$args = array(
+			'spam' => '0',
+			'deleted' => '0',
+			'archived' => '0',
+			'network_id' => get_current_network_id(),
+			'number' => $n,
+			'fields' => 'ids',
+			'order' => 'DESC',
+			'orderby' => 'id',
+		);
+		$blogs = get_sites( $args );
 		if ( empty( $blogs ) ) {
 			echo '<p>' . __( 'All done!' ) . '</p>';
 			break;
 		}
 		echo "<ul>";
-		foreach ( (array) $blogs as $details ) {
-			switch_to_blog( $details['blog_id'] );
+		foreach ( (array) $blogs as $id ) {
+			switch_to_blog( $id );
 			$siteurl = site_url();
 			$upgrade_url = admin_url( 'upgrade.php?step=upgrade_db' );
 			restore_current_blog();
@@ -98,7 +108,7 @@
 			 *
 			 * @param int $blog_id The Site ID.
 			 */
-			do_action( 'wpmu_upgrade_site', $details[ 'blog_id' ] );
+			do_action( 'wpmu_upgrade_site', $id );
 		}
 		echo "</ul>";
 		?><p><?php _e( 'If your browser doesn&#8217;t start loading the next page automatically, click this link:' ); ?> <a class="button" href="upgrade.php?action=upgrade&amp;n=<?php echo ($n + 5) ?>"><?php _e("Next Sites"); ?></a></p>
