Index: content.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/Attic/content.install,v
retrieving revision 1.14.2.32
diff -b -u -p -r1.14.2.32 content.install
--- content.install	4 Sep 2008 23:01:27 -0000	1.14.2.32
+++ content.install	31 Aug 2009 21:10:19 -0000
@@ -612,3 +612,50 @@ function content_update_1010() {
   variable_set('content_update_1009', TRUE);
   return $ret;
 }
\ No newline at end of file
+
+/**
+ * content_update_1009 was implemented assuming that the Batch API was
+ * present which is not the case in Drupal 5. As a result, only one 
+ * table would have had an index created on nid.
+ */
+function content_update_1011() {
+  $ret = array();
+
+  // Gather list of tables.
+  $tables = array();
+  // Get per-field tables.
+  $result = db_query('SELECT * FROM {node_field_instance} nfi '.
+    ' LEFT JOIN {node_field} nf ON nf.field_name = nfi.field_name WHERE db_storage = %d', CONTENT_DB_STORAGE_PER_FIELD);
+  while ($field = db_fetch_array($result)) {
+    $table = _content_tablename($field['field_name'], CONTENT_DB_STORAGE_PER_FIELD);
+    $tables[$table] = $table;
+  }
+  // Additionally, get all per-type tables.
+  foreach (node_get_types() as $type) {
+    $table = _content_tablename($type->type, CONTENT_DB_STORAGE_PER_CONTENT_TYPE);
+    $tables[$table] = $table;
+  }
+
+  // Iterate through all tables and add index. In order to avoid adding duplicate 
+  // indexes, check for existing indexes using logic from content_db_index_exists()
+  // in the Drupal 6 version of CCK.
+  foreach ($tables as $table) {
+    if (db_table_exists($table)) {
+      switch ($GLOBALS['db_type']) {
+        case 'mysql':
+        case 'mysqli':
+          if (!(bool)db_result(db_query("SHOW INDEX FROM {". $table ."} WHERE key_name = 'nid'"))) {
+            $ret[] = update_sql("ALTER TABLE {". $table ."} ADD INDEX (nid)");
+          }
+        break;
+        case 'pgsql':
+          if (!(bool)db_result(db_query("SELECT COUNT(indexname) FROM pg_indexes WHERE indexname = '{". $table .'_nid_idx' ."}'"))) {
+            $ret[] = update_sql("CREATE INDEX {". $table ."}_nid_idx ON {". $table ."}(nid)");
+          }
+          break;
+      }
+    }
+  }
+  variable_set('content_update_1009', TRUE);
+  return $ret;
+}
\ No newline at end of file
