OpenMage / magento-lts

Official OpenMage LTS codebase | Migrate easily from Magento Community Edition in minutes! Download the source code for free or contribute to OpenMage LTS | Security vulnerability patches, bug fixes, performance improvements and more.
https://www.openmage.org
Open Software License 3.0
868 stars 436 forks source link

Integrity constraint violation: 1062 Duplicate entry for key 'UNQ_CATRULE_PRD_PRICE_RULE_DATE_WS_ID_CSTR_GROUP_ID_PRD_ID' #1241

Closed tim-breitenstein-it closed 2 years ago

tim-breitenstein-it commented 4 years ago

Preconditions (*)

  1. Magento Version: 1.9.3.10
  2. Article count: 62183
  3. Catalog Rule count: 138
  4. Flat Catalog Category: On
  5. Flat Catalog Product: Off

Steps to reproduce (*)

  1. Run Cron catalogrule_apply_all

Expected result (*)

Status:  SUCCESS
Message:
---RETURN_VALUE---
Mage_CatalogRule_Model_Observer

Actual result (*)

Status:  ERROR
Message:
---EXCEPTION---
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2020-09-28-1-8-16137' for key 'UNQ_CATRULE_PRD_PRICE_RULE_DATE_WS_ID_CSTR_GROUP_ID_PRD_ID' in /var/www/htdocs/lib/Zend/Db/Statement/Pdo.php:228
Stack trace:
#0 /var/www/htdocs/lib/Zend/Db/Statement/Pdo.php(228): PDOStatement->execute(Array)
#1 /var/www/htdocs/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#2 /var/www/htdocs/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#3 /var/www/htdocs/lib/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array)
#4 /var/www/htdocs/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO `ca...', Array)
#5 /var/www/htdocs/lib/Varien/Db/Adapter/Pdo/Mysql.php(504): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO `ca...', Array)
#6 /var/www/htdocs/app/code/core/Mage/CatalogRule/Model/Action/Index/Refresh.php(591): Varien_Db_Adapter_Pdo_Mysql->query('INSERT INTO `ca...')
#7 /var/www/htdocs/app/code/core/Mage/CatalogRule/Model/Action/Index/Refresh.php(612): Mage_CatalogRule_Model_Action_Index_Refresh->_fillIndexData(Object(Mage_Core_Model_Website), 1601330400)
#8 /var/www/htdocs/app/code/core/Mage/CatalogRule/Model/Action/Index/Refresh.php(126): Mage_CatalogRule_Model_Action_Index_Refresh->_reindex(Object(Mage_Core_Model_Website), 1601330400)
#9 /var/www/htdocs/app/code/core/Mage/CatalogRule/Model/Resource/Rule.php(601): Mage_CatalogRule_Model_Action_Index_Refresh->execute()
#10 /var/www/htdocs/app/code/core/Mage/CatalogRule/Model/Resource/Rule.php(554): Mage_CatalogRule_Model_Resource_Rule->_reindexCatalogRule(NULL)
#11 /var/www/htdocs/app/code/core/Mage/CatalogRule/Model/Rule.php(318): Mage_CatalogRule_Model_Resource_Rule->applyAllRules()
#12 /var/www/htdocs/app/code/core/Mage/CatalogRule/Model/Observer.php(263): Mage_CatalogRule_Model_Rule->applyAll()
#13 /var/www/htdocs/app/code/community/Aoe/Scheduler/Model/Schedule.php(217): Mage_CatalogRule_Model_Observer->dailyCatalogUpdate(Object(Aoe_Scheduler_Model_Schedule))
#14 /var/www/htdocs/app/code/community/Aoe/Scheduler/Model/Schedule.php(623): Aoe_Scheduler_Model_Schedule->runNow(true)
#15 /var/www/htdocs/app/code/community/Aoe/Scheduler/Model/Observer.php(39): Aoe_Scheduler_Model_Schedule->process()
#16 /var/www/htdocs/app/code/core/Mage/Core/Model/App.php(1358): Aoe_Scheduler_Model_Observer->dispatch(Object(Varien_Event_Observer))
#17 /var/www/htdocs/app/code/core/Mage/Core/Model/App.php(1337): Mage_Core_Model_App->_callObserverMethod(Object(Aoe_Scheduler_Model_Observer), 'dispatch', Object(Varien_Event_Observer))
#18 /var/www/htdocs/app/Mage.php(457): Mage_Core_Model_App->dispatchEvent('default', Array)
#19 /var/www/htdocs/shell/scheduler.php(518): Mage::dispatchEvent('default', Array)
#20 /var/www/htdocs/shell/scheduler.php(37): Aoe_Scheduler_Shell_Scheduler->cronAction()
#21 /var/www/htdocs/shell/scheduler.php(545): Aoe_Scheduler_Shell_Scheduler->run()
#22 {main}

