Skip to content

Commit bc2b81c

Browse files
committed
ACP2E-2673: Price partial indexing performance
- added indexes for temporary indexer database table - temporary indexer table is now being dropped instead of deleting data
1 parent 3b22238 commit bc2b81c

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

app/code/Magento/Catalog/Model/Indexer/Product/Price/AbstractAction.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,11 @@ function ($type) use ($productsTypes) {
408408
foreach ($this->dimensionCollectionFactory->create() as $dimensions) {
409409
$this->tableMaintainer->createMainTmpTable($dimensions);
410410
$temporaryTable = $this->tableMaintainer->getMainTmpTable($dimensions);
411-
$this->_emptyTable($temporaryTable);
412411
$indexer->executeByDimensions($dimensions, \SplFixedArray::fromArray($entityIds, false));
413412
$mainTable = $this->tableMaintainer->getMainTableByDimensions($dimensions);
414413
$this->_insertFromTable($temporaryTable, $mainTable);
415414
$this->deleteOutdatedData($entityIds, $temporaryTable, $mainTable);
415+
$this->_connection->dropTable($temporaryTable);
416416
}
417417
} else {
418418
// handle 3d-party indexers for backward compatibility
@@ -437,18 +437,12 @@ function ($type) use ($productsTypes) {
437437
*/
438438
private function deleteOutdatedData(array $entityIds, string $temporaryTable, string $mainTable): void
439439
{
440-
$connection = $this->getConnection();
441-
$describe = $connection->describeTable($connection->getTableName($temporaryTable));
442-
if (false === $describe['entity_id']['NULLABLE']) {
443-
return;
444-
}
445-
446440
$joinCondition = [
447441
'tmp_table.entity_id = main_table.entity_id',
448442
'tmp_table.customer_group_id = main_table.customer_group_id',
449443
'tmp_table.website_id = main_table.website_id',
450444
];
451-
$select = $connection->select()
445+
$select = $this->getConnection()->select()
452446
->from(['main_table' => $mainTable], null)
453447
->joinLeft(['tmp_table' => $temporaryTable], implode(' AND ', $joinCondition), null)
454448
->where('tmp_table.entity_id IS NULL')

app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Price/Action/RowsTest.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ public function testBatchProcessing()
143143
$select->method('join')->willReturnSelf();
144144
$adapter = $this->createMock(AdapterInterface::class);
145145
$adapter->method('select')->willReturn($select);
146-
$adapter->method('describeTable')->willReturn(['entity_id' => ['NULLABLE' => true]]);
146+
$adapter->method('describeTable')->willReturn([]);
147+
$adapter->expects($this->exactly(4))->method('dropTable');
147148
$this->defaultIndexerResource->method('getConnection')->willReturn($adapter);
148149
$adapter->method('fetchAll')->with($select)->willReturn([]);
149150

@@ -193,7 +194,21 @@ public function testBatchProcessing()
193194
->method('getPrimaryKeyName')
194195
->willReturn('entity_id');
195196

196-
$this->actionRows->execute($ids);
197+
$actionRows = new Rows(
198+
$this->config,
199+
$this->storeManager,
200+
$this->currencyFactory,
201+
$this->localeDate,
202+
$this->dateTime,
203+
$this->catalogProductType,
204+
$this->indexerPriceFactory,
205+
$this->defaultIndexerResource,
206+
$this->tierPriceIndexResource,
207+
$this->dimensionCollectionFactory,
208+
$this->tableMaintainer,
209+
2
210+
);
211+
$actionRows->execute($ids);
197212
}
198213

199214
public function testDeletedProductsBatchProcessing()

app/code/Magento/Catalog/etc/db_schema.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,6 +1645,11 @@
16451645
<constraint xsi:type="primary" referenceId="PRIMARY">
16461646
<column name="id"/>
16471647
</constraint>
1648+
<index referenceId="CATALOG_PRODUCT_INDEX_ENTITY_CUSTOMER_WEBSITE" indexType="btree">
1649+
<column name="entity_id"/>
1650+
<column name="customer_group_id"/>
1651+
<column name="website_id"/>
1652+
</index>
16481653
</table>
16491654
<table name="catalog_category_product_index_tmp" resource="default" engine="innodb"
16501655
comment="Catalog Category Product Indexer temporary table">

app/code/Magento/Catalog/etc/db_schema_whitelist.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,8 @@
992992
"index": {
993993
"CATALOG_PRODUCT_INDEX_PRICE_TMP_CUSTOMER_GROUP_ID": true,
994994
"CATALOG_PRODUCT_INDEX_PRICE_TMP_WEBSITE_ID": true,
995-
"CATALOG_PRODUCT_INDEX_PRICE_TMP_MIN_PRICE": true
995+
"CATALOG_PRODUCT_INDEX_PRICE_TMP_MIN_PRICE": true,
996+
"CATALOG_PRODUCT_INDEX_ENTITY_CUSTOMER_WEBSITE": true
996997
},
997998
"constraint": {
998999
"PRIMARY": true

0 commit comments

Comments
 (0)