Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Fixed a performance issue where resaving products in multi-site setups could trigger a full table scan on `elements_owners` for each variant. ([#4305](https://github.com/craftcms/commerce/issues/4305))
- Fixed a bug where the widget Date Range field could break when reopening settings after saving a custom date range. ([#4306](https://github.com/craftcms/commerce/issues/4306))
- Fixed a bug where new orders created in the control panel would default to a non-primary Order Site in multi-site/single-store setups. ([#4310](https://github.com/craftcms/commerce/issues/4310))
- Fixed a PHP error that could occur when opening a product with a provisional draft. ([#4314](https://github.com/craftcms/commerce/issues/4314))
Expand Down
6 changes: 4 additions & 2 deletions src/elements/db/VariantQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,10 @@ protected function beforePrepare(): bool
->innerJoin(['elements_owners' => CraftTable::ELEMENTS_OWNERS], $ownersCondition);

$sortOrderIndex = Db::findIndex(CraftTable::ELEMENTS_OWNERS, ['sortOrder'], false);
// Forcing the use of the `sortOrder` index if no custom `orderBy` is set
if (Craft::$app->getDb()->getIsMysql() && $sortOrderIndex !== null && empty($this->orderBy)) {
// Forcing the use of the `sortOrder` index only when listing (no specific element/owner filter),
// so MySQL doesn't prefer it over targeted indexes when querying by ID.
$hasSpecificFilter = !empty($this->id) || !empty($this->ownerId) || !empty($this->primaryOwnerId);
if (Craft::$app->getDb()->getIsMysql() && $sortOrderIndex !== null && empty($this->orderBy) && !$hasSpecificFilter) {
Comment on lines +523 to +526
$elementOwnersTable = Craft::$app->getDb()->schema->getRawTableName(\craft\db\Table::ELEMENTS_OWNERS);
$this->subQuery->innerJoin([new Expression('[[' . $elementOwnersTable . ']] AS elements_owners USE INDEX (' . $sortOrderIndex . ')')], $ownersCondition);
} else {
Expand Down
Loading