Index: modules/aggregator/aggregator.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/aggregator/aggregator.install,v
retrieving revision 1.12
diff -u -p -r1.12 aggregator.install
--- modules/aggregator/aggregator.install	4 Nov 2007 14:33:06 -0000	1.12
+++ modules/aggregator/aggregator.install	21 Nov 2007 03:49:22 -0000
@@ -23,6 +23,23 @@ function aggregator_uninstall() {
 }
 
 /**
+ * Drupal 5.x to 6.x updates.
+ */
+ 
+/**
+ * Alter primary keys to make them more useful.
+ */
+function aggregator_update_6000() {
+  $ret = array();
+  db_drop_primary_key($ret, 'aggregator_category_feed');
+  db_add_primary_key($ret, 'aggregator_category_feed', array('cid', 'fid'));
+
+  db_drop_primary_key($ret, 'aggregator_category_item');
+  db_add_primary_key($ret, 'aggregator_category_item', array('cid', 'iid'));  
+  return $ret;
+}
+
+/**
  * Implementation of hook_schema().
  */
 function aggregator_schema() {
@@ -75,7 +92,8 @@ function aggregator_schema() {
         'description' => t('The {aggregator_category}.cid to which the feed is being assigned.'),
      )
     ),
-    'primary key' => array('fid', 'cid'),
+    'primary key' => array('cid', 'fid'),
+    'indexes' => array('fid' => array('fid')),
   );
 
   $schema['aggregator_category_item'] = array(
@@ -94,7 +112,8 @@ function aggregator_schema() {
         'description' => t('The {aggregator_category}.cid to which the feed item is being assigned.'),
       )
     ),
-    'primary key' => array('iid', 'cid'),
+    'primary key' => array('cid', 'iid'),
+    'indexes' => array('iid' => array('iid')),
   );
 
   $schema['aggregator_feed'] = array(
@@ -171,11 +190,11 @@ function aggregator_schema() {
         'description' => t("Number of items to display in the feed's block."),
       )
     ),
+    'primary key' => array('fid'),
     'unique keys' => array(
       'url'  => array('url'),
-      'title' => array('title')
+      'title' => array('title'),
     ),
-    'primary key' => array('fid'),
   );
 
   $schema['aggregator_item'] = array(
@@ -231,8 +250,8 @@ function aggregator_schema() {
         'description' => t('Unique identifier for the feed item.'),
       )
     ),
-    'indexes' => array('fid' => array('fid')),
     'primary key' => array('iid'),
+    'indexes' => array('fid' => array('fid')),
   );
 
   return $schema;
Index: modules/block/block.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/block/block.install,v
retrieving revision 1.7
diff -u -p -r1.7 block.install
--- modules/block/block.install	14 Nov 2007 09:31:04 -0000	1.7
+++ modules/block/block.install	21 Nov 2007 03:49:22 -0000
@@ -29,7 +29,7 @@ function block_schema() {
       ),
       'theme' => array(
         'type' => 'varchar',
-        'length' => 255,
+        'length' => 64,
         'not null' => TRUE,
         'default' => '',
         'description' => t('The theme under which the block settings apply.'),
@@ -97,6 +97,12 @@ function block_schema() {
       ),
     ),
     'primary key' => array('bid'),
+    'unique keys' => array(
+      'tmd' => array('theme', 'module', 'delta'),
+    ),
+    'indexes' => array(
+      'list' => array('theme', 'status', 'region', 'weight', 'module'),    
+    ),
   );
 
   $schema['blocks_roles'] = array(
@@ -126,6 +132,9 @@ function block_schema() {
       'delta',
       'rid'
     ),
+    'indexes' => array(
+      'rid' => array('rid'),
+    ),
   );
 
   $schema['boxes'] = array(
Index: modules/book/book.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/book/book.install,v
retrieving revision 1.12
diff -u -p -r1.12 book.install
--- modules/book/book.install	25 Oct 2007 15:32:55 -0000	1.12
+++ modules/book/book.install	21 Nov 2007 03:49:22 -0000
@@ -68,11 +68,13 @@ function book_update_6000() {
         'nid'     => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
         'bid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
       ),
+      'primary key' => array('mlid'),
+      'unique keys' => array(
+        'nid' => array('nid'),      
+      ),
       'indexes' => array(
-        'nid'     => array('nid'),
-        'bid' => array('bid')
+        'bid' => array('bid'),
       ),
-      'primary key' => array('mlid'),
     );
     // Add the node type.
     _book_install_type_create();
@@ -273,11 +275,13 @@ function book_schema() {
         'description' => t("The book ID is the {book}.nid of the top-level page."),
       ),
     ),
+    'primary key' => array('mlid'),
+    'unique keys' => array(
+      'nid' => array('nid'),      
+    ),
     'indexes' => array(
-      'nid'     => array('nid'),
-      'bid' => array('bid')
+      'bid' => array('bid'),
     ),
-    'primary key' => array('mlid'),
   );
 
   return $schema;
Index: modules/comment/comment.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.install,v
retrieving revision 1.9
diff -u -p -r1.9 comment.install
--- modules/comment/comment.install	7 Nov 2007 15:54:49 -0000	1.9
+++ modules/comment/comment.install	21 Nov 2007 03:49:22 -0000
@@ -154,7 +154,7 @@ function comment_schema() {
     ),
     'indexes' => array(
       'nid'    => array('nid'),
-      'status' => array('status')
+      'status' => array('status'), // This index is probably unused
     ),
     'primary key' => array('cid'),
   );
@@ -195,8 +195,10 @@ function comment_schema() {
          'description' => t('The total number of comments on this node.'),
        ),
       ),
-      'indexes' => array('node_comment_timestamp' => array('last_comment_timestamp')),
       'primary key' => array('nid'),
+      'indexes' => array(
+        'node_comment_timestamp' => array('last_comment_timestamp'),
+      ),
   );
 
   return $schema;
Index: modules/contact/contact.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/contact/contact.install,v
retrieving revision 1.9
diff -u -p -r1.9 contact.install
--- modules/contact/contact.install	10 Oct 2007 11:39:32 -0000	1.9
+++ modules/contact/contact.install	21 Nov 2007 03:49:22 -0000
@@ -22,6 +22,20 @@ function contact_uninstall() {
 }
 
 /**
+ * Drupal 5.x to 6.x updates.
+ */
+ 
+/**
+ * Add new table index.
+ */
+function contact_update_6000() {
+  $ret = array();
+  db_add_index($ret, 'contact', 'list', array('weight', 'category'));
+  
+  return $ret;
+}
+
+/**
  * Implementation of hook_schema().
  */
 function contact_schema() {
@@ -68,10 +82,14 @@ function contact_schema() {
         'description' => t('Flag to indicate whether or not category is selected by default. (1 = Yes, 0 = No)'),
       ),
     ),
-    'unique keys' => array('category' => array('category')),
     'primary key' => array('cid'),
+    'unique keys' => array(
+      'category' => array('category'),
+    ),
+    'indexes' => array(
+      'list' => array('weight', 'category'),
+    ),
   );
 
   return $schema;
 }
-
Index: modules/filter/filter.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.install,v
retrieving revision 1.3
diff -u -p -r1.3 filter.install
--- modules/filter/filter.install	4 Nov 2007 14:33:06 -0000	1.3
+++ modules/filter/filter.install	21 Nov 2007 03:49:22 -0000
@@ -42,7 +42,12 @@ function filter_schema() {
       )
     ),
     'primary key' => array('fid'),
-    'indexes' => array('weight' => array('weight')),
+    'unique keys' => array(
+      'fmd' => array('format', 'module', 'delta'),
+    ),
+    'indexes' => array(
+      'list' => array('format', 'weight', 'module', 'delta'),
+    ),
   );
   $schema['filter_formats'] = array(
     'description' => t('Stores input formats: custom groupings of filters, such as Filtered HTML.'),
@@ -64,7 +69,7 @@ function filter_schema() {
         'length' => 255,
         'not null' => TRUE,
         'default' => '',
-        'description' => t('A comma-separated string of roles; references {role}.rid.'),
+        'description' => t('A comma-separated string of roles; references {role}.rid.'), // This is stupid.
       ),
       'cache' => array(
         'type' => 'int',
@@ -74,8 +79,8 @@ function filter_schema() {
         'description' => t('Flag to indicate whether format is cachable. (1 = cachable, 0 = not cachable)'),
       ),
     ),
-    'unique keys' => array('name' => array('name')),
     'primary key' => array('format'),
+    'unique keys' => array('name' => array('name')),
   );
 
   $schema['cache_filter'] = drupal_get_schema_unprocessed('system', 'cache');
