Improve performance of queries for search filters #14754
Labels
bug
Issues or PR's relating to bugs
performance-scalability
Anything related to performance and scalability
search
Issues relating to the search facility in Mautic
Mautic Series
5.2.x series
Mautic installed version
5.2.3
Way of installing
I installed with composer using https://github.com/mautic/recommended-project
PHP version
8.1
What browsers are you seeing the problem on?
Not relevant
What happened?
When using (non base table) searches in the contact overview, the generated query is not optimal, causing performance impact an possible time outs.
How can we reproduce this issue?
Step 1: Have a mautic with preferably a large amount of contacts.
Step 2: Use a search filter, targeting a seperate table, for example filter on a segment with that filter.
The problem lies that this query transforms the filter to a where clause.
See https://github.com/mautic/mautic/blob/6.x/app/bundles/LeadBundle/Entity/CustomFieldRepositoryTrait.php#L45
The where clause generated is a subquery of the other table it needs to reference. See https://github.com/mautic/mautic/blob/6.x/app/bundles/CoreBundle/Entity/CommonRepository.php#L1454
For example getting contacts from a segment uses below query.
On our instances (1.5M leads) this takes 6+ seconds.
If the building of this query could use a join instead of a subquery in the where statement, time goes down to less than .1 seconds.
Main problem where this occurs is when exporting the list of contacts to xls or csv, there this query runs per batch of 200 contacts (so 6+ seconds per batch) and times out. For example, list of 1000 contacts, runs that 5 times, which is 30+ seconds, so you encounter quite quickly a php timeout.
Relevant log output
Code of Conduct
Care about this issue? Want to get it resolved sooner? If you are a member of Mautic, you can add some funds to the Bounties Project so that the person who completes this task can claim those funds once it is merged by a member of the core team! Read the docs here.
The text was updated successfully, but these errors were encountered: