Ticket #5179: left_join.diff
File left_join.diff, 5.6 KB (added by , 17 years ago) |
---|
-
wp-includes/bookmark.php
112 112 } 113 113 if (!empty($category_query)) { 114 114 $category_query .= ") AND taxonomy = 'link_category'"; 115 $join = " LEFT JOIN $wpdb->term_relationships AS tr ON ($wpdb->links.link_id = tr.object_id) LEFTJOIN $wpdb->term_taxonomy as tt ON tt.term_taxonomy_id = tr.term_taxonomy_id";115 $join = " INNER JOIN $wpdb->term_relationships AS tr ON ($wpdb->links.link_id = tr.object_id) INNER JOIN $wpdb->term_taxonomy as tt ON tt.term_taxonomy_id = tr.term_taxonomy_id"; 116 116 } 117 117 118 118 if (get_option('links_recently_updated_time')) { -
wp-includes/query.php
932 932 } 933 933 934 934 if ( !empty($q['category__in']) ) { 935 $join = " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFTJOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) ";935 $join = " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) "; 936 936 $whichcat .= " AND $wpdb->term_taxonomy.taxonomy = 'category' "; 937 937 $include_cats = "'" . implode("', '", $q['category__in']) . "'"; 938 938 $whichcat .= " AND $wpdb->term_taxonomy.term_id IN ($include_cats) "; … … 973 973 974 974 $q['cat'] = $reqcat; 975 975 976 $join = " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFTJOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) ";976 $join = " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) "; 977 977 $whichcat = " AND $wpdb->term_taxonomy.taxonomy = 'category' "; 978 978 $in_cats = array($q['cat']); 979 979 $in_cats = array_merge($in_cats, get_term_children($q['cat'], 'category')); … … 1015 1015 } 1016 1016 1017 1017 if ( !empty($q['tag__in']) ) { 1018 $join = " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFTJOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) ";1018 $join = " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) "; 1019 1019 $whichcat .= " AND $wpdb->term_taxonomy.taxonomy = 'post_tag' "; 1020 1020 $include_tags = "'" . implode("', '", $q['tag__in']) . "'"; 1021 1021 $whichcat .= " AND $wpdb->term_taxonomy.term_id IN ($include_tags) "; … … 1025 1025 } 1026 1026 1027 1027 if ( !empty($q['tag_slug__in']) ) { 1028 $join = " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) LEFTJOIN $wpdb->terms ON ($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id) ";1028 $join = " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) INNER JOIN $wpdb->terms ON ($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id) "; 1029 1029 $whichcat .= " AND $wpdb->term_taxonomy.taxonomy = 'post_tag' "; 1030 1030 $include_tags = "'" . implode("', '", $q['tag_slug__in']) . "'"; 1031 1031 $whichcat .= " AND $wpdb->terms.slug IN ($include_tags) "; … … 1056 1056 $taxonomy_field = $item == 'tag_slug__and' ? 'slug' : 'term_id'; 1057 1057 1058 1058 $q[$item] = array_unique($q[$item]); 1059 $tsql = "SELECT p.ID FROM $wpdb->posts p LEFT JOIN $wpdb->term_relationships tr ON (p.ID = tr.object_id) LEFT JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) LEFTJOIN $wpdb->terms t ON (tt.term_id = t.term_id)";1059 $tsql = "SELECT p.ID FROM $wpdb->posts p INNER JOIN $wpdb->term_relationships tr ON (p.ID = tr.object_id) INNER JOIN $wpdb->term_taxonomy tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id) INNER JOIN $wpdb->terms t ON (tt.term_id = t.term_id)"; 1060 1060 $tsql .= " WHERE tt.taxonomy = '$taxonomy' AND t.$taxonomy_field IN ('" . implode("', '", $q[$item]) . "')"; 1061 1061 $tsql .= " GROUP BY p.ID HAVING count(p.ID) = " . count($q[$item]); 1062 1062 -
wp-includes/taxonomy.php
1357 1357 } 1358 1358 1359 1359 // Get the object and term ids and stick them in a lookup table 1360 $results = $wpdb->get_results("SELECT object_id, term_taxonomy_id FROM $wpdb->term_relationships LEFTJOIN $wpdb->posts ON object_id = ID WHERE term_taxonomy_id IN (".join(',', array_keys($term_ids)).") AND post_type = 'post' AND post_status = 'publish'");1360 $results = $wpdb->get_results("SELECT object_id, term_taxonomy_id FROM $wpdb->term_relationships INNER JOIN $wpdb->posts ON object_id = ID WHERE term_taxonomy_id IN (".join(',', array_keys($term_ids)).") AND post_type = 'post' AND post_status = 'publish'"); 1361 1361 foreach ( $results as $row ) { 1362 1362 $id = $term_ids[$row->term_taxonomy_id]; 1363 1363 ++$term_items[$id][$row->object_id];