Index: wp-includes/query.php
===================================================================
--- wp-includes/query.php	(revision 8735)
+++ wp-includes/query.php	(working copy)
@@ -1046,12 +1046,17 @@
 		}
 
 		if ( !empty($q['category__not_in']) ) {
-			$ids = get_objects_in_term($q['category__not_in'], 'category');
-			if ( is_wp_error( $ids ) )
-				return $ids;
-			if ( is_array($ids) && count($ids > 0) ) {
-				$out_posts = "'" . implode("', '", $ids) . "'";
-				$whichcat .= " AND $wpdb->posts.ID NOT IN ($out_posts)";
+			if ( $wpdb->supports_subqueries() ) {
+				$cat_string = "'" . implode("', '", $q['category__not_in']) . "'";
+				$whichcat .= " AND $wpdb->posts.ID NOT IN (SELECT $wpdb->term_relationships.object_id FROM $wpdb->term_relationships WHERE $wpdb->term_relationships.term_taxonomy_id IN ($cat_string) )";
+			} else {
+				$ids = get_objects_in_term($q['category__not_in'], 'category');
+				if ( is_wp_error( $ids ) )
+					return $ids;
+				if ( is_array($ids) && count($ids > 0) ) {
+					$out_posts = "'" . implode("', '", $ids) . "'";
+					$whichcat .= " AND $wpdb->posts.ID NOT IN ($out_posts)";
+				}
 			}
 		}
 
Index: wp-includes/wp-db.php
===================================================================
--- wp-includes/wp-db.php	(revision 8735)
+++ wp-includes/wp-db.php	(working copy)
@@ -924,6 +924,17 @@
 	}
 
 	/**
+	 * Whether of not the database version supports sub-queries.
+	 *
+	 * @since 2.7
+	 *
+	 * @return bool True if sub-queries are supported, false if version does not
+	 */
+	function supports_subqueries() {
+		return ( version_compare(mysql_get_server_info($this->dbh), '4.1.0', '>=') );
+	}
+
+	/**
 	 * Retrieve the name of the function that called wpdb.
 	 *
 	 * Requires PHP 4.3 and searches up the list of functions until it reaches
