explain.depesz.com

PostgreSQL's explain analyze made readable

Result: hGlg

Settings
# exclusive inclusive rows x rows loops node
1. 0.009 2.073 ↑ 1.0 50 1

Limit (cost=123.02..128.55 rows=50 width=133) (actual time=2.002..2.073 rows=50 loops=1)

2. 0.013 2.064 ↑ 2.6 50 1

Nested Loop Left Join (cost=123.02..137.18 rows=128 width=133) (actual time=2.001..2.064 rows=50 loops=1)

  • Join Filter: ((patient.patient_id)::text = (inspection_rank.patient_id)::text)
  • Rows Removed by Join Filter: 50
3. 0.044 2.001 ↑ 2.6 50 1

Merge Join (cost=107.39..110.09 rows=128 width=107) (actual time=1.955..2.001 rows=50 loops=1)

  • Merge Cond: ((patient.patient_id)::text = (patient_with_users.patient_id)::text)
4. 0.229 1.035 ↑ 2.6 50 1

Sort (cost=32.09..32.41 rows=128 width=75) (actual time=1.032..1.035 rows=50 loops=1)

  • Sort Key: patient.patient_id DESC
  • Sort Method: quicksort Memory: 39kB
5. 0.639 0.806 ↑ 1.5 83 1

Hash Left Join (cost=18.93..27.61 rows=128 width=75) (actual time=0.754..0.806 rows=83 loops=1)

  • Hash Cond: ((patient.organization_id)::text = (organization.organization_id)::text)
6. 0.044 0.044 ↑ 1.5 83 1

Seq Scan on patients patient (cost=0.00..8.34 rows=128 width=70) (actual time=0.008..0.044 rows=83 loops=1)

  • Filter: ((NOT is_deleted) AND (created_at <= now()))
  • Rows Removed by Filter: 17
7. 0.059 0.123 ↓ 1.0 399 1

Hash (cost=13.97..13.97 rows=397 width=20) (actual time=0.123..0.123 rows=399 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 29kB
8. 0.064 0.064 ↓ 1.0 399 1

Seq Scan on organizations organization (cost=0.00..13.97 rows=397 width=20) (actual time=0.008..0.064 rows=399 loops=1)

9. 0.236 0.922 ↑ 2.4 65 1

Sort (cost=75.31..75.70 rows=156 width=42) (actual time=0.919..0.922 rows=65 loops=1)

  • Sort Key: patient_with_users.patient_id DESC
  • Sort Method: quicksort Memory: 36kB
10. 0.009 0.686 ↑ 1.6 100 1

Subquery Scan on patient_with_users (cost=65.72..69.62 rows=156 width=42) (actual time=0.619..0.686 rows=100 loops=1)

11. 0.147 0.677 ↑ 1.6 100 1

HashAggregate (cost=65.72..68.06 rows=156 width=42) (actual time=0.618..0.677 rows=100 loops=1)

  • Group Key: p.patient_id
12. 0.047 0.530 ↓ 1.1 191 1

Hash Right Join (cost=58.42..62.80 rows=167 width=34) (actual time=0.479..0.530 rows=191 loops=1)

  • Hash Cond: ((uxp.patient_id)::text = (p.patient_id)::text)
13. 0.131 0.458 ↓ 1.1 191 1

Sort (cost=48.91..49.32 rows=167 width=66) (actual time=0.450..0.458 rows=191 loops=1)

  • Sort Key: ((((u.last_name)::text || ' '::text) || (u.first_name)::text)) DESC
  • Sort Method: quicksort Memory: 46kB
14. 0.056 0.327 ↓ 1.1 191 1

Hash Left Join (cost=37.80..42.74 rows=167 width=66) (actual time=0.253..0.327 rows=191 loops=1)

  • Hash Cond: ((uxp.user_id)::text = (u.user_id)::text)
15. 0.027 0.027 ↓ 1.1 191 1

Seq Scan on user_x_patients uxp (cost=0.00..3.67 rows=167 width=18) (actual time=0.004..0.027 rows=191 loops=1)

  • Filter: (NOT is_deleted)
16. 0.122 0.244 ↓ 1.0 803 1

Hash (cost=27.91..27.91 rows=791 width=24) (actual time=0.244..0.244 rows=803 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 53kB
17. 0.122 0.122 ↓ 1.0 803 1

Seq Scan on users u (cost=0.00..27.91 rows=791 width=24) (actual time=0.004..0.122 rows=803 loops=1)

18. 0.012 0.025 ↑ 1.6 100 1

Hash (cost=7.56..7.56 rows=156 width=10) (actual time=0.025..0.025 rows=100 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 13kB
19. 0.013 0.013 ↑ 1.6 100 1

Seq Scan on patients p (cost=0.00..7.56 rows=156 width=10) (actual time=0.002..0.013 rows=100 loops=1)

20. 0.007 0.050 ↑ 1.0 1 50

Materialize (cost=15.62..25.17 rows=1 width=74) (actual time=0.001..0.001 rows=1 loops=50)

21. 0.001 0.043 ↑ 1.0 1 1

Nested Loop (cost=15.62..25.17 rows=1 width=74) (actual time=0.025..0.043 rows=1 loops=1)

22. 0.002 0.025 ↑ 1.0 1 1

Subquery Scan on inspection_rank (cost=15.62..19.56 rows=1 width=66) (actual time=0.019..0.025 rows=1 loops=1)

  • Filter: ((inspection_rank.rank = 1) AND (inspection_rank.status = 1))
  • Rows Removed by Filter: 4
23. 0.010 0.023 ↑ 21.0 5 1

WindowAgg (cost=15.62..17.99 rows=105 width=82) (actual time=0.018..0.023 rows=5 loops=1)

24. 0.007 0.013 ↑ 21.0 5 1

Sort (cost=15.62..15.89 rows=105 width=74) (actual time=0.013..0.013 rows=5 loops=1)

  • Sort Key: inspections.patient_id, inspections.end_date DESC, inspections.created_at DESC
  • Sort Method: quicksort Memory: 25kB
25. 0.006 0.006 ↑ 21.0 5 1

Seq Scan on inspections (cost=0.00..12.10 rows=105 width=74) (actual time=0.005..0.006 rows=5 loops=1)

  • Filter: (NOT is_deleted)
26. 0.017 0.017 ↑ 1.0 1 1

Seq Scan on code_masters (cost=0.00..5.59 rows=1 width=12) (actual time=0.005..0.017 rows=1 loops=1)

  • Filter: ((code_value = 1) AND ((code_id)::text = 'D-C-3-1'::text))
  • Rows Removed by Filter: 172