Index: wp-includes/comment-template.php
===================================================================
--- wp-includes/comment-template.php	(revision 18388)
+++ wp-includes/comment-template.php	(working copy)
@@ -878,16 +878,45 @@
 	 * The url of the current comment author escaped for use in attributes.
 	 */
 	$comment_author_url = esc_url($commenter['comment_author_url']);
-
-	/** @todo Use API instead of SELECTs. */
-	if ( $user_ID) {
-		$comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND (comment_approved = '1' OR ( user_id = %d AND comment_approved = '0' ) )  ORDER BY comment_date_gmt", $post->ID, $user_ID));
-	} else if ( empty($comment_author) ) {
-		$comments = get_comments( array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC') );
-	} else {
-		$comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND ( comment_approved = '1' OR ( comment_author = %s AND comment_author_email = %s AND comment_approved = '0' ) ) ORDER BY comment_date_gmt", $post->ID, wp_specialchars_decode($comment_author,ENT_QUOTES), $comment_author_email));
+	
+	$comments = get_comments( array('post_id' => $post->ID, 'order' => 'ASC') );
+	$comments_parents = array();
+	foreach ( $comments as $k=>$comment ) {
+		if ( 1 == $comment->comment_approved )
+			continue;
+			
+		if ( $user_ID ) {
+			if ( ( "0" == $comment->comment_approved ) && ( $user_ID == $comment->user_id ) )
+				continue;
+		}
+		else {
+			if ( ( "0" == $comment->comment_approved ) && ( wp_specialchars_decode($comment_author,ENT_QUOTES) == $comment->comment_author ) && ( $comment_author_email == $comment->comment_author_email ))
+				continue;
+		}
+		$comments_parents[ $comment->comment_ID ] = $comment->comment_parent;
+		unset($comments[$k]);
 	}
-
+	
+	function find_parents_route( &$comments_parents, $node ) {
+		if ( !isset($comments_parents[$node]) ) 
+			return $node;
+		if ( $comments_parents[$node] == 0 )
+			$comments_parents[$node] = 0;
+		else if ( isset ( $comments_parents[$node] ) )
+			$comments_parents[$node] = find_parents_route( &$comments_parents, $comments_parents[$node]);
+		return $comments_parents[$node];
+	}
+	
+	foreach ( $comments_parents as $k=>$v ) {
+		find_parents_route( $comments_parents, $k );
+	}	
+	
+	foreach ( $comments as $comment ) {
+		if ( array_key_exists ( $comment->comment_parent , $comments_parents ) ) {
+									   $comment->comment_parent = $comments_parents[$comment->comment_parent];
+									   }
+	}
+				 
 	// keep $comments for legacy's sake
 	$wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );
 	$comments = &$wp_query->comments;
