diff --git a/includes/database/database.inc b/includes/database/database.inc
index 4cc1a33..8d4d68b 100644
--- a/includes/database/database.inc
+++ b/includes/database/database.inc
@@ -511,6 +511,10 @@ abstract class DatabaseConnection extends PDO {
     $this->logger = $logger;
   }
 
+  public function setChangeLogger(DatabaseChangeLog $logger) {
+    $this->changeLogger = $logger;
+  }
+
   /**
    * Gets the current logging object for this connection.
    *
@@ -522,6 +526,10 @@ abstract class DatabaseConnection extends PDO {
     return $this->logger;
   }
 
+  public function getChangeLogger() {
+    return $this->changeLogger;
+  }
+
   /**
    * Creates the appropriate sequence name for a given table and serial field.
    *
@@ -1326,6 +1334,7 @@ abstract class Database {
    * @var array
    */
   static protected $logs = array();
+  static protected $changeLogs = array();
 
   /**
    * Starts logging a given logging key on the specified connection.
@@ -1359,6 +1368,23 @@ abstract class Database {
     return self::$logs[$key];
   }
 
+  final public static function startChangeLog($logging_key, $key = 'default') {
+    if (empty(self::$changeLogs[$key])) {
+      self::$changeLogs[$key] = new DatabaseChangeLog($key);
+
+      // Every target already active for this connection key needs to have the
+      // logging object associated with it.  
+      if (!empty(self::$connections[$key])) {
+        foreach (self::$connections[$key] as $connection) {
+          $connection->setChangeLogger(self::$changeLogs[$key]);
+        }
+      }  
+    }  
+
+    self::$changeLogs[$key]->start($logging_key);
+    return self::$changeLogs[$key];
+  }
+
   /**
    * Retrieves the queries logged on for given logging key.
    *
@@ -1386,6 +1412,15 @@ abstract class Database {
     return $queries;
   }
 
+  final public static function getChangeLog($logging_key, $key = 'default') {
+    if (empty(self::$changeLogs[$key])) {
+      return NULL;
+    }
+    $queries = self::$changeLogs[$key]->get($logging_key);
+    self::$changeLogs[$key]->end($logging_key);
+    return $queries;
+  }
+
   /**
    * Gets the connection object for the specified database key and target.
    *
diff --git a/includes/database/log.inc b/includes/database/log.inc
index ec27ef8..616048e 100644
--- a/includes/database/log.inc
+++ b/includes/database/log.inc
@@ -157,3 +157,28 @@ class DatabaseLog {
     }
   }
 }
+
+class DatabaseChangeLog extends DatabaseLog {
+ /**
+   * Log a change query to all active logging keys.
+   *
+   * @param $statement
+   *   The prepared statement object to log.
+   * @param $args
+   *   The arguments passed to the statement object.
+   * @param $time
+   *   The time in milliseconds the query took to execute.
+   */
+  public function log($query, $table, $args, $options, $time) {
+    foreach (array_keys($this->queryLog) as $key) {
+      $this->queryLog[$key][] = array(
+        'query' => $query,
+        'table' => $table,
+        'args' => $args,
+        'options' => $options,
+        'caller' => $this->findCaller(),
+        'time' => $time,
+      );
+    }
+  }
+}
diff --git a/includes/database/mysql/query.inc b/includes/database/mysql/query.inc
index 888b6a5..8c4bb02 100644
--- a/includes/database/mysql/query.inc
+++ b/includes/database/mysql/query.inc
@@ -32,8 +32,16 @@ class InsertQuery_mysql extends InsertQuery {
     else {
       $values = $this->fromQuery->getArguments();
     }
-
-    $last_insert_id = $this->connection->query((string) $this, $values, $this->queryOptions);
+    $change_logger = $this->connection->getLogger();
+    if (!empty($change_logger)) {
+      $query_start = microtime(TRUE);
+    }
+    $sql = (string) $this;
+    $last_insert_id = $this->connection->query($sql, $values, $this->queryOptions);
+    if (!empty($change_logger)) {
+      $query_end = microtime(TRUE);
+      $change_logger->changeLog($sql, $insert_values, $this->queryOptions, $query_end - $query_start);
+    }
 
     // Re-initialize the values array so that we can re-use this query.
     $this->insertValues = array();
diff --git a/includes/database/query.inc b/includes/database/query.inc
index 23b652f..d280dc2 100644
--- a/includes/database/query.inc
+++ b/includes/database/query.inc
@@ -77,7 +77,7 @@ interface QueryConditionInterface {
 
   /**
    * Sets a condition that the specified subquery returns values.
-   * 
+   *
    * @param SelectQueryInterface $select
    *   The subquery that must contain results.
    *
@@ -85,10 +85,10 @@ interface QueryConditionInterface {
    *   The called object.
    */
   public function exists(SelectQueryInterface $select);
-  
+
   /**
    * Sets a condition that the specified subquery returns no values.
-   * 
+   *
    * @param SelectQueryInterface $select
    *   The subquery that must not contain results.
    *
@@ -96,7 +96,7 @@ interface QueryConditionInterface {
    *   The called object.
    */
   public function notExists(SelectQueryInterface $select);
-  
+
   /**
    * Gets a complete list of all conditions in this conditional clause.
    *
@@ -264,14 +264,14 @@ abstract class Query implements QueryPlaceholderInterface {
 
   /**
    * The target of the connection object.
-   * 
+   *
    * @var string
    */
   protected $connectionTarget;
 
   /**
    * The key of the connection object.
-   * 
+   *
    * @var string
    */
   protected $connectionKey;
@@ -597,11 +597,19 @@ class InsertQuery extends Query {
     // we wrap it in a transaction so that it is atomic where possible. On many
     // databases, such as SQLite, this is also a notable performance boost.
     $transaction = $this->connection->startTransaction();
+    $change_logger = $this->connection->getLogger();
 
     try {
       $sql = (string) $this;
       foreach ($this->insertValues as $insert_values) {
+        if (!empty($change_logger)) {
+          $query_start = microtime(TRUE);
+        }
         $last_insert_id = $this->connection->query($sql, $insert_values, $this->queryOptions);
+        if (!empty($change_logger)) {
+          $query_end = microtime(TRUE);
+          $change_logger->changeLog($sql, $insert_values, $this->queryOptions, $query_end - $query_start);
+        }
       }
     }
     catch (Exception $e) {
@@ -764,7 +772,7 @@ class DeleteQuery extends Query implements QueryConditionInterface {
     $this->condition->notExists($select);
     return $this;
   }
-  
+
   /**
    * Implements QueryConditionInterface::conditions().
    */
@@ -807,7 +815,17 @@ class DeleteQuery extends Query implements QueryConditionInterface {
       $values = $this->condition->arguments();
     }
 
-    return $this->connection->query((string) $this, $values, $this->queryOptions);
+    $change_logger = $this->connection->getLogger();
+    if (!empty($change_logger)) {
+      $query_start = microtime(TRUE);
+    }
+    $sql = (string) $this;
+    $return = $this->connection->query($sql, $values, $this->queryOptions);
+    if (!empty($change_logger)) {
+      $query_end = microtime(TRUE);
+      $change_logger->changeLog($sql, $values, $this->queryOptions, $query_end - $query_start);
+    }
+    return $return;
   }
 
   /**
@@ -875,7 +893,17 @@ class TruncateQuery extends Query {
    *   Return value is dependent on the database type.
    */
   public function execute() {
-    return $this->connection->query((string) $this, array(), $this->queryOptions);
+    $change_logger = $this->connection->getLogger();
+    if (!empty($change_logger)) {
+      $query_start = microtime(TRUE);
+    }
+    $sql = (string) $this;
+    $return = $this->connection->query($sql, array(), $this->queryOptions);
+    if (!empty($change_logger)) {
+      $query_end = microtime(TRUE);
+      $change_logger->changeLog($sql, array(), $this->queryOptions, $query_end - $query_start);
+    }
+    return $return;
   }
 
   /**
@@ -999,7 +1027,7 @@ class UpdateQuery extends Query implements QueryConditionInterface {
     $this->condition->notExists($select);
     return $this;
   }
-  
+
   /**
    * Implements QueryConditionInterface::conditions().
    */
@@ -1102,7 +1130,17 @@ class UpdateQuery extends Query implements QueryConditionInterface {
       $update_values = array_merge($update_values, $this->condition->arguments());
     }
 
-    return $this->connection->query((string) $this, $update_values, $this->queryOptions);
+    $change_logger = $this->connection->getLogger();
+    if (!empty($change_logger)) {
+      $query_start = microtime(TRUE);
+    }
+    $sql = (string) $this;
+    $return = $this->connection->query($sql, $update_values, $this->queryOptions);
+    if (!empty($change_logger)) {
+      $query_end = microtime(TRUE);
+      $change_logger->changeLog($sql, $update_values, $this->queryOptions, $query_end - $query_start);
+    }
+    return $return;
   }
 
   /**
@@ -1484,7 +1522,7 @@ class MergeQuery extends Query implements QueryConditionInterface {
     $this->condition->notExists($select);
     return $this;
   }
-  
+
   /**
    * Implements QueryConditionInterface::conditions().
    */
@@ -1689,14 +1727,14 @@ class DatabaseCondition implements QueryConditionInterface, Countable {
   public function exists(SelectQueryInterface $select) {
     return $this->condition('', $select, 'EXISTS');
   }
-  
+
   /**
    * Implements QueryConditionInterface::notExists().
    */
   public function notExists(SelectQueryInterface $select) {
     return $this->condition('', $select, 'NOT EXISTS');
   }
-  
+
   /**
    * Implements QueryConditionInterface::conditions().
    */
diff --git a/includes/database/sqlite/query.inc b/includes/database/sqlite/query.inc
index 6b8a72f..ed12fde 100644
--- a/includes/database/sqlite/query.inc
+++ b/includes/database/sqlite/query.inc
@@ -27,7 +27,16 @@ class InsertQuery_sqlite extends InsertQuery {
       return parent::execute();
     }
     else {
-      return $this->connection->query('INSERT INTO {' . $this->table . '} DEFAULT VALUES', array(), $this->queryOptions);
+      $change_logger = $this->connection->getLogger();
+      $sql = 'INSERT INTO {' . $this->table . '} DEFAULT VALUES';
+      if (!empty($change_logger)) {
+        $query_start = microtime(TRUE);
+      }
+      $return = $this->connection->query($sql, array(), $this->queryOptions);
+      if (!empty($change_logger)) {
+        $query_end = microtime(TRUE);
+        $change_logger->changeLog($sql, array(), $this->queryOptions, $query_end - $query_start);
+      }
     }
   }
 
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index b60c682..b9130da 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -1232,11 +1232,16 @@ class DrupalWebTestCase extends DrupalTestCase {
     global $user, $language, $conf;
 
     // Generate a temporary prefixed database to ensure that tests have a clean starting point.
-    $this->databasePrefix = 'simpletest' . mt_rand(1000, 1000000);
-    db_update('simpletest_test_id')
-      ->fields(array('last_prefix' => $this->databasePrefix))
-      ->condition('test_id', $this->testId)
-      ->execute();
+    $changelog_key = 'DrupalWebTestCase::setup';
+    $queries = Database::getChangeLog($changelog_key);
+    if (!$queries) {
+      $this->databasePrefix = 'simpletest' . mt_rand(1000, 1000000);
+      db_update('simpletest_test_id')
+        ->fields(array('last_prefix' => $this->databasePrefix))
+        ->condition('test_id', $this->testId)
+        ->execute();
+      Database::startChangeLog($changelog_key);
+    }
 
     // Clone the current connection and replace the current prefix.
     $connection_info = Database::getConnectionInfo('default');
@@ -1289,22 +1294,34 @@ class DrupalWebTestCase extends DrupalTestCase {
     $test_info['test_run_id'] = $this->databasePrefix;
     $test_info['in_child_site'] = FALSE;
 
-    include_once DRUPAL_ROOT . '/includes/install.inc';
-    drupal_install_system();
-
-    $this->preloadRegistry();
+    if ($queries) {
+      $empty = array();
+      $connection = Database::getConnection();
+      foreach ($queries as $query) {
+        if (!isset($empty[$query['table']])) {
+          db_truncate($query['table'])->execute();
+          $empty[$query['table']] = TRUE;
+        }
+        $connection->query($query['query'], $query['args'], $query['options']);
+      }
+    }
+    else {
+      include_once DRUPAL_ROOT . '/includes/install.inc';
+      drupal_install_system();
 
-    // Set path variables.
-    variable_set('file_public_path', $public_files_directory);
-    variable_set('file_private_path', $private_files_directory);
-    variable_set('file_temporary_path', $temp_files_directory);
+      // Set path variables.
+      variable_set('file_public_path', $public_files_directory);
+      variable_set('file_private_path', $private_files_directory);
+      variable_set('file_temporary_path', $temp_files_directory);
 
-    // Include the testing profile.
-    variable_set('install_profile', $this->profile);
-    $profile_details = install_profile_info($this->profile, 'en');
+      // Include the testing profile.
+      variable_set('install_profile', $this->profile);
+      $profile_details = install_profile_info($this->profile, 'en');
 
-    // Install the modules specified by the testing profile.
-    module_enable($profile_details['dependencies'], FALSE);
+      // Install the modules specified by the testing profile.
+      module_enable($profile_details['dependencies'], FALSE);
+      Database::endChangeLog($changelog_key);
+    }
 
     // Install modules needed for this test. This could have been passed in as
     // either a single array argument or a variable number of string arguments.
@@ -1354,42 +1371,6 @@ class DrupalWebTestCase extends DrupalTestCase {
   }
 
   /**
-   * Preload the registry from the testing site.
-   *
-   * This method is called by DrupalWebTestCase::setUp(), and preloads the
-   * registry from the testing site to cut down on the time it takes to
-   * set up a clean environment for the current test run.
-   */
-  protected function preloadRegistry() {
-    // Use two separate queries, each with their own connections: copy the
-    // {registry} and {registry_file} tables over from the parent installation
-    // to the child installation.
-    $original_connection = Database::getConnection('default', 'simpletest_original_default');
-    $test_connection = Database::getConnection();
-
-    foreach (array('registry', 'registry_file') as $table) {
-      // Find the records from the parent database.
-      $source_query = $original_connection
-        ->select($table, array(), array('fetch' => PDO::FETCH_ASSOC))
-        ->fields($table);
-
-      $dest_query = $test_connection->insert($table);
-
-      $first = TRUE;
-      foreach ($source_query->execute() as $row) {
-        if ($first) {
-          $dest_query->fields(array_keys($row));
-          $first = FALSE;
-        }
-        // Insert the records into the child database.
-        $dest_query->values($row);
-      }
-
-      $dest_query->execute();
-    }
-  }
-
-  /**
    * Reset all data structures after having enabled new modules.
    *
    * This method is called by DrupalWebTestCase::setUp() after enabling
