--- mk-slave-prefetch	2008-06-01 11:28:21.000000000 +0000
+++ mk-slave-parallel-prefetch	2008-06-01 14:04:16.000000000 +0000
@@ -770,6 +770,7 @@
 # End DSNParser package
 # ###########################################################################
 
+
 # ###########################################################################
 # LogParser package 1755
 # ###########################################################################
@@ -1325,6 +1326,28 @@
 $dbh->{InactiveDestroy}  = 1;
 $dbh->do('/*!40001 set @@session.query_cache_type=OFF */');
 
+use threads;
+use Thread::Queue;
+
+my $queue = new Thread::Queue;
+my $threadcount=4;
+
+while($threadcount--) {
+	threads::async {
+		my $query;
+		my $thdbh = $dsn_parser->get_dbh(
+			$dsn_parser->get_cxn_params(\%opts), { AutoCommit => 1 });
+		$thdbh->{FetchHashKeyName} = 'NAME_lc';
+		$thdbh->{InactiveDestroy}  = 1;
+		$thdbh->do('/*!40001 set @@session.query_cache_type=OFF */');
+		print $queue."\n";
+		while ($query = $queue->dequeue ) {
+			eval { $thdbh->do('/* AAAAA */ '. $query); }
+		}
+	}
+}	
+
+
 # ############################################################################
 # Daemonize only after (potentially) asking for passwords for --askpass.
 # ############################################################################
@@ -1480,61 +1503,18 @@
             # Convert the event to a SELECT and print/execute it.
             my $select = $qn->convert_to_select($event->{arg});
             if ( $select =~ m/\A\s*(?:set|select|use)/i ) {
-               my $fingerprint = $qn->fingerprint($event->{arg});
-               if ( (my $avg = get_avg($fingerprint)) < $opts{q} ) {
-
                   # Safeguard as much as possible against really enormous
                   # result sets.
                   my $sql = $qn->convert_select_list($select);
-                  if ( $have_subqueries && !have_seen_query($fingerprint)) {
-                     # Wrap in a "derived table," but only if it hasn't been
-                     # seen before.  This way, really short queries avoid the
-                     # overhead of creating the temp table.
-                     $sql = $qn->wrap_in_derived($sql);
-                  }
-
                   # Do it!
-                  $ENV{MKDEBUG} && _d($sql);
                   $stats{do_query}++;
                   if ( $opts{x} ) {
-                     eval {
-                        my $start = gettimeofday();
-                        $dbh->do($sql);
-                        store_avg($fingerprint, gettimeofday() - $start);
-                     };
-                     if ( $EVAL_ERROR ) {
-                        $stats{query_error}++;
-                        if ( $ENV{MKDEBUG} ) {
-                           _d($EVAL_ERROR);
-                           _d("SQL was: ", $event->{arg});
-                        }
-                     }
+			$queue->enqueue($sql);
                   }
                   elsif ( $opts{print} ) {
                      print $sql, ";\n";
                   }
-
                }
-
-               # The query's average execution time is longer than the
-               # specified limit, so we skip it and just wait for the master
-               # to pass it by.
-               else {
-                  $ENV{MKDEBUG}
-                     && _d("Avg time $avg too long for ", $fingerprint);
-                  $stats{query_too_long}++;
-                  wait_for_master(\%slave, $pos + 1);
-                  %slave    = get_status($dbh);
-                  $last_chk = $i;
-               }
-
-            }
-            else {
-               $stats{query_not_rewritten}++;
-               if ( $ENV{MKDEBUG} || $opts{printnonrewritten} ) {
-                  _d($event->{arg});
-               }
-            }
          }
 
          $ENV{MKDEBUG} && _d('Closing filehandle');