Last active
April 21, 2020 22:12
-
-
Save toan-tam/26273f83c1ccb786c311ae21dabf566c to your computer and use it in GitHub Desktop.
Magento 2.3.2 EE - Patch for `INSERT INTO search_tmp_` search issue: https://github.com/magento/magento2/issues/15545
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: Model/Search/FilterMapper/CustomAttributeFilter.php | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- Model/Search/FilterMapper/CustomAttributeFilter.php (date 1574535757476) | |
+++ Model/Search/FilterMapper/CustomAttributeFilter.php (date 1574535757476) | |
@@ -98,8 +98,21 @@ | |
$attributes[] = $attributeId; | |
+ // BEGIN EDIT - Fix hanging `INSERT INTO search_tmp_` queries | |
+ // Patch created by referencing http://bit.ly/2OcN8a4 and http://bit.ly/2QN3p7d | |
+ $optimizedSelectQuery = new \Zend_Db_Expr('(SELECT `entity_id`, `store_id`, `attribute_id`, `value`, `source_id` FROM ' | |
+ . $this->resourceConnection->getTableName('catalog_product_index_eav') | |
+ . sprintf( | |
+ ' WHERE `attribute_id`=%s AND `store_id`=%s' | |
+ . ' GROUP BY CONCAT(`entity_id`," ",`attribute_id`," ",`store_id`," ",`value`) )', | |
+ $attributeId, | |
+ $this->storeManager->getStore()->getId() | |
+ ) | |
+ ); | |
+ | |
$select->joinInner( | |
- [$filterJoinAlias => $this->resourceConnection->getTableName('catalog_product_index_eav')], | |
+ [$filterJoinAlias => $optimizedSelectQuery], | |
+ // END EDIT | |
$this->conditionManager->combineQueries( | |
$this->getJoinConditions($attributeId, $mainTableAlias, $filterJoinAlias), | |
Select::SQL_AND | |
Index: Model/Search/FilterMapper/VisibilityFilter.php | |
IDEA additional info: | |
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | |
<+>UTF-8 | |
=================================================================== | |
--- Model/Search/FilterMapper/VisibilityFilter.php (date 1574535765359) | |
+++ Model/Search/FilterMapper/VisibilityFilter.php (date 1574535765359) | |
@@ -118,9 +118,17 @@ | |
private function applyFilterByJoin(FilterInterface $filter, Select $select) | |
{ | |
$mainTableAlias = $this->extractTableAliasFromSelect($select); | |
+ | |
+ // BEGIN EDIT - Fix hanging `INSERT INTO search_tmp_` queries | |
+ // Patch created by referencing http://bit.ly/2OcN8a4 and http://bit.ly/2QN3p7d | |
+ $optimizedVisibilityQuery = new \Zend_Db_Expr('(SELECT `entity_id`, `store_id`, `attribute_id`, `value` FROM ' | |
+ . $this->resourceConnection->getTableName('catalog_product_index_eav') | |
+ . sprintf(' WHERE `attribute_id`=%s AND `store_id`=%s GROUP BY CONCAT(`entity_id`," ",`attribute_id`," ",`store_id`," ",`value`) )', $this->getVisibilityAttributeId(), $this->storeManager->getStore()->getId()) | |
+ ); | |
$select->joinInner( | |
- ['visibility_filter' => $this->resourceConnection->getTableName('catalog_product_index_eav')], | |
+ ['visibility_filter' => $optimizedVisibilityQuery], | |
+ // END EDIT | |
$this->conditionManager->combineQueries( | |
[ | |
sprintf('%s.entity_id = visibility_filter.entity_id', $mainTableAlias), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment