Skip to content

[BUG] Mage_SalesRule_Model_Observer->addProductAttributes produces a slow query #4979

@EliasKotlyar

Description

@EliasKotlyar

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Hello

We are experiencing a performance Problem with the following Query:
Query: SELECT DISTINCT ea.attribute_code FROM salesrule_product_attribute AS a
INNER JOIN eav_attribute AS ea ON ea.attribute_id = a.attribute_id
Time: 0.33641290664673 sec

We traced it down to following code:
public function getActiveAttributes($websiteId, $customerGroupId)
{
$read = $this->_getReadAdapter();
$select = $read->select()
->from(
['a' => $this->getTable('salesrule/product_attribute')],
new Zend_Db_Expr('DISTINCT ea.attribute_code'),
)
->joinInner(['ea' => $this->getTable('eav/attribute')], 'ea.attribute_id = a.attribute_id', []);
return $read->fetchAll($select);
}

It would be great if we could improve performance here. Also we can remove unused parameters. See the following MR

Expected Behavior

Query would run faster

Steps To Reproduce

Run any test using sales_flat_rules

Environment

- OpenMage:
- php:

Anything else?

Query has been optimized to:
SELECT ea.attribute_code
FROM eav_attribute AS ea
INNER JOIN (
SELECT DISTINCT attribute_id FROM salesrule_product_attribute
) AS a ON ea.attribute_id = a.attribute_id;

Which is a slightly faster version.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions