Skip to content

Extremely slow getOrders query because of query complexity #65

Description

@dylanmaurits

This piece of code in the searchDataProvider can generate queries that take up to tens of seconds when querying for increment id.

        $emailFilter = (new Filter())
            ->setField(OrderInterface::CUSTOMER_EMAIL)
            ->setValue($searchTerm . '%')
            ->setConditionType('like');

        $idFilter = (new Filter())
            ->setField(OrderInterface::INCREMENT_ID)
            ->setValue($searchTerm . '%')
            ->setConditionType('like');

        $searchCriteria = $this->searchCriteriaBuilder
            ->addFilters([$emailFilter, $idFilter])
            ->setPageSize(10)
            ->create();

        $orders = $this->orderRepository
            ->getList($searchCriteria)
            ->getItems();

This is an example of a query that is generated by this piece of code:

SELECT `main_table`.*
FROM `sales_order` AS `main_table` 
WHERE ((`customer_email` LIKE 'ST_11000114112') OR (`increment_id` LIKE 'ST_11000114112')) LIMIT 10;

Here's an example of how much time this query takes on our test enviroment (45 seconds):
Image

There's probably more ways to fix this issue but I think it would be a good idea to split the email and the increment_id search. These should not be in the same query with the same value. They're not related that way anyways.

I am probably going to overwrite it for now and look for an '@' in the searchTerm and determine which filter to use based on that and don't set another filter however this would break if you have an '@' in your increment ID for some reason so this should be fixed properly.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions