# Huge performance issue with landing page data views

**URL:** <https://forum.mautic.org/t/huge-performance-issue-with-landing-page-data-views/2563>\
**Category:** Product Support\
**Created:** [October 12, 2015, 8:28am UTC](https://forum.mautic.org/t/huge-performance-issue-with-landing-page-data-views/2563 "2015-10-12T08:28:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cdd\_james](https://avatars.discourse-cdn.com/v4/letter/c/a183cd/32.png) [@cdd\_james](https://forum.mautic.org/u/cdd_james)\
**Post date:** [October 12, 2015, 8:28am UTC](https://forum.mautic.org/t/huge-performance-issue-with-landing-page-data-views/2563/1 "2015-10-12T08:28:09Z")

</div>

We have been seeing big problems when trying to access (via the Mautic admin pages) the stats for landing pages. We have a page that has around 10,000 hits, and are unable to view the stats - the admin panel just hangs. We looked at the SQL query that was being used by the page and the problem seems to be with the subqueries, we were able to achieve the same output using the below query in a fraction of the time:  
  
  
  
CREATE TEMPORARY TABLE IF NOT EXISTS tmp\_0 AS (  
  
SELECT  
  
b.tracking\_id  
  
FROM  
  
page\_hits b  
  
LEFT JOIN  
  
pages p  
  
ON  
  
b.page\_id = p.id  
  
WHERE  
  
b.code = 200  
  
GROUP BY  
  
b.tracking\_id  
  
HAVING  
  
COUNT(DISTINCT(b.page\_id)) = 1  
  
);  
  
SELECT  
  
h.page\_id,  
  
count(distinct(h.tracking\_id)) AS bounces  
  
FROM  
  
page\_hits h  
  
INNER JOIN  
  
tmp\_0  
  
ON  
  
h.tracking\_id = tmp\_0.tracking\_id  
  
AND  
  
h. page\_id IN (19)  
  
GROUP BY  
  
h.page\_id  
  
;  
  
DROP TEMPORARY TABLE tmp\_0;  
  
  
  
  
  
  
  
Can you please review this and implement a revised SQL query - currently the landing pages stats element of Mautic is now currently unusable for us.

---

<div class="post-metadata">

**Author:** ![gmillard](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/gmillard/32/5_2.png) [@gmillard](https://forum.mautic.org/u/gmillard)\
**Post date:** [October 15, 2015, 1:50pm UTC](https://forum.mautic.org/t/huge-performance-issue-with-landing-page-data-views/2563/2 "2015-10-15T13:50:30Z")

</div>

The tricky part with this is because we use Doctrine ORM to support multiple database platforms, I’m not sure Doctrine’s ORM classes will allow us to easily construct such a query.

---

<div class="post-metadata">

**Author:** ![cdd\_james](https://avatars.discourse-cdn.com/v4/letter/c/a183cd/32.png) [@cdd\_james](https://forum.mautic.org/u/cdd_james)\
**Post date:** [October 19, 2015, 9:53am UTC](https://forum.mautic.org/t/huge-performance-issue-with-landing-page-data-views/2563/3 "2015-10-19T09:53:58Z")

</div>

Alan - if this sort of query is tricky with Doctrine, could you investigate alternate solutions to the query issue - currently this part of Mautic is now unusable for us.

---

<div class="post-metadata">

**Author:** ![cdd\_james](https://avatars.discourse-cdn.com/v4/letter/c/a183cd/32.png) [@cdd\_james](https://forum.mautic.org/u/cdd_james)\
**Post date:** [October 12, 2015, 8:28am UTC](https://forum.mautic.org/t/huge-performance-issue-with-landing-page-data-views/2563/4 "2015-10-12T08:28:09Z")

</div>

We have been seeing big problems when trying to access (via the Mautic admin pages) the stats for landing pages. We have a page that has around 10,000 hits, and are unable to view the stats - the admin panel just hangs. We looked at the SQL query that was being used by the page and the problem seems to be with the subqueries, we were able to achieve the same output using the below query in a fraction of the time:

CREATE TEMPORARY TABLE IF NOT EXISTS tmp\_0 AS (  
SELECT  
b.tracking\_id  
FROM  
page\_hits b  
LEFT JOIN  
pages p  
ON  
b.page\_id = p.id  
WHERE  
b.code = 200  
GROUP BY  
b.tracking\_id  
HAVING  
COUNT(DISTINCT(b.page\_id)) = 1  
);  
SELECT  
h.page\_id,  
count(distinct(h.tracking\_id)) AS bounces  
FROM  
page\_hits h  
INNER JOIN  
tmp\_0  
ON  
h.tracking\_id = tmp\_0.tracking\_id  
AND  
h. page\_id IN (19)  
GROUP BY  
h.page\_id  
;  
DROP TEMPORARY TABLE tmp\_0;

Can you please review this and implement a revised SQL query - currently the landing pages stats element of Mautic is now currently unusable for us.

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [October 14, 2015, 8:14am UTC](https://forum.mautic.org/t/huge-performance-issue-with-landing-page-data-views/2563/5 "2015-10-14T08:14:26Z")

</div>

That’s interesting. Would you mind to send a PR with your changes to official GH repo?

[https://github.com/mautic/mautic](https://github.com/mautic/mautic)

---

<div class="post-metadata">

**Author:** ![mbabker](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@mbabker](https://forum.mautic.org/u/mbabker)\
**Post date:** [October 28, 2015, 4:14pm UTC](https://forum.mautic.org/t/huge-performance-issue-with-landing-page-data-views/2563/6 "2015-10-28T16:14:45Z")

</div>

Unfortunately it seems Doctrine itself doesn’t support temporary tables at the moment (see [http://www.doctrine-project.org/jira/browse/DBAL-1145](http://www.doctrine-project.org/jira/browse/DBAL-1145)), so a native solution using Doctrine’s API is out of the question.

One possible alternative is to just feed Doctrine raw queries. In the code where these queries are being generated, the subquery would need to be wrapped in the create table statement then the outer query adjusted a bit to match the changes needed to query the temporary table. Theoretically this change is possible to accomplish but will need some heavy testing and review to see through to completion.

---

<div class="post-metadata">

**Author:** ![mbabker](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@mbabker](https://forum.mautic.org/u/mbabker)\
**Post date:** [October 30, 2015, 2:53pm UTC](https://forum.mautic.org/t/huge-performance-issue-with-landing-page-data-views/2563/7 "2015-10-30T14:53:17Z")

</div>

I make no promises this is immediately working, but [https://github.com/mautic/mautic/pull/1103](https://github.com/mautic/mautic/pull/1103) makes an attempt to restructure those queries.

---

<div class="post-metadata">

**Author:** ![silavapi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/silavapi/32/7424_2.png) [@silavapi](https://forum.mautic.org/u/silavapi)\
**Post date:** [February 2, 2020, 10:57pm UTC](https://forum.mautic.org/t/huge-performance-issue-with-landing-page-data-views/2563/8 "2020-02-02T22:57:24Z")

</div>


