Index: wp-includes/rewrite.php
===================================================================
--- wp-includes/rewrite.php	(revision 18407)
+++ wp-includes/rewrite.php	(working copy)
@@ -767,7 +767,8 @@
 		global $wpdb;
 
 		//get pages in order of hierarchy, i.e. children after parents
-		$posts = get_page_hierarchy( $wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'page' AND post_status != 'auto-draft'") );
+		$_posts = $wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'page' AND post_status != 'auto-draft'", OBJECT_K);
+		$posts = get_page_hierarchy( $_posts );
 
 		// If we have no pages get out quick
 		if ( !$posts )
@@ -781,7 +782,7 @@
 
 		foreach ( $posts as $id => $post ) {
 			// URL => page name
-			$uri = get_page_uri($id);
+			$uri = get_page_uri($_posts[$id]);
 			$attachments = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $id ));
 			if ( !empty($attachments) ) {
 				foreach ( $attachments as $attachment ) {
