# Bug OP-13639 - Slow performance after upgrade to version 13

Project: OpenProject
Status: closed
URL: https://community.openproject.org/work_packages/OP-13639

## Open points

_No work packages_

## Details

| Attribute | Value |
| --- | --- |
| Date |  |
| Priority | High |
| Module |  |
| Target versions | 13.3.0 |
| Observed in versions |  |
| Sprint | 13.3.0 |
| Backlog bucket |  |
| Bug found in version (deprecated) |  |
| Found in mobile app version |  |
| Follow-up feedback e-mail |  |
| Requires doc change | No |
| Accessibility | No |
| Pull preview |  |
| List |  |
| Labels |  |

## People

| Attribute | Value |
| --- | --- |
| Assignee |  |
| Accountable |  |
| Product manager |  |
| Developers |  |
| Designer |  |
| Ordered by |  |
| Signed off by |  |
| Interest by |  |

## Planning

| Attribute | Value |
| --- | --- |
| Relevance |  |

## Costs

| Attribute | Value |
| --- | --- |
| Votes |  |
| Work |  |
| Labor costs |  |

## Description

### Trigger for this bug

Users started to complain about the performance after the upgrade. I also noticed a more complex work-package view to load very slowly which loaded quite acceptable in the prior version (12.5.8).

### Steps to reproduce

1.  Setup an instance with a lot of projects and work-packages in version 12.5.8
2.  Measure time to load work-package views
3.  Upgrade to version 13.0.7
4.  Measure time to load work-package views

### What is the buggy behavior?

*   extremely slow loading

### What is the expected behavior?

*   same performance, or maybe deactivating baseline-comparison

### More information

*   a lot of PostgreSQL load visible via top

### Environment information

**OpenProject installation type**

*   [ ] Hosted cloud edition
*   [x] Packaged installation
    *   What distribution? Debian
*   [ ] Docker All-in-one container
*   [ ] Docker-compose installation
*   [ ] Other (please specify)

# Statistics (2023-12-12 ... 2023-12-15)

<figure class="table op-uc-figure_align-center op-uc-figure"><table class="op-uc-table"><thead class="op-uc-table--head"><tr class="op-uc-table--row"><th class="op-uc-table--cell op-uc-table--cell_head"><p class="op-uc-p">Duration</p></th><th class="op-uc-table--cell op-uc-table--cell_head"><p class="op-uc-p">Number of queries</p></th><th class="op-uc-table--cell op-uc-table--cell_head"><p class="op-uc-p">Number of notification queries</p></th></tr></thead><tbody><tr class="op-uc-table--row"><td class="op-uc-table--cell"><p class="op-uc-p">&gt; 100.000ms</p></td><td class="op-uc-table--cell"><p class="op-uc-p">339</p></td><td class="op-uc-table--cell"><p class="op-uc-p">339</p></td></tr><tr class="op-uc-table--row"><td class="op-uc-table--cell"><p class="op-uc-p">&gt; 10.000ms</p></td><td class="op-uc-table--cell"><p class="op-uc-p">6161</p></td><td class="op-uc-table--cell"><p class="op-uc-p">6157</p></td></tr><tr class="op-uc-table--row"><td class="op-uc-table--cell"><p class="op-uc-p">&gt; 1.000ms</p></td><td class="op-uc-table--cell"><p class="op-uc-p">48677</p></td><td class="op-uc-table--cell"><p class="op-uc-p">45200</p></td></tr></tbody></table></figure>

# Notable queries

## Under load

I filtered all 5-digit duration queries. Not exactly receiving negative feedback from users right now (not being on-site right now), it seems these massive amounts simply block workers on PostgreSQL. Could you have a look into this?

First, I grepped out all those long-running queries, then I added some query types for you to investigate.

## Log of long-running queries (more than 10.000ms)

