Index: wp-includes/taxonomy.php
===================================================================
--- wp-includes/taxonomy.php	(revision 24796)
+++ wp-includes/taxonomy.php	(working copy)
@@ -722,12 +722,35 @@
 
 				$terms = implode( ',', $terms );
 
-				$where[] = "(
-					SELECT COUNT(1)
+				/* selects in wheres are very slow in mysql
+				so it needs to be broken down manually and done 
+				by a join*/
+				// make sure we don't have duplicate tempary tables on high load
+				do  {
+					$tableid = time().'_'.floor(rand(1,100000));
+					$table = "temp_tax_" . $tableid;
+					$table1 = "temp_tax1_" .$tableid;
+					$wpdb->query( 
+						$wpdb->prepare( "SHOW TABLES LIKE ? ", $table1));
+				} while($wpdb->num_rows);
+				//create temp
+				$wpdb->query("create temporary table $table ( object_id bigint(20) unsigned, term_taxonomy_id bigint(20) unsigned) ");
+				$wpdb->query("create temporary table $table1 ( object_id bigint(20) unsigned, c int ) ");
+				$wpdb->query("insert into $table select  object_id , term_taxonomy_id from  wp_term_relationships where term_taxonomy_id IN ($terms)");
+				$wpdb->query("insert into $table1 select object_id,count(*) from $table group by object_id");
+				$join .= " , $table1 AS tt ";
+				// get rid of first temp table, second is needed for query
+				$wpdb->query("DROP TABLE $table");
+				$where[] = " tt.c = $num_terms AND tt.object_id = wp_posts.ID ";
+
+/*old code
+				(
+					SELECT COUNT(1) 
 					FROM $wpdb->term_relationships
 					WHERE term_taxonomy_id IN ($terms)
 					AND object_id = $primary_table.$primary_id_column
 				) = $num_terms";
+*/
 			}
 
 			$i++;
