| 725 | | $where[] = "( |
| 726 | | SELECT COUNT(1) |
| | 725 | /* selects in wheres are very slow in mysql |
| | 726 | so it needs to be broken down manually and done |
| | 727 | by a join*/ |
| | 728 | // make sure we don't have duplicate tempary tables on high load |
| | 729 | do { |
| | 730 | $tableid = time().'_'.floor(rand(1,100000)); |
| | 731 | $table = "temp_tax_" . $tableid; |
| | 732 | $table1 = "temp_tax1_" .$tableid; |
| | 733 | $wpdb->query( |
| | 734 | $wpdb->prepare( "SHOW TABLES LIKE ? ", $table1)); |
| | 735 | } while($wpdb->num_rows); |
| | 736 | //create temp |
| | 737 | $wpdb->query("create temporary table $table ( object_id bigint(20) unsigned, term_taxonomy_id bigint(20) unsigned) "); |
| | 738 | $wpdb->query("create temporary table $table1 ( object_id bigint(20) unsigned, c int ) "); |
| | 739 | $wpdb->query("insert into $table select object_id , term_taxonomy_id from wp_term_relationships where term_taxonomy_id IN ($terms)"); |
| | 740 | $wpdb->query("insert into $table1 select object_id,count(*) from $table group by object_id"); |
| | 741 | $join .= " , $table1 AS tt "; |
| | 742 | // get rid of first temp table, second is needed for query |
| | 743 | $wpdb->query("DROP TABLE $table"); |
| | 744 | $where[] = " tt.c = $num_terms AND tt.object_id = wp_posts.ID "; |
| | 745 | |
| | 746 | /*old code |
| | 747 | ( |
| | 748 | SELECT COUNT(1) |