Index: modules/filter/filter.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/filter/filter.module,v
retrieving revision 1.190
diff -u -p -r1.190 filter.module
--- modules/filter/filter.module	22 Oct 2007 10:32:03 -0000	1.190
+++ modules/filter/filter.module	21 Nov 2007 03:49:22 -0000
@@ -369,7 +369,7 @@ function filter_list_format($format) {
 
   if (!isset($filters[$format])) {
     $filters[$format] = array();
-    $result = db_query("SELECT * FROM {filters} WHERE format = %d ORDER BY weight ASC", $format);
+    $result = db_query("SELECT * FROM {filters} WHERE format = %d ORDER BY weight, module, delta", $format);
     while ($filter = db_fetch_object($result)) {
       $list = module_invoke($filter->module, 'filter', 'list');
       if (isset($list) && is_array($list) && isset($list[$filter->delta])) {
Index: modules/locale/locale.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/locale/locale.install,v
retrieving revision 1.21
diff -u -p -r1.21 locale.install
--- modules/locale/locale.install	15 Nov 2007 13:27:45 -0000	1.21
+++ modules/locale/locale.install	21 Nov 2007 03:49:22 -0000
@@ -233,6 +233,9 @@ function locale_schema() {
       ),
     ),
     'primary key' => array('language'),
+    'indexes' => array(
+      'list' => array('weight', 'name'),
+    ),
   );
 
   $schema['locales_source'] = array(
@@ -272,8 +275,9 @@ function locale_schema() {
       ),
     ),
     'primary key' => array('lid'),
-    'indexes' => array
-        ('source' => array(array('source', 30))),
+    'indexes' => array(
+      'source' => array(array('source', 30)),
+    ),
   );
 
   $schema['locales_target'] = array(
@@ -300,7 +304,7 @@ function locale_schema() {
       ),
       'plid' => array(
         'type' => 'int',
-        'not null' => TRUE,
+        'not null' => TRUE, // This should be NULL for no referenced string, not zero.
         'default' => 0,
         'description' => t('Parent lid (lid of the previous string in the plural chain) in case of plural strings. References {locales_source}.lid.'),
       ),
@@ -311,11 +315,11 @@ function locale_schema() {
         'description' => t('Plural index number in case of plural strings.'),
       ),
     ),
+    'primary key' => array('language', 'lid', 'plural'),
     'indexes' => array(
-      'language'   => array('language'),
-      'lid'    => array('lid'),
-      'plid'   => array('plid'),
-      'plural' => array('plural')
+      'lid'      => array('lid'),
+      'plid'     => array('plid'),
+      'plural'   => array('plural'),
     ),
   );
 
Index: modules/node/node.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/node/node.install,v
retrieving revision 1.3
diff -u -p -r1.3 node.install
--- modules/node/node.install	4 Nov 2007 14:33:07 -0000	1.3
+++ modules/node/node.install	21 Nov 2007 03:49:22 -0000
@@ -97,13 +97,11 @@ function node_schema() {
       'node_status_type'    => array('status', 'type', 'nid'),
       'node_title_type'     => array('title', array('type', 4)),
       'node_type'           => array(array('type', 4)),
-      'status'              => array('status'),
       'uid'                 => array('uid'),
       'tnid'                => array('tnid'),
       'translate'           => array('translate'),
       ),
     'unique keys' => array(
-      'nid_vid' => array('nid', 'vid'),
       'vid'     => array('vid')
       ),
     'primary key' => array('nid'),
