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 24 Nov 2007 04:37:50 -0000 @@ -75,7 +75,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 +95,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 +173,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 +233,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 24 Nov 2007 04:37:50 -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 24 Nov 2007 04:37:50 -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 24 Nov 2007 04:37:50 -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 24 Nov 2007 04:37:50 -0000 @@ -68,10 +68,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 24 Nov 2007 04:37:50 -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 since you can't use joins, nor index. ), '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 24 Nov 2007 04:37:50 -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.22 diff -u -p -r1.22 locale.install --- modules/locale/locale.install 23 Nov 2007 12:15:12 -0000 1.22 +++ modules/locale/locale.install 24 Nov 2007 04:37:50 -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 24 Nov 2007 04:37:50 -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 24 Nov 2007 04:37:50 -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 24 Nov 2007 04:37:50 -0000 @@ -119,14 +119,14 @@ function profile_schema() { 'fid' => array( 'type' => 'int', 'unsigned' => TRUE, - 'not null' => FALSE, + 'not null' => TRUE, 'default' => 0, 'description' => t('The {profile_fields}.fid of the field.'), ), 'uid' => array( 'type' => 'int', 'unsigned' => TRUE, - 'not null' => FALSE, + 'not null' => TRUE, 'default' => 0, 'description' => t('The {users}.uid of the profile user.'), ), @@ -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 24 Nov 2007 04:37:50 -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.191 diff -u -p -r1.191 system.install --- modules/system/system.install 22 Nov 2007 21:02:15 -0000 1.191 +++ modules/system/system.install 24 Nov 2007 04:37:50 -0000 @@ -584,6 +584,9 @@ function system_schema() { 'default' => 0) ), 'primary key' => array('fid'), + 'indexes' => array( + 'allow' => array('event', 'hostname', 'timestamp'), + ), ); $schema['history'] = array( @@ -606,6 +609,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)'), @@ -2402,13 +2408,16 @@ function system_update_6022() { db_add_index($ret, 'files', 'timestamp', array('timestamp')); // Rename the file_revisions table to upload then add nid column. Since we're - // changing the table name we need to drop and re-add the vid index so both - // pgsql ends up with the correct index name. + // changing the table name we need to drop and re-add the indexes and + // the primary key so both mysql and pgsql end up with the correct index + // names. + db_drop_primary_key($ret, 'file_revisions'); db_drop_index($ret, 'file_revisions', 'vid'); db_rename_table($ret, 'file_revisions', 'upload'); db_add_field($ret, 'upload', 'nid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0)); db_add_index($ret, 'upload', 'nid', array('nid')); - db_add_index($ret, 'upload', 'vid', array('vid')); + db_add_primary_key($ret, 'upload', array('vid', 'fid')); + db_add_index($ret, 'upload', 'fid', array('fid')); // The nid column was renamed to uid. Use the old nid to find the node's uid. update_sql('UPDATE {files} SET uid = (SELECT n.uid FROM {node} n WHERE {files}.uid = n.nid)'); @@ -2703,6 +2712,101 @@ function system_update_6037() { } /** + * Update table indices to make them more rational and useful. + */ +function system_update_6038() { + $ret = array(); + // Required modules first. + // Add new system module indexes. + db_add_index($ret, 'flood', 'allow', array('event', 'hostname', 'timestamp')); + db_add_index($ret, 'history', 'nid', array('nid')); + // Change length of theme field in {blocks} to be consistent with module, and + // to avoid a MySQL error regarding a too-long index. Also 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'),),)); + db_add_index($ret, 'blocks_roles', 'rid', array('rid')); + // Improve filter module indices. + db_drop_index($ret, 'filters', 'weight'); + db_add_unique_key($ret, 'filters', 'fmd', array('format', 'module', 'delta')); + db_add_index($ret, 'filters', 'list', array('format', 'weight', 'module', 'delta')); + // Drop unneeded keys form the node table. + db_drop_index($ret, 'node', 'status'); + db_drop_unique_key($ret, 'node', 'nid_vid'); + // Improve user module indices. + db_add_unique_key($ret, 'users', 'mail', array('mail')); + db_add_index($ret, 'users_roles', 'rid', array('rid')); + + // Optional modules - need to check if the tables exist. + // Alter aggregator module's tables primary keys to make them more useful. + if (db_table_exists('aggregator_category_feed')) { + db_drop_primary_key($ret, 'aggregator_category_feed'); + db_add_primary_key($ret, 'aggregator_category_feed', array('cid', 'fid')); + db_add_index($ret, 'aggregator_category_feed', 'fid', array('fid')); + } + if (db_table_exists('aggregator_category_item')) { + db_drop_primary_key($ret, 'aggregator_category_item'); + db_add_primary_key($ret, 'aggregator_category_item', array('cid', 'iid')); + db_add_index($ret, 'aggregator_category_item', 'iid', array('iid')); + } + // Alter contact module's table to add an index. + if (db_table_exists('contact')) { + db_add_index($ret, 'contact', 'list', array('weight', 'category')); + } + // Alter locale table to add a primary key, drop an index. + if (db_table_exists('locales_target')) { + db_add_primary_key($ret, 'locales_target', array('language', 'lid', 'plural')); + db_drop_index($ret, 'locales_target', 'language'); + } + // Alter a poll module table to add a primary key. + if (db_table_exists('poll_votes')) { + db_drop_index($ret, 'poll_votes', 'nid'); + db_add_primary_key($ret, 'poll_votes', array('nid', 'uid', 'hostname')); + } + // Alter a profile module table to add a primary key. + if (db_table_exists('profile_values')) { + db_drop_index($ret, 'profile_values', 'uid'); + db_drop_index($ret, 'profile_values', 'fid'); + db_change_field($ret,'profile_values' ,'fid', 'fid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0,), array('indexes' => array('fid' => array('fid'),))); + db_change_field($ret,'profile_values' ,'uid', 'uid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0,)); + db_add_primary_key($ret, 'profile_values', array('uid', 'fid')); + } + // Alter a statistics module table to add an index. + if (db_table_exists('accesslog')) { + db_add_index($ret, 'accesslog', 'uid', array('uid')); + } + // Alter taxonomy module's tables. + if (db_table_exists('term_data')) { + db_drop_index($ret, 'term_data', 'vid'); + db_add_unique_key($ret, 'term_data', 'vid_name', array('vid', 'name')); + db_add_index($ret, 'term_data', 'taxonomy_tree', array('vid', 'weight', 'name')); + } + if (db_table_exists('term_node')) { + db_drop_primary_key($ret, 'term_node'); + db_drop_index($ret, 'term_node', 'tid'); + db_add_primary_key($ret, 'term_node', array('tid', 'vid')); + } + if (db_table_exists('term_relation')) { + db_drop_index($ret, 'term_relation', 'tid1'); + db_add_unique_key($ret, 'term_relation', 'tid1_tid2', array('tid1', 'tid2')); + } + if (db_table_exists('term_synonym')) { + db_drop_index($ret, 'term_synonym', 'name'); + db_add_unique_key($ret, 'term_synonym', 'name_tid', array('name', 'tid')); + } + if (db_table_exists('vocabulary')) { + db_add_index($ret, 'vocabulary', 'list', array('weight', 'name')); + } + if (db_table_exists('vocabulary_node_types')) { + db_drop_primary_key($ret, 'vocabulary_node_types'); + db_add_primary_key($ret, 'vocabulary_node_types', array('type', 'vid')); + db_add_index($ret, 'vocabulary_node_types', 'vid', array('vid')); + } + + 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 24 Nov 2007 04:37:50 -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 24 Nov 2007 04:37:50 -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 24 Nov 2007 04:37:50 -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;