diff -U3 -r --new-file faceted_search.old/faceted_search.inc faceted_search.new/faceted_search.inc
--- faceted_search.old/faceted_search.inc	2009-01-04 19:36:25.000000000 +0000
+++ faceted_search.new/faceted_search.inc	2009-08-06 20:52:10.505931285 +0100
@@ -1171,7 +1171,8 @@
     // improvement.
     //
     // See http://drupal.org/node/109513 regarding the use of HEAP engine.
-    db_query('CREATE TEMPORARY TABLE '. $this->_results_table .' (nid int unsigned NOT NULL, PRIMARY KEY (nid)) Engine=HEAP '. $query->query(), $query->args(), $this->_results_table);
+    db_query("CREATE TEMPORARY TABLE {$this->_results_table} AS {$query->query()}", $query->args());
+    db_query("ALTER TABLE {$this->_results_table} ADD PRIMARY KEY (nid)");
     $this->_results_count = db_result(db_query('SELECT COUNT(*) FROM '. $this->_results_table));
     $this->_ready = TRUE;
   }
@@ -1615,7 +1616,7 @@
    *   Either 'ASC' or 'DESC'.
    */
   function add_groupby($clause, $order = 'ASC') {
-    $this->groupby[$this->current_part][] = $clause .' '. $order;
+    $this->groupby[$this->current_part][] = $clause;
   }
 
   /**
diff -U3 -r --new-file faceted_search.old/taxonomy_facets.module faceted_search.new/taxonomy_facets.module
--- faceted_search.old/taxonomy_facets.module	2009-03-03 04:55:34.000000000 +0000
+++ faceted_search.new/taxonomy_facets.module	2009-08-06 20:52:10.505931285 +0100
@@ -369,7 +369,9 @@
     $query->add_field('term_data', 'tid', 'tid');
     $query->add_field('term_data', 'name', 'name');
     $query->add_where('term_data.vid = %d', $this->_vocabulary->vid);
-    $query->add_groupby('tid'); // Needed for counting matching nodes.
+    $query->add_groupby('term_data.tid'); // Needed for counting matching nodes.
+    $query->add_groupby('term_data.name'); // Needed for counting matching nodes.
+    $query->add_groupby('term_data.weight'); // Needed for counting matching nodes.
     return TRUE;
   }
 
@@ -478,7 +480,9 @@
     $query->add_field('term_data', 'tid', 'tid');
     $query->add_field('term_data', 'name', 'name');
     $query->add_where('term_hierarchy.parent = %d', $this->_tid);
-    $query->add_groupby('tid'); // Needed for counting matching nodes.
+    $query->add_groupby('term_data.tid'); // Needed for counting matching nodes.
+    $query->add_groupby('term_data.name'); // Needed for counting matching nodes.
+    $query->add_groupby('term_data.weight'); // Needed for counting matching nodes.
     return TRUE;
   }
 
@@ -518,7 +522,7 @@
   // that do not meet those conditions do not belong in the
   // taxonomy_facets_term_node table.
   $tids = array();
-  $results = db_query("SELECT tn.tid, t.vid FROM {node} n INNER JOIN {term_node} tn ON n.vid = tn.vid INNER JOIN {term_data} t ON t.tid = tn.tid INNER JOIN {faceted_search_filters} f ON f.filter_id = t.vid INNER JOIN {vocabulary} v ON t.vid = v.vid WHERE n.nid = %d AND f.filter_key = 'taxonomy' AND f.status = 1 AND v.hierarchy > 0", $nid);
+  $results = db_query("SELECT tn.tid, t.vid FROM {node} n INNER JOIN {term_node} tn ON n.vid = tn.vid INNER JOIN {term_data} t ON t.tid = tn.tid INNER JOIN {faceted_search_filters} f ON f.filter_id = CAST(t.vid AS CHAR) INNER JOIN {vocabulary} v ON t.vid = v.vid WHERE n.nid = %d AND f.filter_key = 'taxonomy' AND f.status = 1 AND v.hierarchy > 0", $nid);
   while ($r = db_fetch_object($results)) {
     // Create associations between the node and all of the term's ancestors.
     $ancestors = taxonomy_get_parents_all($r->tid);