Index: modules/poll/poll.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/poll/poll.install,v
retrieving revision 1.12
diff -u -p -r1.12 poll.install
--- modules/poll/poll.install	21 Oct 2007 18:59:02 -0000	1.12
+++ modules/poll/poll.install	21 Nov 2007 03:49:22 -0000
@@ -120,10 +120,10 @@ function poll_schema() {
         'description' => t('The IP address this vote is from unless the voter was logged in.'),
         ),
       ),
+    'primary key' => array('nid', 'uid', 'hostname'),
     'indexes' => array(
       'hostname' => array('hostname'),
-      'nid'      => array('nid'),
-      'uid'      => array('uid')
+      'uid'      => array('uid'),
       ),
     );
 
Index: modules/profile/profile.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/profile/profile.install,v
retrieving revision 1.11
diff -u -p -r1.11 profile.install
--- modules/profile/profile.install	10 Oct 2007 11:39:33 -0000	1.11
+++ modules/profile/profile.install	21 Nov 2007 03:49:22 -0000
@@ -136,9 +136,9 @@ function profile_schema() {
         'description' => t('The value for the field.'),
       ),
     ),
+    'primary key' => array('uid', 'fid'),
     'indexes' => array(
       'fid' => array('fid'),
-      'uid' => array('uid')
     ),
   );
 
Index: modules/statistics/statistics.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/statistics/statistics.install,v
retrieving revision 1.12
diff -u -p -r1.12 statistics.install
--- modules/statistics/statistics.install	4 Nov 2007 14:33:07 -0000	1.12
+++ modules/statistics/statistics.install	21 Nov 2007 03:49:22 -0000
@@ -109,7 +109,10 @@ function statistics_schema() {
         'description' => t('Timestamp of when the page was visited.'),
       ),
     ),
-    'indexes' => array('accesslog_timestamp' => array('timestamp')),
+    'indexes' => array(
+      'accesslog_timestamp' => array('timestamp'),
+      'uid' => array('uid'),
+    ),
     'primary key' => array('aid'),
   );
 
Index: modules/system/system.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.install,v
retrieving revision 1.188
diff -u -p -r1.188 system.install
--- modules/system/system.install	20 Nov 2007 14:48:07 -0000	1.188
+++ modules/system/system.install	21 Nov 2007 03:49:22 -0000
@@ -582,6 +582,9 @@ function system_schema() {
         'default' => 0)
       ),
     'primary key' => array('fid'),
+    'indexes' => array(
+      'allow' => array('event', 'hostname', 'timestamp'),
+    ),
     );
 
   $schema['history'] = array(
@@ -604,6 +607,9 @@ function system_schema() {
         'default' => 0)
       ),
     'primary key' => array('uid', 'nid'),
+    'indexes' => array(
+      'nid' => array('nid'),
+    ),
     );
   $schema['menu_router'] = array(
     'description' => t('Maps paths to various callbacks (access, page and title)'),
@@ -2701,6 +2707,26 @@ function system_update_6037() {
 }
 
 /**
+ * Update table indices to make them more rational and useful.
+ */
+function system_update_6038() {
+  $ret = array();
+  // Change length of theme field in {blocks} to be consistent with module, and
+  // to avoid a MySQL error regarding a too-long index.  Add new indices.
+  db_change_field($ret, 'blocks', 'theme', 'theme', array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => ''),
+                  array('unique keys' => array(
+                           'tmd' => array('theme', 'module', 'delta'),
+                         ),
+                         'indexes' => array(
+                           'list' => array('theme', 'status', 'region', 'weight', 'module'),    
+                         ),));
+
+
+  return $ret;
+}
+
+
+/**
  * @} End of "defgroup updates-5.x-to-6.x"
  * The next series of updates should start at 7000.
  */
Index: modules/taxonomy/taxonomy.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/taxonomy/taxonomy.install,v
retrieving revision 1.4
diff -u -p -r1.4 taxonomy.install
--- modules/taxonomy/taxonomy.install	21 Oct 2007 18:59:02 -0000	1.4
+++ modules/taxonomy/taxonomy.install	21 Nov 2007 03:49:22 -0000
@@ -43,7 +43,10 @@ function taxonomy_schema() {
       ),
     ),
     'primary key' => array('tid'),
-    'indexes' => array('vid' => array('vid')),
+    'unique keys' => array(
+      'vid_name' => array('vid', 'name'),
+    ),
+    'indexes' => array('taxonomy_tree' => array('vid', 'weight', 'name')),
   );
 
   $schema['term_hierarchy'] = array(
@@ -66,7 +69,6 @@ function taxonomy_schema() {
     ),
     'indexes' => array(
       'parent' => array('parent'),
-      'tid' => array('tid'),
     ),
     'primary key' => array('tid', 'parent'),
   );
@@ -97,11 +99,10 @@ function taxonomy_schema() {
       ),
     ),
     'indexes' => array(
-      'nid' => array('nid'),
       'vid' => array('vid'),
-      'tid' => array('tid'),
+      'nid' => array('nid'),
     ),
-    'primary key' => array('vid', 'tid', 'nid'),
+    'primary key' => array('tid', 'vid'),
   );
 
   $schema['term_relation'] = array(
@@ -127,8 +128,10 @@ function taxonomy_schema() {
         'description' => t('The {term_data}.tid of the second term in a relationship.'),
       ),
     ),
+    'unique keys' => array(
+      'tid1_tid2' => array('tid1', 'tid2'),
+    ),
     'indexes' => array(
-      'tid1' => array('tid1'),
       'tid2' => array('tid2'),
     ),
     'primary key' => array('trid'),
@@ -157,8 +160,10 @@ function taxonomy_schema() {
         'description' => t('The name of the synonym.'),
       ),
     ),
+    'unique keys' => array(
+      'name_tid' => array('name', 'tid'),
+    ),
     'indexes' => array(
-      'name' => array(array('name', 3)),
       'tid' => array('tid'),
     ),
     'primary key' => array('tsid'),
@@ -249,6 +254,9 @@ function taxonomy_schema() {
       ),
     ),
     'primary key' => array('vid'),
+    'indexes' => array(
+      'list' => array('weight', 'name'),
+    ),
   );
 
   $schema['vocabulary_node_types'] = array(
@@ -268,7 +276,10 @@ function taxonomy_schema() {
         'description' => t('The {node}.type of the node type for which the vocabulary may be used.'),
       ),
     ),
-    'primary key' => array('vid', 'type'),
+    'primary key' => array('type', 'vid'),
+    'indexes' => array(
+      'vid' => array('vid'),
+    ),
   );
 
   return $schema;
Index: modules/upload/upload.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/upload/upload.install,v
retrieving revision 1.4
diff -u -p -r1.4 upload.install
--- modules/upload/upload.install	4 Nov 2007 14:33:07 -0000	1.4
+++ modules/upload/upload.install	21 Nov 2007 03:49:22 -0000
@@ -61,8 +61,11 @@ function upload_schema() {
         'description' => t('Whether the file should be visibly listed on the node: yes(1) or no(0).'),
       ),
     ),
-    'primary key' => array('fid', 'vid'),
-    'indexes' => array('vid' => array('vid'), 'nid' => array('nid')),
+    'primary key' => array('vid', 'fid'),
+    'indexes' => array(
+      'fid' => array('fid'),
+      'nid' => array('nid'),
+    ),
   );
 
   return $schema;
Index: modules/user/user.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.install,v
retrieving revision 1.3
diff -u -p -r1.3 user.install
--- modules/user/user.install	4 Nov 2007 14:33:07 -0000	1.3
+++ modules/user/user.install	21 Nov 2007 03:49:22 -0000
@@ -254,7 +254,10 @@ function user_schema() {
       'access' => array('access'),
       'created' => array('created')
     ),
-    'unique keys' => array('name' => array('name')),
+    'unique keys' => array(
+      'name' => array('name'),
+      'mail' => array('mail'),
+    ),
     'primary key' => array('uid'),
   );
 
@@ -277,6 +280,9 @@ function user_schema() {
       ),
     ),
     'primary key' => array('uid', 'rid'),
+    'indexes' => array(
+      'rid' => array('rid'),
+    ),
   );
 
   return $schema;
