Add date index to order tables for speeding up order list query. (#39682)

This commit is contained in:
Barry Hughes 2023-08-11 10:39:54 -07:00 committed by GitHub
commit 26abedebe0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 5 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: enhancement
Modify order index to also include date for faster order list query.

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Connect WC_Install's create_tables to HPOS tables when its active.

View File

@ -1162,6 +1162,11 @@ class WC_Install {
$product_attributes_lookup_table_creation_sql = wc_get_container()->get( DataRegenerator::class )->get_table_creation_sql();
$feature_controller = wc_get_container()->get( FeaturesController::class );
$hpos_enabled =
$feature_controller->feature_is_enabled( DataSynchronizer::ORDERS_DATA_SYNC_ENABLED_OPTION ) || $feature_controller->feature_is_enabled( CustomOrdersTableController::CUSTOM_ORDERS_TABLE_USAGE_ENABLED_OPTION );
$hpos_table_schema = $hpos_enabled ? wc_get_container()->get( OrdersTableDataStore::class )->get_database_schema() : '';
$tables = "
CREATE TABLE {$wpdb->prefix}woocommerce_sessions (
session_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
@ -1505,6 +1510,7 @@ CREATE TABLE {$wpdb->prefix}wc_category_lookup (
category_id bigint(20) unsigned NOT NULL,
PRIMARY KEY (category_tree_id,category_id)
) $collate;
$hpos_table_schema;
";
return $tables;

View File

@ -2653,7 +2653,7 @@ CREATE TABLE $orders_table_name (
KEY date_created (date_created_gmt),
KEY customer_id_billing_email (customer_id, billing_email({$composite_customer_id_email_length})),
KEY billing_email (billing_email($max_index_length)),
KEY type_status (type, status),
KEY type_status_date (type, status, date_created_gmt),
KEY parent_order_id (parent_order_id),
KEY date_updated (date_updated_gmt)
) $collate;
@ -2691,10 +2691,10 @@ CREATE TABLE $operational_data_table_name (
order_stock_reduced tinyint(1) NULL,
date_paid_gmt datetime NULL,
date_completed_gmt datetime NULL,
shipping_tax_amount decimal(26, 8) NULL,
shipping_total_amount decimal(26, 8) NULL,
discount_tax_amount decimal(26, 8) NULL,
discount_total_amount decimal(26, 8) NULL,
shipping_tax_amount decimal(26,8) NULL,
shipping_total_amount decimal(26,8) NULL,
discount_tax_amount decimal(26,8) NULL,
discount_total_amount decimal(26,8) NULL,
recorded_sales tinyint(1) NULL,
UNIQUE KEY order_id (order_id),
KEY order_key (order_key)