Next Zend_Db_Statement_Exception: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2020-09-28-1-8-16137' for key 'UNQ_CATRULE_PRD_PRICE_RULE_DATE_WS_ID_CSTR_GROUP_ID_PRD_ID', query was: INSERT INTO `catalogrule_product_price` SELECT NULL AS `rule_product_price_id`, `dates`.`rule_date`, `t`.`customer_group_id`, `t`.`product_id`, MIN(rule_price) AS `rule_price`, 1 AS `website_id`, `t`.`latest_start_date`, `t`.`earliest_end_date` FROM (SELECT `cppt`.`customer_group_id`, `cppt`.`product_id`, CASE  WHEN IFNULL((@group_id), 'N/A') != cppt.grouped_id THEN @price := CASE `cppt`.`action_operator` WHEN 'to_percent' THEN cppt.price * cppt.action_amount/100 WHEN 'by_percent' THEN cppt.price * (1 - cppt.action_amount/100) WHEN 'to_fixed' THEN IF((cppt.action_amount < cppt.price), cppt.action_amount, cppt.price) WHEN 'by_fixed' THEN IF((0 > cppt.price - cppt.action_amount), 0, cppt.price - cppt.action_amount) END WHEN IFNULL((@group_id), 'N/A') = cppt.grouped_id AND IFNULL((@action_stop), 0) = 0 THEN @price := CASE `cppt`.`action_operator` WHEN 'to_percent' THEN @price * cppt.action_amount/100 WHEN 'by_percent' THEN @price * (1 - cppt.action_amount/100) WHEN 'to_fixed' THEN IF((cppt.action_amount < @price), cppt.action_amount, @price) WHEN 'by_fixed' THEN IF((0 > @price - cppt.action_amount), 0, @price - cppt.action_amount) END ELSE @price END AS `rule_price`, `cppt`.`from_date` AS `latest_start_date`, `cppt`.`to_date` AS `earliest_end_date`, CASE  WHEN IFNULL((@group_id), 'N/A') != cppt.grouped_id THEN @action_stop := cppt.action_stop WHEN IFNULL((@group_id), 'N/A') = cppt.grouped_id THEN @action_stop := IFNULL((@action_stop), 0) + cppt.action_stop END, @group_id := cppt.grouped_id, `cppt`.`from_time`, `cppt`.`to_time` FROM `catalogrule_product_price_tmp` AS `cppt` ORDER BY `cppt`.`grouped_id` ASC, `cppt`.`sort_order` ASC, `cppt`.`rule_product_id` ASC) AS `t`
 INNER JOIN (SELECT DATE_ADD(FROM_UNIXTIME(1601330400), INTERVAL -1 DAY) AS rule_date UNION SELECT FROM_UNIXTIME(1601330400) AS rule_date UNION SELECT DATE_ADD(FROM_UNIXTIME(1601330400), INTERVAL 1 DAY) AS rule_date) AS `dates` ON 1=1 WHERE (UNIX_TIMESTAMP(dates.rule_date) >= from_time) AND (IF((to_time = 0), 1, UNIX_TIMESTAMP(dates.rule_date) <= to_time)) GROUP BY `customer_group_id`,
    `product_id`,
    `dates`.`rule_date` in /var/www/htdocs/lib/Zend/Db/Statement/Pdo.php:235
Stack trace:
#0 /var/www/htdocs/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
#1 /var/www/htdocs/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
#2 /var/www/htdocs/lib/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array)
#3 /var/www/htdocs/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO `ca...', Array)
#4 /var/www/htdocs/lib/Varien/Db/Adapter/Pdo/Mysql.php(504): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO `ca...', Array)
#5 /var/www/htdocs/app/code/core/Mage/CatalogRule/Model/Action/Index/Refresh.php(591): Varien_Db_Adapter_Pdo_Mysql->query('INSERT INTO `ca...')
#6 /var/www/htdocs/app/code/core/Mage/CatalogRule/Model/Action/Index/Refresh.php(612): Mage_CatalogRule_Model_Action_Index_Refresh->_fillIndexData(Object(Mage_Core_Model_Website), 1601330400)
#7 /var/www/htdocs/app/code/core/Mage/CatalogRule/Model/Action/Index/Refresh.php(126): Mage_CatalogRule_Model_Action_Index_Refresh->_reindex(Object(Mage_Core_Model_Website), 1601330400)
#8 /var/www/htdocs/app/code/core/Mage/CatalogRule/Model/Resource/Rule.php(601): Mage_CatalogRule_Model_Action_Index_Refresh->execute()
#9 /var/www/htdocs/app/code/core/Mage/CatalogRule/Model/Resource/Rule.php(554): Mage_CatalogRule_Model_Resource_Rule->_reindexCatalogRule(NULL)
#10 /var/www/htdocs/app/code/core/Mage/CatalogRule/Model/Rule.php(318): Mage_CatalogRule_Model_Resource_Rule->applyAllRules()
#11 /var/www/htdocs/app/code/core/Mage/CatalogRule/Model/Observer.php(263): Mage_CatalogRule_Model_Rule->applyAll()
#12 /var/www/htdocs/app/code/community/Aoe/Scheduler/Model/Schedule.php(217): Mage_CatalogRule_Model_Observer->dailyCatalogUpdate(Object(Aoe_Scheduler_Model_Schedule))
#13 /var/www/htdocs/app/code/community/Aoe/Scheduler/Model/Schedule.php(623): Aoe_Scheduler_Model_Schedule->runNow(true)
#14 /var/www/htdocs/app/code/community/Aoe/Scheduler/Model/Observer.php(39): Aoe_Scheduler_Model_Schedule->process()
#15 /var/www/htdocs/app/code/core/Mage/Core/Model/App.php(1358): Aoe_Scheduler_Model_Observer->dispatch(Object(Varien_Event_Observer))
#16 /var/www/htdocs/app/code/core/Mage/Core/Model/App.php(1337): Mage_Core_Model_App->_callObserverMethod(Object(Aoe_Scheduler_Model_Observer), 'dispatch', Object(Varien_Event_Observer))
#17 /var/www/htdocs/app/Mage.php(457): Mage_Core_Model_App->dispatchEvent('default', Array)
#18 /var/www/htdocs/shell/scheduler.php(518): Mage::dispatchEvent('default', Array)
#19 /var/www/htdocs/shell/scheduler.php(37): Aoe_Scheduler_Shell_Scheduler->cronAction()
#20 /var/www/htdocs/shell/scheduler.php(545): Aoe_Scheduler_Shell_Scheduler->run()
#21 {main}

Possible Fix ?

app/code/core/Mage/CatalogRule/Model/Action/Index/Refresh.php

From: ->group(array('customer_group_id', 'product_id', 'dates.rule_date')); To: ->group(array('customer_group_id', 'product_id', 'dates.rule_date', 'website_id'));

    /**
     * Prepare index select
     *
     * @param Mage_Core_Model_Website $website
     * @param int|Zend_Db_Expr $time
     * @return Varien_Db_Select
     */
    protected function _prepareIndexSelect(Mage_Core_Model_Website $website, $time)
    {
        $nA = $this->_connection->quote('N/A');
        $this->_connection->query('SET @price := 0');
        $this->_connection->query('SET @group_id := NULL');
        $this->_connection->query('SET @action_stop := NULL');

        $indexSelect = $this->_connection->select()
            ->from(array('cppt' => $this->_getTemporaryTable()), array())
            ->order(array('cppt.grouped_id', 'cppt.sort_order', 'cppt.rule_product_id'))
            ->columns(
                array(
                    'customer_group_id' => 'cppt.customer_group_id',
                    'product_id'        => 'cppt.product_id',
                    'rule_price'        => $this->_calculatePrice(),
                    'latest_start_date' => 'cppt.from_date',
                    'earliest_end_date' => 'cppt.to_date',
                    new Zend_Db_Expr(
                        $this->_connection->getCaseSql(
                            '',
                            array(
                                $this->_connection->getIfNullSql(
                                    new Zend_Db_Expr('@group_id'),
                                    $nA
                                ) . ' != cppt.grouped_id' => new Zend_Db_Expr('@action_stop := cppt.action_stop'),
                                $this->_connection->getIfNullSql(
                                    new Zend_Db_Expr('@group_id'),
                                    $nA
                                ) . ' = cppt.grouped_id' => '@action_stop := '
                                    . $this->_connection->getIfNullSql(
                                        new Zend_Db_Expr('@action_stop'),
                                        new Zend_Db_Expr(0)
                                    ) . ' + cppt.action_stop',
                            )
                        )
                    ),
                    new Zend_Db_Expr('@group_id := cppt.grouped_id'),
                    'from_time'         => 'cppt.from_time',
                    'to_time'           => 'cppt.to_time'
                )
            );

        $select = $this->_connection->select()
            ->from($indexSelect, array())
            ->joinInner(
                array(
                    'dates' => $this->_connection->select()->union(
                        array(
                            new Zend_Db_Expr(
                                'SELECT ' . $this->_connection->getDateAddSql(
                                    $this->_connection->fromUnixtime($time),
                                    -1,
                                    Varien_Db_Adapter_Interface::INTERVAL_DAY
                                ) . ' AS rule_date'
                            ),
                            new Zend_Db_Expr('SELECT ' . $this->_connection->fromUnixtime($time) . ' AS rule_date'),
                            new Zend_Db_Expr(
                                'SELECT ' . $this->_connection->getDateAddSql(
                                    $this->_connection->fromUnixtime($time),
                                    1,
                                    Varien_Db_Adapter_Interface::INTERVAL_DAY
                                ) . ' AS rule_date'
                            ),
                        )
                    )
                ),
                '1=1',
                array()
            )
            ->columns(
                array(
                    'rule_product_price_id' => new Zend_Db_Expr('NULL'),
                    'rule_date'             => 'dates.rule_date',
                    'customer_group_id'     => 'customer_group_id',
                    'product_id'            => 'product_id',
                    'rule_price'            => 'MIN(rule_price)',
                    'website_id'            => new Zend_Db_Expr($website->getId()),
                    'latest_start_date'     => 'latest_start_date',
                    'earliest_end_date'     => 'earliest_end_date',
                )
            )
            ->where(new Zend_Db_Expr($this->_connection->getUnixTimestamp('dates.rule_date') . " >= from_time"))
            ->where(
                $this->_connection->getCheckSql(
                    new Zend_Db_Expr('to_time = 0'),
                    new Zend_Db_Expr(1),
                    new Zend_Db_Expr($this->_connection->getUnixTimestamp('dates.rule_date') . " <= to_time")
                )
            )
            ->group(array('customer_group_id', 'product_id', 'dates.rule_date', 'website_id'));

        return $select;
    }
colinmollenhour commented 4 years ago

Your fix looks valid to me, grouping by website_id should prevent duplicate rules from different websites, but shouldn't there be a filter clause on website_id as well?

tim-breitenstein-it commented 4 years ago

@colinmollenhour Do you mean?

    /**
     * Prepare index select
     *
     * @param Mage_Core_Model_Website $website
     * @param int|Zend_Db_Expr $time
     * @return Varien_Db_Select
     */
    protected function _prepareIndexSelect(Mage_Core_Model_Website $website, $time)
    {
        $nA = $this->_connection->quote('N/A');
        $this->_connection->query('SET @price := 0');
        $this->_connection->query('SET @group_id := NULL');
        $this->_connection->query('SET @action_stop := NULL');

        $indexSelect = $this->_connection->select()
            ->from(array('cppt' => $this->_getTemporaryTable()), array())
            ->order(array('cppt.grouped_id', 'cppt.sort_order', 'cppt.rule_product_id'))
            ->columns(
                array(
                    'customer_group_id' => 'cppt.customer_group_id',
                    'product_id'        => 'cppt.product_id',
                    'rule_price'        => $this->_calculatePrice(),
                    'latest_start_date' => 'cppt.from_date',
                    'earliest_end_date' => 'cppt.to_date',
                    new Zend_Db_Expr(
                        $this->_connection->getCaseSql(
                            '',
                            array(
                                $this->_connection->getIfNullSql(
                                    new Zend_Db_Expr('@group_id'),
                                    $nA
                                ) . ' != cppt.grouped_id' => new Zend_Db_Expr('@action_stop := cppt.action_stop'),
                                $this->_connection->getIfNullSql(
                                    new Zend_Db_Expr('@group_id'),
                                    $nA
                                ) . ' = cppt.grouped_id' => '@action_stop := '
                                    . $this->_connection->getIfNullSql(
                                        new Zend_Db_Expr('@action_stop'),
                                        new Zend_Db_Expr(0)
                                    ) . ' + cppt.action_stop',
                            )
                        )
                    ),
                    new Zend_Db_Expr('@group_id := cppt.grouped_id'),
                    'from_time'         => 'cppt.from_time',
                    'to_time'           => 'cppt.to_time'
                )
            );

        $select = $this->_connection->select()
            ->from($indexSelect, array())
            ->joinInner(
                array(
                    'dates' => $this->_connection->select()->union(
                        array(
                            new Zend_Db_Expr(
                                'SELECT ' . $this->_connection->getDateAddSql(
                                    $this->_connection->fromUnixtime($time),
                                    -1,
                                    Varien_Db_Adapter_Interface::INTERVAL_DAY
                                ) . ' AS rule_date'
                            ),
                            new Zend_Db_Expr('SELECT ' . $this->_connection->fromUnixtime($time) . ' AS rule_date'),
                            new Zend_Db_Expr(
                                'SELECT ' . $this->_connection->getDateAddSql(
                                    $this->_connection->fromUnixtime($time),
                                    1,
                                    Varien_Db_Adapter_Interface::INTERVAL_DAY
                                ) . ' AS rule_date'
                            ),
                        )
                    )
                ),
                '1=1',
                array()
            )
            ->columns(
                array(
                    'rule_product_price_id' => new Zend_Db_Expr('NULL'),
                    'rule_date'             => 'dates.rule_date',
                    'customer_group_id'     => 'customer_group_id',
                    'product_id'            => 'product_id',
                    'rule_price'            => 'MIN(rule_price)',
                    'website_id'            => new Zend_Db_Expr($website->getId()),
                    'latest_start_date'     => 'latest_start_date',
                    'earliest_end_date'     => 'earliest_end_date',
                )
            )
            ->where(new Zend_Db_Expr($this->_connection->getUnixTimestamp('dates.rule_date') . " >= from_time"))
            ->where(
                $this->_connection->getCheckSql(
                    new Zend_Db_Expr('to_time = 0'),
                    new Zend_Db_Expr(1),
                    new Zend_Db_Expr($this->_connection->getUnixTimestamp('dates.rule_date') . " <= to_time")
                )
            )
            ->where(new Zend_Db_Expr($website->getId() . " = website_id"))
            ->group(array('customer_group_id', 'product_id', 'dates.rule_date', 'website_id'));

        return $select;
    }

or something like that

    /**
     * Prepare index select
     *
     * @param Mage_Core_Model_Website $website
     * @param int|Zend_Db_Expr $time
     * @return Varien_Db_Select
     */
    protected function _prepareIndexSelect(Mage_Core_Model_Website $website, $time)
    {
        $nA = $this->_connection->quote('N/A');
        $this->_connection->query('SET @price := 0');
        $this->_connection->query('SET @group_id := NULL');
        $this->_connection->query('SET @action_stop := NULL');

        $indexSelect = $this->_connection->select()
            ->from(array('cppt' => $this->_getTemporaryTable()), array())
            ->order(array('cppt.grouped_id', 'cppt.sort_order', 'cppt.rule_product_id'))
            ->columns(
                array(
                    'customer_group_id' => 'cppt.customer_group_id',
                    'product_id'        => 'cppt.product_id',
                    'rule_price'        => $this->_calculatePrice(),
                    'latest_start_date' => 'cppt.from_date',
                    'earliest_end_date' => 'cppt.to_date',
                    new Zend_Db_Expr(
                        $this->_connection->getCaseSql(
                            '',
                            array(
                                $this->_connection->getIfNullSql(
                                    new Zend_Db_Expr('@group_id'),
                                    $nA
                                ) . ' != cppt.grouped_id' => new Zend_Db_Expr('@action_stop := cppt.action_stop'),
                                $this->_connection->getIfNullSql(
                                    new Zend_Db_Expr('@group_id'),
                                    $nA
                                ) . ' = cppt.grouped_id' => '@action_stop := '
                                    . $this->_connection->getIfNullSql(
                                        new Zend_Db_Expr('@action_stop'),
                                        new Zend_Db_Expr(0)
                                    ) . ' + cppt.action_stop',
                            )
                        )
                    ),
                    new Zend_Db_Expr('@group_id := cppt.grouped_id'),
                    'from_time'         => 'cppt.from_time',
                    'to_time'           => 'cppt.to_time'
                )
            );

        $select = $this->_connection->select()
            ->from($indexSelect, array())
            ->joinInner(
                array(
                    'dates' => $this->_connection->select()->union(
                        array(
                            new Zend_Db_Expr(
                                'SELECT ' . $this->_connection->getDateAddSql(
                                    $this->_connection->fromUnixtime($time),
                                    -1,
                                    Varien_Db_Adapter_Interface::INTERVAL_DAY
                                ) . ' AS rule_date'
                            ),
                            new Zend_Db_Expr('SELECT ' . $this->_connection->fromUnixtime($time) . ' AS rule_date'),
                            new Zend_Db_Expr(
                                'SELECT ' . $this->_connection->getDateAddSql(
                                    $this->_connection->fromUnixtime($time),
                                    1,
                                    Varien_Db_Adapter_Interface::INTERVAL_DAY
                                ) . ' AS rule_date'
                            ),
                        )
                    )
                ),
                '1=1',
                array()
            )
            ->columns(
                array(
                    'rule_product_price_id' => new Zend_Db_Expr('NULL'),
                    'rule_date'             => 'dates.rule_date',
                    'customer_group_id'     => 'customer_group_id',
                    'product_id'            => 'product_id',
                    'rule_price'            => 'MIN(rule_price)',
                    'website_id'            => new Zend_Db_Expr($website->getId()),
                    'latest_start_date'     => 'latest_start_date',
                    'earliest_end_date'     => 'earliest_end_date',
                )
            )
            ->where(new Zend_Db_Expr($this->_connection->getUnixTimestamp('dates.rule_date') . " >= from_time"))
            ->where(
                $this->_connection->getCheckSql(
                    new Zend_Db_Expr('to_time = 0'),
                    new Zend_Db_Expr(1),
                    new Zend_Db_Expr($this->_connection->getUnixTimestamp('dates.rule_date') . " <= to_time")
                )
            )
            ->addAttributeToFilter('website_id', $website->getId())
            ->group(array('customer_group_id', 'product_id', 'dates.rule_date', 'website_id'));

        return $select;
    }
colinmollenhour commented 4 years ago

Yes, either of those, although my personal preference is:

->where('website_id = ?', $website->getId())
tim-breitenstein-it commented 3 years ago

Yes, either of those, although my personal preference is:

->where('website_id = ?', $website->getId())

This won´t work:

[Zend_Db_Statement_Exception]
  SQLSTATE[42S22]: Column not found: 1054 Unknown column 'website_id' in 'where clause', query was: 

What finally works for me:

    /**
     * Fill Index Data
     *
     * @param Mage_Core_Model_Website $website
     * @param int $time
     */
    protected function _fillIndexData(Mage_Core_Model_Website $website, $time)
    {
        $this->_connection->query(
            $this->_connection->insertFromSelect(
                $this->_prepareIndexSelect($website, $time),
                $this->_resource->getTable('catalogrule/rule_product_price'),
                [],
                Varien_Db_Adapter_Interface::INSERT_IGNORE
            )
        );
    }