```sql
2023-12-12 07:31:45.930 CET [627137] openproject@openproject LOG:  duration: 60534.772 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 07:31:47.010 CET [626592] openproject@openproject LOG:  duration: 61978.870 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 07:31:54.931 CET [627258] openproject@openproject LOG:  duration: 60450.996 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 07:32:53.305 CET [627285] openproject@openproject LOG:  duration: 51523.089 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 07:32:53.322 CET [627272] openproject@openproject LOG:  duration: 51520.089 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 07:32:54.407 CET [627273] openproject@openproject LOG:  duration: 52986.176 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 07:34:39.929 CET [627258] openproject@openproject LOG:  duration: 54396.960 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 07:34:47.438 CET [627272] openproject@openproject LOG:  duration: 53977.613 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 07:55:37.893 CET [627272] openproject@openproject LOG:  duration: 70168.188 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 07:55:38.100 CET [627257] openproject@openproject LOG:  duration: 71365.518 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 07:55:38.286 CET [627433] openproject@openproject LOG:  duration: 69793.324 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 07:55:39.478 CET [627290] openproject@openproject LOG:  duration: 68177.186 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 07:59:05.870 CET [627736] openproject@openproject LOG:  duration: 57954.145 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 07:59:07.112 CET [627740] openproject@openproject LOG:  duration: 58942.168 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 08:01:04.326 CET [627728] openproject@openproject LOG:  duration: 62359.259 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 08:01:05.009 CET [627670] openproject@openproject LOG:  duration: 61997.598 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 08:12:42.609 CET [627728] openproject@openproject LOG:  duration: 64331.658 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 08:12:44.638 CET [627669] openproject@openproject LOG:  duration: 66336.571 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 08:13:12.580 CET [627808] openproject@openproject LOG:  duration: 56701.593 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 08:13:12.582 CET [627889] openproject@openproject LOG:  duration: 57139.576 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 08:15:35.779 CET [628023] openproject@openproject LOG:  duration: 59154.801 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 08:17:31.790 CET [628061] openproject@openproject LOG:  duration: 59964.535 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 08:17:33.542 CET [628064] openproject@openproject LOG:  duration: 58606.424 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 08:17:43.666 CET [628106] openproject@openproject LOG:  duration: 60845.766 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 08:21:31.583 CET [628080] openproject@openproject LOG:  duration: 59770.365 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 08:24:24.066 CET [628238] openproject@openproject LOG:  duration: 67083.841 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 08:25:30.390 CET [628222] openproject@openproject LOG:  duration: 72418.616 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 08:25:30.981 CET [628218] openproject@openproject LOG:  duration: 72788.982 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 08:29:51.757 CET [628384] openproject@openproject LOG:  duration: 68667.326 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 08:29:51.797 CET [628407] openproject@openproject LOG:  duration: 66359.566 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 08:29:51.936 CET [628420] openproject@openproject LOG:  duration: 66286.262 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 08:32:11.537 CET [628496] openproject@openproject LOG:  duration: 65383.238 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 08:32:12.947 CET [628494] openproject@openproject LOG:  duration: 66517.980 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 08:35:11.499 CET [628521] openproject@openproject LOG:  duration: 57306.747 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 08:44:43.326 CET [628664] openproject@openproject LOG:  duration: 55716.084 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 08:44:44.254 CET [628611] openproject@openproject LOG:  duration: 55801.674 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 08:44:44.404 CET [628647] openproject@openproject LOG:  duration: 56630.043 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 09:29:23.842 CET [629263] openproject@openproject LOG:  duration: 58801.722 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 09:29:26.286 CET [629319] openproject@openproject LOG:  duration: 58096.550 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 09:32:14.274 CET [629429] openproject@openproject LOG:  duration: 57499.507 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 09:42:59.153 CET [629675] openproject@openproject LOG:  duration: 58893.189 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 09:54:43.105 CET [629791] openproject@openproject LOG:  duration: 57348.928 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 09:54:43.447 CET [629866] openproject@openproject LOG:  duration: 58814.657 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 09:57:01.322 CET [629610] openproject@openproject LOG:  duration: 64571.079 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 09:57:02.248 CET [629640] openproject@openproject LOG:  duration: 61346.312 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 09:57:03.802 CET [629600] openproject@openproject LOG:  duration: 61875.028 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 10:22:43.828 CET [630107] openproject@openproject LOG:  duration: 60499.359 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 10:22:45.008 CET [630065] openproject@openproject LOG:  duration: 58486.749 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 10:22:45.398 CET [629951] openproject@openproject LOG:  duration: 58283.553 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 10:22:51.765 CET [630004] openproject@openproject LOG:  duration: 60492.428 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 10:26:45.506 CET [630375] openproject@openproject LOG:  duration: 74053.749 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 10:28:56.801 CET [630495] openproject@openproject LOG:  duration: 49813.884 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 10:28:57.665 CET [630424] openproject@openproject LOG:  duration: 49656.793 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 10:29:01.370 CET [630497] openproject@openproject LOG:  duration: 49587.217 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 10:29:02.795 CET [630511] openproject@openproject LOG:  duration: 51500.777 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 10:36:48.680 CET [630489] openproject@openproject LOG:  duration: 26974.363 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 10:36:49.767 CET [630511] openproject@openproject LOG:  duration: 28058.550 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 10:48:39.972 CET [630495] openproject@openproject LOG:  duration: 90394.583 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 11:00:44.611 CET [630972] openproject@openproject LOG:  duration: 104641.268 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 A
2023-12-12 11:07:00.182 CET [631231] openproject@openproject LOG:  duration: 24626.920 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 11:07:00.887 CET [631194] openproject@openproject LOG:  duration: 25399.237 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 12:32:45.468 CET [632447] openproject@openproject LOG:  duration: 11703.753 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 12:32:45.643 CET [632450] openproject@openproject LOG:  duration: 11718.453 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 12:32:45.959 CET [632421] openproject@openproject LOG:  duration: 12186.643 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 12:41:20.778 CET [632675] openproject@openproject LOG:  duration: 10532.508 ms  execute <unnamed>: SELECT "journals"."id" AS event_id, "journals"."created_at" AS event_datetime, "journals".
2023-12-12 13:20:10.649 CET [633863] openproject@openproject LOG:  duration: 10278.514 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 13:20:10.867 CET [633817] openproject@openproject LOG:  duration: 10701.953 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 13:20:15.206 CET [633815] openproject@openproject LOG:  duration: 10559.895 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 13:31:02.239 CET [633958] openproject@openproject LOG:  duration: 32459.064 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 13:31:03.339 CET [633923] openproject@openproject LOG:  duration: 33156.043 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 14:05:07.210 CET [634586] openproject@openproject LOG:  duration: 35542.881 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 14:05:08.069 CET [634590] openproject@openproject LOG:  duration: 36009.800 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 14:10:49.041 CET [634595] openproject@openproject LOG:  duration: 28979.913 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 14:10:49.327 CET [634605] openproject@openproject LOG:  duration: 29918.287 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 15:00:32.928 CET [635650] openproject@openproject LOG:  duration: 73931.885 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 15:00:33.575 CET [635675] openproject@openproject LOG:  duration: 74660.518 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 15:03:47.225 CET [635774] openproject@openproject LOG:  duration: 122122.197 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 A
2023-12-12 15:08:36.251 CET [635839] openproject@openproject LOG:  duration: 80592.985 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 15:11:11.450 CET [635895] openproject@openproject LOG:  duration: 83176.658 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 15:13:18.430 CET [636030] openproject@openproject LOG:  duration: 67512.323 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 15:15:30.650 CET [636058] openproject@openproject LOG:  duration: 58768.346 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 15:16:02.251 CET [636099] openproject@openproject LOG:  duration: 66047.473 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 15:16:23.642 CET [636079] openproject@openproject LOG:  duration: 74930.056 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 15:19:26.489 CET [636191] openproject@openproject LOG:  duration: 75041.230 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 15:22:11.001 CET [636257] openproject@openproject LOG:  duration: 67326.627 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 15:31:45.286 CET [636296] openproject@openproject LOG:  duration: 78483.819 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 15:33:54.394 CET [636508] openproject@openproject LOG:  duration: 73393.886 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 15:37:49.253 CET [636592] openproject@openproject LOG:  duration: 67074.913 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 15:50:12.732 CET [636615] openproject@openproject LOG:  duration: 64686.562 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 15:51:21.686 CET [636693] openproject@openproject LOG:  duration: 86206.722 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 15:51:23.877 CET [636610] openproject@openproject LOG:  duration: 86689.224 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 16:24:26.418 CET [637188] openproject@openproject LOG:  duration: 11876.497 ms  execute <unnamed>: SELECT SUM(hours) FROM "work_packages" LEFT OUTER JOIN "work_package_hierarchies" ON "work
2023-12-12 16:24:27.173 CET [636915] openproject@openproject LOG:  duration: 12507.602 ms  execute <unnamed>: SELECT SUM(hours) FROM "work_packages" LEFT OUTER JOIN "work_package_hierarchies" ON "work
2023-12-12 16:26:09.304 CET [637187] openproject@openproject LOG:  duration: 10857.630 ms  execute <unnamed>: SELECT SUM(hours) FROM "work_packages" LEFT OUTER JOIN "work_package_hierarchies" ON "work
2023-12-12 16:33:46.209 CET [637364] openproject@openproject LOG:  duration: 65703.127 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 16:33:46.382 CET [637188] openproject@openproject LOG:  duration: 65172.072 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 16:33:47.997 CET [637186] openproject@openproject LOG:  duration: 65846.179 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 16:36:03.687 CET [637011] openproject@openproject LOG:  duration: 65789.720 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 17:01:30.171 CET [637553] openproject@openproject LOG:  duration: 57582.605 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 17:01:30.624 CET [637591] openproject@openproject LOG:  duration: 57552.471 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 17:01:31.776 CET [637583] openproject@openproject LOG:  duration: 59283.643 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 17:07:07.303 CET [637553] openproject@openproject LOG:  duration: 49626.717 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 17:07:07.826 CET [637583] openproject@openproject LOG:  duration: 48339.149 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 17:07:13.666 CET [637803] openproject@openproject LOG:  duration: 48330.151 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 17:53:09.695 CET [638083] openproject@openproject LOG:  duration: 48646.627 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 17:55:51.292 CET [637551] openproject@openproject LOG:  duration: 49974.691 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 17:56:20.350 CET [637572] openproject@openproject LOG:  duration: 52588.996 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 18:06:09.480 CET [638512] openproject@openproject LOG:  duration: 53162.174 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 18:06:15.210 CET [637551] openproject@openproject LOG:  duration: 54838.664 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 18:06:55.082 CET [637572] openproject@openproject LOG:  duration: 72086.757 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 18:10:44.130 CET [637583] openproject@openproject LOG:  duration: 50718.659 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 18:10:44.419 CET [638636] openproject@openproject LOG:  duration: 51242.385 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 18:11:00.021 CET [638666] openproject@openproject LOG:  duration: 46906.870 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 18:11:02.059 CET [638667] openproject@openproject LOG:  duration: 48373.363 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 18:12:07.279 CET [638633] openproject@openproject LOG:  duration: 42438.390 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 18:12:11.846 CET [637583] openproject@openproject LOG:  duration: 39602.256 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 18:12:11.854 CET [638636] openproject@openproject LOG:  duration: 39614.228 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 18:17:08.672 CET [638667] openproject@openproject LOG:  duration: 49847.960 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 18:17:09.719 CET [638518] openproject@openproject LOG:  duration: 50533.563 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 18:17:10.549 CET [638636] openproject@openproject LOG:  duration: 50509.378 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 18:17:11.055 CET [637583] openproject@openproject LOG:  duration: 51363.065 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 18:34:37.241 CET [638892] openproject@openproject LOG:  duration: 50925.911 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 18:34:37.439 CET [638666] openproject@openproject LOG:  duration: 50249.014 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 18:34:37.738 CET [638672] openproject@openproject LOG:  duration: 50152.390 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 18:34:38.263 CET [637583] openproject@openproject LOG:  duration: 50432.236 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 18:39:44.388 CET [638945] openproject@openproject LOG:  duration: 52153.573 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 18:39:47.153 CET [638666] openproject@openproject LOG:  duration: 49301.246 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 18:39:47.792 CET [638920] openproject@openproject LOG:  duration: 48924.048 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 18:41:57.294 CET [639014] openproject@openproject LOG:  duration: 51604.682 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 18:42:13.958 CET [639011] openproject@openproject LOG:  duration: 52912.176 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 18:42:14.146 CET [639010] openproject@openproject LOG:  duration: 52696.295 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 18:42:15.286 CET [639012] openproject@openproject LOG:  duration: 53764.006 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-12 18:42:43.562 CET [639029] openproject@openproject LOG:  duration: 53510.645 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-12 18:43:12.630 CET [639028] openproject@openproject LOG:  duration: 49181.017 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-13 09:11:59.168 CET [647593] openproject@openproject LOG:  duration: 40575.677 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-13 09:12:00.112 CET [648245] openproject@openproject LOG:  duration: 41507.686 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-13 09:12:03.625 CET [648235] openproject@openproject LOG:  duration: 41805.197 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-13 09:12:04.361 CET [646766] openproject@openproject LOG:  duration: 42085.560 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-13 09:12:40.313 CET [648244] openproject@openproject LOG:  duration: 42287.455 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-13 09:12:40.467 CET [648101] openproject@openproject LOG:  duration: 42839.072 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-13 09:12:43.019 CET [648254] openproject@openproject LOG:  duration: 42126.362 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-13 09:12:43.376 CET [647780] openproject@openproject LOG:  duration: 42712.078 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-13 09:12:58.970 CET [648021] openproject@openproject LOG:  duration: 21606.119 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-13 09:13:00.475 CET [648248] openproject@openproject LOG:  duration: 21969.681 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-13 09:13:00.534 CET [648243] openproject@openproject LOG:  duration: 20563.962 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-13 09:13:01.610 CET [648234] openproject@openproject LOG:  duration: 20824.431 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-13 13:43:52.630 CET [650041] openproject@openproject LOG:  duration: 65756.862 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-13 13:43:52.970 CET [651043] openproject@openproject LOG:  duration: 65898.084 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-13 13:43:53.478 CET [651022] openproject@openproject LOG:  duration: 65201.832 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-13 13:43:54.536 CET [650651] openproject@openproject LOG:  duration: 66434.353 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-13 14:03:29.261 CET [651587] openproject@openproject LOG:  duration: 46517.540 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-13 14:03:29.275 CET [651324] openproject@openproject LOG:  duration: 47287.120 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-13 14:03:29.624 CET [651534] openproject@openproject LOG:  duration: 46921.676 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-13 14:33:10.871 CET [651843] openproject@openproject LOG:  duration: 34116.872 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-13 14:33:11.956 CET [651906] openproject@openproject LOG:  duration: 35702.096 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-13 14:33:12.333 CET [651933] openproject@openproject LOG:  duration: 34450.028 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-14 08:59:20.282 CET [663865] openproject@openproject LOG:  duration: 58352.728 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-14 08:59:20.843 CET [664170] openproject@openproject LOG:  duration: 58250.311 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-14 08:59:20.905 CET [664091] openproject@openproject LOG:  duration: 56668.080 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-14 08:59:21.493 CET [664103] openproject@openproject LOG:  duration: 57657.033 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-14 10:16:28.122 CET [665139] openproject@openproject LOG:  duration: 34019.200 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-14 10:16:28.526 CET [665125] openproject@openproject LOG:  duration: 34286.528 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-14 10:16:28.952 CET [665140] openproject@openproject LOG:  duration: 35519.598 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-14 13:10:37.704 CET [666845] openproject@openproject LOG:  duration: 51093.710 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-14 13:10:38.234 CET [666604] openproject@openproject LOG:  duration: 51543.337 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-14 13:10:38.787 CET [667045] openproject@openproject LOG:  duration: 52161.141 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-14 14:06:14.035 CET [667677] openproject@openproject LOG:  duration: 24157.237 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-14 14:06:14.441 CET [667441] openproject@openproject LOG:  duration: 24105.736 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-14 14:06:14.931 CET [667179] openproject@openproject LOG:  duration: 24063.659 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-14 14:26:19.455 CET [667179] openproject@openproject LOG:  duration: 26556.760 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-14 14:26:20.682 CET [667367] openproject@openproject LOG:  duration: 25690.236 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-14 14:26:21.500 CET [667677] openproject@openproject LOG:  duration: 26670.399 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-14 14:30:16.387 CET [667677] openproject@openproject LOG:  duration: 24674.428 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-14 14:30:16.644 CET [667806] openproject@openproject LOG:  duration: 25497.050 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-14 14:30:16.820 CET [667886] openproject@openproject LOG:  duration: 25559.033 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-14 15:34:16.442 CET [668348] openproject@openproject LOG:  duration: 24226.866 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-14 15:34:17.287 CET [668520] openproject@openproject LOG:  duration: 24646.157 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-14 15:34:17.865 CET [668613] openproject@openproject LOG:  duration: 25344.921 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-14 16:24:27.009 CET [669113] openproject@openproject LOG:  duration: 31030.415 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-14 16:24:27.582 CET [669004] openproject@openproject LOG:  duration: 31087.427 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-14 16:24:28.900 CET [669094] openproject@openproject LOG:  duration: 33149.643 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-14 16:30:27.442 CET [668814] openproject@openproject LOG:  duration: 29606.350 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-14 16:30:27.741 CET [669124] openproject@openproject LOG:  duration: 30184.664 ms  execute <unnamed>: SELECT "notifications"."id" AS t0_r0, "notifications"."subject" AS t0_r1, "notifications".
2023-12-14 16:30:28.081 CET [669111] openproject@openproject LOG:  duration: 29524.140 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-15 08:29:19.815 CET [679354] openproject@openproject LOG:  duration: 27762.293 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
2023-12-15 08:29:20.855 CET [679360] openproject@openproject LOG:  duration: 27935.215 ms  execute <unnamed>: SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = $1 AN
```

### First query type that consistenly takes a very long time to execute (I replaced all parameters with their values)

```sql
openproject=# SELECT "notifications".* FROM "notifications" WHERE "notifications"."recipient_id" = '193' AND "notifications"."resource_type" = 'WorkPackage' AND "notifications"."resource_id" IN (SELECT "work_packages"."id" FROM "work_packages" WHERE "work_packages"."project_id" IN (SELECT "projects"."id" FROM "projects" WHERE "projects"."id" IN (( SELECT "projects"."id" FROM "members" INNER JOIN "projects" ON "projects"."active" = TRUE AND "members"."project_id" = "projects"."id" AND "members"."user_id" = 193 INNER JOIN "enabled_modules" ON "projects"."id" = "enabled_modules"."project_id" AND "enabled_modules"."name" IN ('work_package_tracking') AND "projects"."active" = TRUE INNER JOIN "member_roles" ON "member_roles"."member_id" = "members"."id" INNER JOIN "roles" ON "roles"."id" = "member_roles"."role_id" INNER JOIN "member_roles" "member_roles_members" ON "member_roles_members"."member_id" = "members"."id" INNER JOIN "role_permissions" ON "roles"."id" = "role_permissions"."role_id" AND (FALSE OR "role_permissions"."permission" = 'view_work_packages' AND "enabled_modules"."name" = 'work_package_tracking') UNION ALL SELECT "projects"."id" FROM "projects" INNER JOIN "enabled_modules" ON "projects"."id" = "enabled_modules"."project_id" AND "enabled_modules"."name" IN ('work_package_tracking') AND "projects"."active" = TRUE INNER JOIN "roles" ON "roles"."builtin" = 1 AND "projects"."active" AND "projects"."public" AND NOT (EXISTS (SELECT 1 FROM "members" WHERE "members"."project_id" = "projects"."id" AND "members"."user_id" = 193)) INNER JOIN "role_permissions" ON "roles"."id" = "role_permissions"."role_id" AND (FALSE OR "role_permissions"."permission" = 'view_work_packages' AND "enabled_modules"."name" = 'work_package_tracking') )))) AND (notifications.read_ian IN ('f')) AND "notifications"."id" IN (SELECT "notifications"."id" FROM "notifications" WHERE "notifications"."recipient_id" = '193' AND "notifications"."resource_type" = 'WorkPackage' AND "notifications"."resource_id" IN (SELECT "work_packages"."id" FROM "work_packages" WHERE "work_packages"."project_id" IN (SELECT "projects"."id" FROM "projects" WHERE "projects"."id" IN (( SELECT "projects"."id" FROM "members" INNER JOIN "projects" ON "projects"."active" = TRUE AND "members"."project_id" = "projects"."id" AND "members"."user_id" = 193 INNER JOIN "enabled_modules" ON "projects"."id" = "enabled_modules"."project_id" AND "enabled_modules"."name" IN ('work_package_tracking') AND "projects"."active" = TRUE INNER JOIN "member_roles" ON "member_roles"."member_id" = "members"."id" INNER JOIN "roles" ON "roles"."id" = "member_roles"."role_id" INNER JOIN "member_roles" "member_roles_members" ON "member_roles_members"."member_id" = "members"."id" INNER JOIN "role_permissions" ON "roles"."id" = "role_permissions"."role_id" AND (FALSE OR "role_permissions"."permission" = 'view_work_packages' AND "enabled_modules"."name" = 'work_package_tracking') UNION ALL SELECT "projects"."id" FROM "projects" INNER JOIN "enabled_modules" ON "projects"."id" = "enabled_modules"."project_id" AND "enabled_modules"."name" IN ('work_package_tracking') AND "projects"."active" = TRUE INNER JOIN "roles" ON "roles"."builtin" = 1 AND "projects"."active" AND "projects"."public" AND NOT (EXISTS (SELECT 1 FROM "members" WHERE "members"."project_id" = "projects"."id" AND "members"."user_id" = 193)) INNER JOIN "role_permissions" ON "roles"."id" = "role_permissions"."role_id" AND (FALSE OR "role_permissions"."permission" = 'view_work_packages' AND "enabled_modules"."name" = 'work_package_tracking') )))) AND "notifications"."read_ian" IS NOT NULL ORDER BY "notifications"."id" DESC) ORDER BY "notifications"."reason" ASC, "notifications"."id" DESC LIMIT 100 OFFSET 0;
```

## Part of the explain/analyze (I noticed that here we join with the work-packages table which can be quite massive - see the increase 29.026..292.589)

```sql
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Limit  (cost=4794.73..4794.74 rows=1 width=112) (actual time=21032.713..21032.764 rows=100 loops=1)
   ->  Sort  (cost=4794.73..4794.74 rows=1 width=112) (actual time=21032.712..21032.757 rows=100 loops=1)
         Sort Key: notifications.reason, notifications.id DESC
         Sort Method: top-N heapsort  Memory: 48kB
         ->  Nested Loop Semi Join  (cost=2931.79..4794.72 rows=1 width=112) (actual time=299.745..21027.183 rows=6557 loops=1)
               ->  Nested Loop  (cost=2679.29..4222.23 rows=1 width=112) (actual time=296.115..333.585 rows=6557 loops=1)
                     ->  HashAggregate  (cost=2678.86..2680.73 rows=187 width=8) (actual time=296.100..299.779 rows=7503 loops=1)
                           Group Key: notifications_1.id
                           Batches: 1  Memory Usage: 929kB
                           ->  Sort  (cost=2676.06..2676.53 rows=187 width=8) (actual time=293.982..294.467 rows=7503 loops=1)
                                 Sort Key: notifications_1.id DESC
                                 Sort Method: quicksort  Memory: 544kB
                                 ->  Nested Loop  (cost=848.51..2669.00 rows=187 width=8) (actual time=29.026..292.589 rows=7503 loops=1)
                                       ->  HashAggregate  (cost=848.08..856.35 rows=827 width=8) (actual time=28.881..35.746 rows=30745 loops=1)
                                             Group Key: work_packages_1.id
                                             Batches: 1  Memory Usage: 3089kB
                                             ->  Nested Loop  (cost=580.30..846.02 rows=827 width=8) (actual time=8.433..22.183 rows=30745 loops=1)
                                                   ->  HashAggregate  (cost=580.01..580.06 rows=5 width=16) (actual time=8.424..8.461 rows=122 loops=1)
                                                         Group Key: projects_1.id
                                                         Batches: 1  Memory Usage: 48kB
                                                         ->  Merge Semi Join  (cost=568.51..580.00 rows=5 width=16) (actual time=8.319..8.406 rows=122 loops=1)
                                                               Merge Cond: (projects_1.id = projects_2.id)
                                                               ->  Index Only Scan using projects_pkey on projects projects_1  (cost=0.14..11.07 rows=195 width=8) (actual time=0.010..0.051 rows=195 loops=1)
                                                                     Heap Fetches: 126
                                                               ->  Sort  (cost=568.36..568.38 rows=5 width=8) (actual time=8.304..8.321 rows=125 loops=1)
                                                                     Sort Key: projects_2.id
                                                                     Sort Method: quicksort  Memory: 30kB
                                                                     ->  Append  (cost=252.07..568.31 rows=5 width=8) (actual time=0.498..8.282 rows=125 loops=1)
                                                                           ->  Nested Loop  (cost=252.07..449.23 rows=4 width=8) (actual time=0.498..8.155 rows=125 loops=1)
                                                                                 ->  Nested Loop  (cost=251.78..447.87 rows=4 width=24) (actual time=0.489..7.874 rows=123 loops=1)
                                                                                       Join Filter: (members.project_id = projects_2.id)
                                                                                       ->  Nested Loop  (cost=251.64..442.61 rows=5 width=32) (actual time=0.483..7.677 rows=138 loops=1)
                                                                                             ->  Hash Join  (cost=251.49..440.59 rows=5 width=24) (actual time=0.477..7.420 rows=156 loops=1)
                                                                                                   Hash Cond: (member_roles.member_id = members.id)
                                                                                                   ->  Nested Loop  (cost=1.49..187.97 rows=999 width=8) (actual time=0.033..5.479 rows=29260 loops=1)
                                                                                                         ->  Hash Join  (cost=1.20..8.96 rows=1 width=16) (actual time=0.023..0.053 rows=7 loops=1)
                                                                                                               Hash Cond: (role_permissions.role_id = roles.id)
                                                                                                               ->  Seq Scan on role_permissions  (cost=0.00..7.74 rows=7 width=8) (actual time=0.006..0.032 rows=7 loops=1)
                                                                                                                     Filter: ((permission)::text = 'view_work_packages'::text)
                                                                                                                     Rows Removed by Filter: 304
                                                                                                               ->  Hash  (cost=1.09..1.09 rows=9 width=8) (actual time=0.007..0.008 rows=12 loops=1)
                                                                                                                     Buckets: 1024  Batches: 1  Memory Usage: 9kB
                                                                                                                     ->  Seq Scan on roles  (cost=0.00..1.09 rows=9 width=8) (actual time=0.002..0.003 rows=12 loops=1)
                                                                                                         ->  Index Scan using index_member_roles_on_role_id on member_roles  (cost=0.29..147.29 rows=3172 width=16) (actual time=0.005..0.476 rows=4180 loops=7)
                                                                                                               Index Cond: (role_id = roles.id)
                                                                                                   ->  Hash  (cost=248.10..248.10 rows=152 width=16) (actual time=0.216..0.217 rows=161 loops=1)
                                                                                                         Buckets: 1024  Batches: 1  Memory Usage: 16kB
                                                                                                         ->  Bitmap Heap Scan on members  (cost=5.47..248.10 rows=152 width=16) (actual time=0.031..0.193 rows=161 loops=1)
                                                                                                               Recheck Cond: (user_id = 193)
                                                                                                               Heap Blocks: exact=154
                                                                                                               ->  Bitmap Index Scan on index_members_on_user_id_and_project_id  (cost=0.00..5.43 rows=152 width=0) (actual time=0.018..0.018 rows=163 loops=1)
                                                                                                                     Index Cond: (user_id = 193)
                                                                                             ->  Index Scan using enabled_modules_project_id on enabled_modules  (cost=0.15..0.39 rows=1 width=8) (actual time=0.001..0.001 rows=1 loops=156)
                                                                                                   Index Cond: (project_id = members.project_id)
                                                                                                   Filter: ((name)::text = 'work_package_tracking'::text)
                                                                                                   Rows Removed by Filter: 2
:
```
