Index: includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.457
diff -u -p -r1.457 bootstrap.inc
--- includes/bootstrap.inc	23 Dec 2010 10:13:53 -0000	1.457
+++ includes/bootstrap.inc	28 Dec 2010 11:20:08 -0000
@@ -2643,44 +2643,53 @@ function ip_address() {
 function drupal_get_schema($table = NULL, $rebuild = FALSE) {
   static $schema = array();
 
-  if (empty($schema) || $rebuild) {
-    // Try to load the schema from cache.
-    if (!$rebuild && $cached = cache_get('schema')) {
-      $schema = $cached->data;
+  // If a table is specified, try to load the individual cache entry for that
+  // table.
+  if (isset($table) && !$rebuild) {
+    if (isset($schema[$table])) {
+      return $schema[$table];
+    }
+    else if ($cached = cache_get('schema:' . $table)) {
+      $schema[$table] = $cached->data;
     }
-    // Otherwise, rebuild the schema cache.
     else {
-      $schema = array();
-      // Load the .install files to get hook_schema.
-      // On some databases this function may be called before bootstrap has
-      // been completed, so we force the functions we need to load just in case.
-      if (function_exists('module_load_all_includes')) {
-        // This function can be called very early in the bootstrap process, so
-        // we force the module_list() cache to be refreshed to ensure that it
-        // contains the complete list of modules before we go on to call
-        // module_load_all_includes().
-        module_list(TRUE);
-        module_load_all_includes('install');
-      }
+      // Rebuild the full schema cache in the case of a cache miss.
+      $rebuild = TRUE;
+    }
+  }
+  else {
+    $schema = array();
+    // Load the .install files to get hook_schema.
+    // On some databases this function may be called before bootstrap has
+    // been completed, so we force the functions we need to load just in case.
+    if (function_exists('module_load_all_includes')) {
+      // This function can be called very early in the bootstrap process, so
+      // we force the module_list() cache to be refreshed to ensure that it
+      // contains the complete list of modules before we go on to call
+      // module_load_all_includes().
+      module_list(TRUE);
+      module_load_all_includes('install');
+    }
 
-      require_once DRUPAL_ROOT . '/includes/common.inc';
-      // Invoke hook_schema for all modules.
-      foreach (module_implements('schema') as $module) {
-        // Cast the result of hook_schema() to an array, as a NULL return value
-        // would cause array_merge() to set the $schema variable to NULL as well.
-        // That would break modules which use $schema further down the line.
-        $current = (array) module_invoke($module, 'schema');
-        // Set 'module' and 'name' keys for each table, and remove descriptions,
-        // as they needlessly slow down cache_get() for every single request.
-        _drupal_schema_initialize($current, $module);
-        $schema = array_merge($schema, $current);
-      }
+    require_once DRUPAL_ROOT . '/includes/common.inc';
+    // Invoke hook_schema for all modules.
+    foreach (module_implements('schema') as $module) {
+      // Cast the result of hook_schema() to an array, as a NULL return value
+      // would cause array_merge() to set the $schema variable to NULL as well.
+      // That would break modules which use $schema further down the line.
+      $current = (array) module_invoke($module, 'schema');
+      // Set 'module' and 'name' keys for each table, and remove descriptions,
+      // as they needlessly slow down cache_get() for every single request.
+      _drupal_schema_initialize($current, $module);
+      $schema = array_merge($schema, $current);
+    }
 
-      drupal_alter('schema', $schema);
-      // If the schema is empty, avoid saving it: some database engines require
-      // the schema to perform queries, and this could lead to infinite loops.
-      if (!empty($schema) && (drupal_get_bootstrap_phase() == DRUPAL_BOOTSTRAP_FULL)) {
-        cache_set('schema', $schema);
+    drupal_alter('schema', $schema);
+    // If the schema is empty, avoid saving it: some database engines require
+    // the schema to perform queries, and this could lead to infinite loops.
+    if ($rebuild && !empty($schema) && (drupal_get_bootstrap_phase() == DRUPAL_BOOTSTRAP_FULL)) {
+      foreach ($schema as $key => $definition) {
+        cache_set('schema:' . $key, $definition);
       }
     }
   }
