WordPress.org

Make WordPress Core


Ignore:
Timestamp:
02/06/2015 04:50:19 AM (5 years ago)
Author:
pento
Message:

WPDB: If a site is using the utf8 charset, and their version of MySQL supports utf8mb4, auto-upgrade them to utf8mb4.

This patch also resizes some indexes, to allow for the 767 byte index size limit in standard MySQL installs.

See #21212

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/schema.php

    r30742 r31349  
    4444    // Engage multisite if in the middle of turning it on from network.php.
    4545    $is_multisite = is_multisite() || ( defined( 'WP_INSTALLING_NETWORK' ) && WP_INSTALLING_NETWORK );
     46
     47    /*
     48     * Indexes have a maximum size of 767 bytes. Historically, we haven't need to be concerned about that.
     49     * As of 4.2, however, we moved to utf8mb4, which uses 4 bytes per character. This means that an index which
     50     * used to have room for floor(767/3) = 255 characters, now only has room for floor(767/4) = 191 characters.
     51     */
     52    $max_index_length = 191;
    4653
    4754    // Blog specific tables.
     
    5259 term_group bigint(10) NOT NULL default 0,
    5360 PRIMARY KEY  (term_id),
    54  KEY slug (slug),
    55  KEY name (name)
     61 KEY slug (slug($max_index_length)),
     62 KEY name (name($max_index_length))
    5663) $charset_collate;
    5764CREATE TABLE $wpdb->term_taxonomy (
     
    8087  PRIMARY KEY  (meta_id),
    8188  KEY comment_id (comment_id),
    82   KEY meta_key (meta_key)
     89  KEY meta_key (meta_key($max_index_length))
    8390) $charset_collate;
    8491CREATE TABLE $wpdb->comments (
     
    137144  PRIMARY KEY  (meta_id),
    138145  KEY post_id (post_id),
    139   KEY meta_key (meta_key)
     146  KEY meta_key (meta_key($max_index_length))
    140147) $charset_collate;
    141148CREATE TABLE $wpdb->posts (
     
    164171  comment_count bigint(20) NOT NULL default '0',
    165172  PRIMARY KEY  (ID),
    166   KEY post_name (post_name),
     173  KEY post_name (post_name($max_index_length)),
    167174  KEY type_status_date (post_type,post_status,post_date,ID),
    168175  KEY post_parent (post_parent),
     
    214221  PRIMARY KEY  (umeta_id),
    215222  KEY user_id (user_id),
    216   KEY meta_key (meta_key)
     223  KEY meta_key (meta_key($max_index_length))
    217224) $charset_collate;\n";
    218225
     
    262269  path varchar(100) NOT NULL default '',
    263270  PRIMARY KEY  (id),
    264   KEY domain (domain,path)
     271  KEY domain (domain(140),path(51))
    265272) $charset_collate;
    266273CREATE TABLE $wpdb->sitemeta (
     
    270277  meta_value longtext,
    271278  PRIMARY KEY  (meta_id),
    272   KEY meta_key (meta_key),
     279  KEY meta_key (meta_key($max_index_length)),
    273280  KEY site_id (site_id)
    274281) $charset_collate;
     
    289296  KEY user_email (user_email),
    290297  KEY user_login_email (user_login,user_email),
    291   KEY domain_path (domain,path)
     298  KEY domain_path (domain(140),path(51))
    292299) $charset_collate;";
    293300
Note: See TracChangeset for help on using the changeset viewer.