magento2: Error while reindexing price

Preconditions

  1. Magento ver. 2.2.6
  2. PHP 7.0.26 (cli) (built: Nov 21 2017 14:36:41) ( NTS )

Steps to reproduce

  1. After upgrading magento from version 2.2.2 to 2.2.6

Expected result

  1. Reindexing of price

Actual result

  1. While reindexing price it shows error

Base table or view not found: 1146 Table catalog_product_index_price_temp’ doesn’t exist, query was: SELECT i.entity_id, o.option_id FROM catalog_product_index_price_temp AS i INNER JOIN catalog_product_entity AS e ON e.entity_id = i.entity_id INNER JOIN catalog_product_option AS o ON o.product_id = e.entity_id

suffix temp is used instead of tmp

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 26 (10 by maintainers)

Most upvoted comments

So I recently had this issue with 2.3.4-p2. I dug a little bit further and I think there is nothing wrong with table names per-say. In Magento\ConfigurableProduct\Model\ResourceModel\Product\Indexer\Price\Configurable there is a method called executeByDimensions. This method calls Magento\Catalog\Model\Indexer\Product\Price\TableMaintainer createMainTmpTable method. This method creates a TEMPORARY table with the suffix “_temp” which is supposed to be exactly as the “_tmp”. This is intentional. The issue happens when the MySQL session is halted for some reason and the temporary table disappears. So there is probably room for improvement here but if you run into that issue I guess you should focus more on the MySQL settings and make sure there are no long-running queries into that TEMPORARY table.

This is true and it helped me a lot. I used it as a starting point for debugging. In my case I discovered an enabled module in my repository with the following code:

    public function __construct(ObjectManagerFactory $objectManagerFactory, \Magento\Framework\App\State $appState){
        (...)
        $this->objectManager = $objectManagerFactory->create($params);
        (...)
    }

This basically created a new instance of the object manager which was the reason why a different MySQL connection was used which in turn caused the error with the missing table.

So I recently had this issue with 2.3.4-p2. I dug a little bit further and I think there is nothing wrong with table names per-say. In Magento\ConfigurableProduct\Model\ResourceModel\Product\Indexer\Price\Configurable there is a method called executeByDimensions. This method calls Magento\Catalog\Model\Indexer\Product\Price\TableMaintainer createMainTmpTable method. This method creates a TEMPORARY table with the suffix “_temp” which is supposed to be exactly as the “_tmp”. This is intentional. The issue happens when the MySQL session is halted for some reason and the temporary table disappears. So there is probably room for improvement here but if you run into that issue I guess you should focus more on the MySQL settings and make sure there are no long-running queries into that TEMPORARY table.

Here is a patch file, you can use if you’re interested:

diff --git a/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Price/CustomOptionPriceModifier.php b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Price/CustomOptionPriceModifier.php
index 646cd0d4..9bdb2a66 100644
--- a/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Price/CustomOptionPriceModifier.php
+++ b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Price/CustomOptionPriceModifier.php
@@ -138,7 +138,7 @@ class CustomOptionPriceModifier implements PriceModifierInterface
         $select = $this->getConnection()
             ->select()
             ->from(
-                ['i' => $priceTable->getTableName()],
+                ['i' => $this->getTable('catalog_product_index_price_tmp')],
                 ['entity_id']
             )->join(
                 ['e' => $this->getTable('catalog_product_entity')],

I’m struggling to understand this whole post. Where is fix to this issue? I can see labels saying fixed in 2.3, however version 2.3 hasn’t yet been released! I need this fix on my website asap or at least walk around solution to it. I cannot add any products to my website as they won’t appear unless indexed.

Hi, I think the error is because of getIdxTable function in vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Price/DefaultPrice.php. It is returning table name as “catalog_product_index_price_temp” while it should be “catalog_product_index_price_tmp”

public function getIdxTable($table = null) { return $this->tableStrategy->getTableName(‘catalog_product_index_price’); }