diff --git a/plugins/woocommerce/changelog/fix-35465 b/plugins/woocommerce/changelog/fix-35465 new file mode 100644 index 00000000000..c102d8bf01d --- /dev/null +++ b/plugins/woocommerce/changelog/fix-35465 @@ -0,0 +1,4 @@ +Significance: patch +Type: enhancement + +Modify order index to also include date for faster order list query. diff --git a/plugins/woocommerce/changelog/fix-35465-2 b/plugins/woocommerce/changelog/fix-35465-2 new file mode 100644 index 00000000000..82fe9a6ba7a --- /dev/null +++ b/plugins/woocommerce/changelog/fix-35465-2 @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Connect WC_Install's create_tables to HPOS tables when its active. diff --git a/plugins/woocommerce/includes/class-wc-install.php b/plugins/woocommerce/includes/class-wc-install.php index 7572e0de37f..e2dcaf8883c 100644 --- a/plugins/woocommerce/includes/class-wc-install.php +++ b/plugins/woocommerce/includes/class-wc-install.php @@ -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; diff --git a/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php b/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php index d5868b7025b..333bc4c87dd 100644 --- a/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php +++ b/plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableDataStore.php @@ -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)