Automattic\WooCommerce\Internal\Utilities
DatabaseUtil::get_max_index_length
Get max index length.
Method of the class: DatabaseUtil{}
Hooks from the method
Returns
Int. Max index length.
Usage
$DatabaseUtil = new DatabaseUtil(); $DatabaseUtil->get_max_index_length(): int;
DatabaseUtil::get_max_index_length() DatabaseUtil::get max index length code WC 10.3.6
public function get_max_index_length(): int {
/**
* Filters the maximum index length in the database.
*
* Indexes have a maximum size of 767 bytes. Historically, we haven't need to be concerned about that.
* As of WP 4.2, however, they moved to utf8mb4, which uses 4 bytes per character. This means that an index which
* used to have room for floor(767/3) = 255 characters, now only has room for floor(767/4) = 191 characters.
*
* Additionally, MyISAM engine also limits the index size to 1000 bytes. We add this filter so that interested folks on InnoDB engine can increase the size till allowed 3071 bytes.
*
* @param int $max_index_length Maximum index length. Default 191.
*
* @since 8.0.0
*/
$max_index_length = apply_filters( 'woocommerce_database_max_index_length', 191 );
// Index length cannot be more than 768, which is 3078 bytes in utf8mb4 and max allowed by InnoDB engine.
return min( absint( $max_index_length ), 767 );
}