-
-
Notifications
You must be signed in to change notification settings - Fork 436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improving query performance for coupon code check #1110
Conversation
Hi |
pinging @lemundo-team to see if we can get some info although this PR is quite old |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested and (although I don't have milions of records) the query goes from 26ms to 0.5ms so that's quite an important gain in the context of high traffic
with around 100k coupons the query goes from 150ms to 0.6ms, great result!!
@@ -91,7 +91,7 @@ public function setValidationFilter($websiteId, $customerGroupId, $couponCode = | |||
$connection->quoteInto( | |||
'main_table.rule_id = rule_coupons.rule_id AND main_table.coupon_type != ?', | |||
Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON | |||
), | |||
) . $connection->quoteInto(' AND rule_coupons.code = ?', $couponCode), // Fixing Performance Issue for Coupon Checkout! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happen if $couponCode = ''
? Has this been tested?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the cart page works fine, before and after adding the coupon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the method has default $couponCode = ''
, possibly called somewhere else other than cart page. This needs to be tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just checked, the method only reference once. So may be we can do a BC change
from
public function setValidationFilter($websiteId, $customerGroupId, $couponCode = '', $now = null)
to
public function setValidationFilter($websiteId, $customerGroupId, $couponCode, $now = null)
fixed conflict |
@Flyingmana can we setup demo-instances and connect them to blackfire.io?
|
we have our demo on nexess which is configured here: https://github.com/OpenMage/OpenMage-demo-deployment (and where we have also newRelic configured) although this looks more like something which fits into the gitpod thing |
I think we should have both the fixes |
I haven't finished the crash test for my version. |
this would be nice, but should be discussed somewhere else. |
$result = Mage::getResourceModel('salesrule/rule_collection')
->setValidationFilter(1, 10, 'abc')
->getSelect()->__toString();
SELECT`main_table`.*, `rule_coupons`.`code`
FROM `salesrule` AS `main_table`
INNER JOIN `salesrule_customer_group` AS `customer_group_ids`
ON main_table.rule_id = customer_group_ids.rule_id AND customer_group_ids.customer_group_id = 10
LEFT JOIN `salesrule_coupon` AS `rule_coupons`
ON main_table.rule_id = rule_coupons.rule_id
AND main_table.coupon_type != 1 #cond1
AND rule_coupons.code = 'abc' #cond2 added by PR
WHERE
(
EXISTS (
SELECT 1
FROM `salesrule_website` AS `website`
WHERE
(website.website_id IN (1)) AND (main_table.rule_id = website.rule_id)
)
)
AND (from_date is null or from_date <= '2023-01-19')
AND (to_date is null or to_date >= '2023-01-19')
AND (`is_active` = '1')
AND (
main_table.coupon_type = 1 #see cond1, this is always false
OR (
(
(
main_table.coupon_type = 3 AND rule_coupons.type = 0
)
OR (
main_table.coupon_type = 2 AND main_table.use_auto_generation = 1 AND rule_coupons.type = 1
)
OR (
main_table.coupon_type = 2 AND main_table.use_auto_generation = 0 AND rule_coupons.type = 0
)
)
AND rule_coupons.code = 'abc'
)
) Can be simplified to SELECT`main_table`.*, `rule_coupons`.`code`
FROM `salesrule` AS `main_table`
INNER JOIN `salesrule_customer_group` AS `customer_group_ids`
ON main_table.rule_id = customer_group_ids.rule_id AND customer_group_ids.customer_group_id = 10
LEFT JOIN `salesrule_coupon` AS `rule_coupons`
ON main_table.rule_id = rule_coupons.rule_id
AND main_table.coupon_type != 1
AND rule_coupons.code = 'abc' #cond2 added by PR
WHERE
(
EXISTS (
SELECT 1
FROM `salesrule_website` AS `website`
WHERE
(website.website_id IN (1)) AND (main_table.rule_id = website.rule_id)
)
)
AND (from_date is null or from_date <= '2023-01-19')
AND (to_date is null or to_date >= '2023-01-19')
AND (`is_active` = '1')
AND rule_coupons.code = 'abc' #cond3
AND
(
(
main_table.coupon_type = 3 AND rule_coupons.type = 0
)
OR (
main_table.coupon_type = 2 AND main_table.use_auto_generation <= 1 AND rule_coupons.type <= 1
)
) I think either cond2 or cond3 can be removed, but not sure which one is faster. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested with a cart with one rule without code, and with another rule with a coupon code.
I think this is good.
@kiatng let's merge this in the meanwhile and see if we can improve it ;-) |
…#1110) Co-authored-by: Hannes Drittler <h.drittler@lemundo.de> Co-authored-by: Fabrizio Balliano <fabrizio.balliano@gmail.com>
merged and cherrypicked to v20 |
Just FYI Thank you! |
Adding coupon code to where clause in order to improve query performance
Description (*)
This was one of the major bottle necks over the last few Black Fridays! Thousands of customers applying coupon codes in checkout and the checkout is causing causing more and more load.
It might be that this query is only leading to bad performance when using certain MySQL versions like #295 does...
Related Pull Requests
#303
Manual testing scenarios (*)
Contribution checklist (*)