Skip to content
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

Switch order search to using starts over cont #1660

Conversation

gmacdougall
Copy link
Member

Due to the way that standard indexes work in modern databases. Use of
contains to find a string is very inefficient. Instead, if we find
things that start with the string, the index can find the records it is
looking for very efficiently.

This turns a table sequential scan into a simple index lookup
signifncantly speeding things up, or avoiding timeouts on stores with
millions of orders.

Example:

mysql> SELECT COUNT(`spree_orders`.`id`) FROM `spree_orders` WHERE (`spree_orders` .`email` LIKE '%foo@bar\\.com%' AND `spree_orders`.`completed_at` IS NULL);
+----------------------------+
| COUNT(`spree_orders`.`id`) |
+----------------------------+
|                          1 |
+----------------------------+
1 row in set (20.27 sec)

mysql> SELECT COUNT(`spree_orders`.`id`) FROM `spree_orders` WHERE (`spree_orders` .`email` LIKE 'foo@bar\\.com%' AND `spree_orders`.`completed_at` IS NULL);
+----------------------------+
| COUNT(`spree_orders`.`id`) |
+----------------------------+
|                          1 |
+----------------------------+
1 row in set (0.00 sec)

Copy link
Contributor

@jhawthorn jhawthorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

I think the order number and shipment number might as well be a plain ==, but let's ship this change first and see if this causes anyone any hardships. The only field here I think might be useful to do a "contains" instead of a "start" is email.

Can this get a CHANGELOG entry?

@gmacdougall
Copy link
Member Author

gmacdougall commented Dec 20, 2016

Sure thing. I agree that having contains would be better than starts with on e-mail, but the reason that this came up is that we're getting timeouts on our site with large numbers of orders when attempting to search via e-mail.

@gmacdougall gmacdougall force-pushed the stop-using-contains-on-order-search branch from 2cb4ac5 to e13e004 Compare December 20, 2016 23:44
@gmacdougall
Copy link
Member Author

Changelog added in an amendment.

@stewart
Copy link
Contributor

stewart commented Dec 21, 2016

I believe the contains is also useful for promotion codes.

@cbrunsdon
Copy link
Contributor

I think this is probably worth reaching out to a few places CS departments and do a quick ask to see if they ever use email addresses with "contains" like that. I know people could override the view and switch the query param back, but its potentially a disruptive thing. It would be nice if we could support wildcards ourselves and let people decide when to use them.

@jhawthorn
Copy link
Contributor

@cbrunsdon @gmacdougall Can anything be done to move this forward? One of our promises with Solidus is to work well on large stores, which this change is necessary for.

Maybe we should start by changing the less controversial searches, like number and shipment_number to _start

@gmacdougall
Copy link
Member Author

I feel that all of the things listed here are large enough that non-indexed searches are inappropriate. It's not that hard to get millions of orders or promotion codes.

@bbuchalter
Copy link
Contributor

@gmacdougall can we get this one rebased on master and review this work again?

=======
click_on 'Filter'
fill_in "q_promotions_codes_value_start", with: promotion.codes.first.value
>>>>>>> e13e004... Switch order search to using starts over cont

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpected token tRSHFT
unexpected token tIDENTIFIER

||||||| parent of e13e004... Switch order search to using starts over cont
click_on 'Filter'
fill_in "q_promotions_codes_value_cont", with: promotion.codes.first.value
=======

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpected token tEQQ

click_on "Filter Results"
fill_in "q_order_promotions_promotion_code_value_cont", with: promotion.codes.first.value
||||||| parent of e13e004... Switch order search to using starts over cont

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpected token tOROP
unexpected token tIDENTIFIER

@@ -160,8 +160,16 @@
end

it "only shows the orders with the selected promotion" do
<<<<<<< HEAD

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpected token tLSHFT

@gmacdougall
Copy link
Member Author

Change rebased and shall rise again!

@gmacdougall gmacdougall force-pushed the stop-using-contains-on-order-search branch from 227439b to 847bb0a Compare July 2, 2017 12:58
Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with this change, it just needs a rebase that fixes CHANGELOG (again) and the conflict error.

Going to request changes to point out that it needs some action, I'll approve once fixed! 👍

=======
<%= label_tag :q_number_start, Spree.t(:order_number, :number => '') %>
<%= f.text_field :number_start %>
>>>>>>> e13e004... Switch order search to using starts over cont
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmacdougall I think this has been introduced rebasing and fixing the CHANGELOG conflict.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad. I'll fix that up.

@gmacdougall gmacdougall force-pushed the stop-using-contains-on-order-search branch 2 times, most recently from 51507cc to e6458c8 Compare July 3, 2017 17:21
@gmacdougall
Copy link
Member Author

This is now rebased (properly)!

@gmacdougall gmacdougall force-pushed the stop-using-contains-on-order-search branch from e6458c8 to 2979d6f Compare July 4, 2017 20:38
@mamhoff
Copy link
Contributor

mamhoff commented Oct 4, 2017

Resolved conflict with the current master branch so that the changelog entry is in the right place. I still think this is a worthwhile change.

@tvdeyen
Copy link
Member

tvdeyen commented Oct 4, 2017

@gmacdougall would you mind to rebase again so we can merge this?

Due to the way that standard indexes work in modern databases. Use of
contains to find a string is very inefficient. Instead, if we find
things that start with the string, the index can find the records it is
looking for very efficiently.

This turns a table sequential scan into a simple index lookup
signifncantly speeding things up, or avoiding timeouts on stores with
millions of orders.
@gmacdougall gmacdougall force-pushed the stop-using-contains-on-order-search branch from 1d9679b to d565006 Compare October 4, 2017 20:32
@gmacdougall
Copy link
Member Author

Rebased the CHANGELOG out of this. Should be good to go.

@gmacdougall gmacdougall merged commit 0b9cb14 into solidusio:master Oct 4, 2017
@gmacdougall gmacdougall deleted the stop-using-contains-on-order-search branch October 4, 2017 21:25
@gmacdougall gmacdougall restored the stop-using-contains-on-order-search branch October 4, 2017 21:25
@mtomov
Copy link
Contributor

mtomov commented Oct 5, 2017

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants