Fix slow query for a student accessing the People page

Bug #1929473 reported by Tim Lock
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mahara
Fix Released
High
Doris Tam
20.04
Fix Released
High
Unassigned
20.10
Fix Released
High
Unassigned
21.04
Fix Released
High
Unassigned

Bug Description

This item fixes the issue with the query run as a student when accessing the People page initially. Once loaded the page handled the data dynamically in the background without any issues.

--

Explain analyse SELECT COUNT(u.id) FROM usr u LEFT OUTER JOIN usr_account_preference h ON (u.id = h.usr AND h.field = 'hiderealname') WHERE u.id != 0 AND u.active = 1 AND u.deleted = 0 AND u.id != 43543 AND (u.id IN ( SELECT usr FROM usr_institution WHERE institution IN ('dev') AND u.id != 43543 ));
                                                                 QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------------------
 Finalize Aggregate (cost=31657803.52..31657803.53 rows=1 width=8) (actual time=337495.337..337495.337 rows=1 loops=1)
   -> Seq Scan on usr u (cost=0.00..31657737.10 rows=26568 width=8) (actual time=8.908..337469.038 rows=47490 loops=1)
         Filter: ((id <> 0) AND (id <> 43543) AND (active = 1) AND (deleted = 0) AND (SubPlan 1))
         Rows Removed by Filter: 5831
         SubPlan 1
           -> Result (cost=0.00..1068.60 rows=47496 width=8) (actual time=0.002..4.988 rows=26305 loops=53226)
                 One-Time Filter: (u.id <> 43543)
                 -> Seq Scan on usr_institution (cost=0.00..1068.60 rows=47496 width=8) (actual time=0.001..3.047 rows=26305 loops=53226)
                       Filter: ((institution)::text = 'dev'::text)
                       Rows Removed by Filter: 5939
 Planning Time: 0.158 ms
 Execution Time: 337495.376 ms

With the fix:

Explain analyse SELECT COUNT(u.id) FROM usr u LEFT OUTER JOIN usr_account_preference h ON (u.id = h.usr AND h.field = 'hiderealname') WHERE u.id != 0 AND u.active = 1 AND u.deleted = 0 AND u.id != 43543 AND (u.id IN ( SELECT usr FROM usr_institution WHERE institution IN ('dev') ));
                                                                                       QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Finalize Aggregate (cost=4188.30..4188.31 rows=1 width=8) (actual time=29.719..29.719 rows=1 loops=1)
   -> Gather (cost=4188.19..4188.30 rows=1 width=8) (actual time=29.607..31.436 rows=2 loops=1)
         Workers Planned: 1
         Workers Launched: 1
         -> Partial Aggregate (cost=3188.19..3188.20 rows=1 width=8) (actual time=26.441..26.441 rows=1 loops=2)
               -> Parallel Hash Join (cost=1083.22..3118.59 rows=27841 width=8) (actual time=8.881..25.216 rows=23745 loops=2)
                     Hash Cond: (u.id = usr_institution.usr)
                     -> Parallel Seq Scan on usr u (cost=0.00..1953.31 rows=31256 width=8) (actual time=0.021..10.581 rows=26613 loops=2)
                           Filter: ((id <> 0) AND (id <> 43543) AND (active = 1) AND (deleted = 0))
                           Rows Removed by Filter: 48
                     -> Parallel Hash (cost=835.85..835.85 rows=19790 width=8) (actual time=8.517..8.517 rows=23746 loops=2)
   ...

Revision history for this message
Tim Lock (timlock) wrote :
Revision history for this message
Kristina Hoeppner (kris-hoeppner) wrote :

Hi Tim,

Thank you for reporting the problem and providing a patch. We'll add it into our code review system.

If you send me your email address, we can make sure to attribute the fix correctly. My email address should be visible in my Launchpad profile.

Thank you
Kristina

Changed in mahara:
assignee: nobody → Doris Tam (doristam)
milestone: none → 21.10.0
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
Mahara Bot (dev-mahara) wrote : A patch has been submitted for review

Patch for "master" branch: https://reviews.mahara.org/11864

Doris Tam (doristam)
Changed in mahara:
status: Confirmed → Won't Fix
status: Won't Fix → In Progress
Revision history for this message
Mahara Bot (dev-mahara) wrote : A change has been merged

Reviewed: https://reviews.mahara.org/11864
Committed: https://git.mahara.org/mahara/mahara/commit/bd5d141608d7478a6499c269b41ca579a7b321a8
Submitter: Robert Lyon (<email address hidden>)
Branch: master

commit bd5d141608d7478a6499c269b41ca579a7b321a8
Author: Tim Lock <email address hidden>
Date: Mon Jul 19 13:28:21 2021 +1200

Bug 1929473: Fix slow query for when students access the People page

Change-Id: I5551c2f5e84ab4442928ba63e82d3b423efb9c48

Robert Lyon (robertl-9)
Changed in mahara:
importance: Medium → High
Revision history for this message
Mahara Bot (dev-mahara) wrote : A patch has been submitted for review

Patch for "21.04_STABLE" branch: https://reviews.mahara.org/11905

Revision history for this message
Mahara Bot (dev-mahara) wrote :

Patch for "20.10_STABLE" branch: https://reviews.mahara.org/11906

Revision history for this message
Mahara Bot (dev-mahara) wrote :

Patch for "20.04_STABLE" branch: https://reviews.mahara.org/11907

Revision history for this message
Mahara Bot (dev-mahara) wrote : A change has been merged

Reviewed: https://reviews.mahara.org/11906
Committed: https://git.mahara.org/mahara/mahara/commit/bd71da803dd277764b9e7c3e695ced8365da5e37
Submitter: Robert Lyon (<email address hidden>)
Branch: 20.10_STABLE

commit bd71da803dd277764b9e7c3e695ced8365da5e37
Author: Tim Lock <email address hidden>
Date: Mon Jul 19 13:28:21 2021 +1200

Bug 1929473: Fix slow query for when students access the People page

Change-Id: I5551c2f5e84ab4442928ba63e82d3b423efb9c48
(cherry picked from commit bd5d141608d7478a6499c269b41ca579a7b321a8)

Revision history for this message
Mahara Bot (dev-mahara) wrote :

Reviewed: https://reviews.mahara.org/11905
Committed: https://git.mahara.org/mahara/mahara/commit/fbe73d9dd28e2800c0750cb252944c4fb6fab476
Submitter: Robert Lyon (<email address hidden>)
Branch: 21.04_STABLE

commit fbe73d9dd28e2800c0750cb252944c4fb6fab476
Author: Tim Lock <email address hidden>
Date: Mon Jul 19 13:28:21 2021 +1200

Bug 1929473: Fix slow query for when students access the People page

Change-Id: I5551c2f5e84ab4442928ba63e82d3b423efb9c48
(cherry picked from commit bd5d141608d7478a6499c269b41ca579a7b321a8)

Revision history for this message
Mahara Bot (dev-mahara) wrote :

Reviewed: https://reviews.mahara.org/11907
Committed: https://git.mahara.org/mahara/mahara/commit/9efd1bc3efd7c2bb015de9d78d7e8b0e9d5415e1
Submitter: Robert Lyon (<email address hidden>)
Branch: 20.04_STABLE

commit 9efd1bc3efd7c2bb015de9d78d7e8b0e9d5415e1
Author: Tim Lock <email address hidden>
Date: Mon Jul 19 13:28:21 2021 +1200

Bug 1929473: Fix slow query for when students access the People page

Change-Id: I5551c2f5e84ab4442928ba63e82d3b423efb9c48
(cherry picked from commit bd5d141608d7478a6499c269b41ca579a7b321a8)

no longer affects: mahara/21.10
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.