explain.depesz.com

PostgreSQL's explain analyze made readable

Result: ZR28

Settings
# exclusive inclusive rows x rows loops node
1. 0.019 969.385 ↑ 1.0 45 1

Limit (cost=136,337.25..136,337.37 rows=45 width=286) (actual time=969.352..969.385 rows=45 loops=1)

2. 36.328 969.366 ↑ 592.4 45 1

Sort (cost=136,337.25..136,403.90 rows=26,658 width=286) (actual time=969.352..969.366 rows=45 loops=1)

  • Sort Key: last_event_subquery.last_event_date DESC NULLS LAST, companies.id
  • Sort Method: top-N heapsort Memory: 36kB
3. 50.309 933.038 ↓ 3.4 89,515 1

Hash Left Join (cost=49,452.93..135,471.96 rows=26,658 width=286) (actual time=106.821..933.038 rows=89,515 loops=1)

  • Hash Cond: (companies.id = last_event_subquery.distinct_col)
4. 313.842 834.417 ↓ 3.4 89,515 1

Hash Join (cost=15,846.74..101,765.78 rows=26,658 width=274) (actual time=58.495..834.417 rows=89,515 loops=1)

  • Hash Cond: (companies.id = organizations_relevant_companies.company_id)
5. 462.775 463.240 ↓ 2.0 889,922 1

Seq Scan on companies (cost=52.05..84,059.40 rows=438,695 width=274) (actual time=0.832..463.240 rows=889,922 loops=1)

  • Filter: (((organization_id IS NULL) OR (organization_id = 7)) AND (NOT (hashed SubPlan 1)))
  • Rows Removed by Filter: 636369
6.          

SubPlan (forSeq Scan)

7. 0.465 0.465 ↑ 1.0 1,032 1

Seq Scan on hidden_globals (cost=0.00..49.48 rows=1,032 width=4) (actual time=0.006..0.465 rows=1,032 loops=1)

  • Filter: (organization_id = 7)
  • Rows Removed by Filter: 1566
8. 26.626 57.335 ↑ 1.0 89,595 1

Hash (cost=14,635.36..14,635.36 rows=92,746 width=4) (actual time=57.335..57.335 rows=89,595 loops=1)

  • Buckets: 131072 Batches: 1 Memory Usage: 4174kB
9. 30.709 30.709 ↑ 1.0 89,595 1

Index Only Scan using organizations_relevant_companies_organization_id_company_id_idx on organizations_relevant_companies (cost=0.43..14,635.36 rows=92,746 width=4) (actual time=0.017..30.709 rows=89,595 loops=1)

  • Index Cond: (organization_id = 7)
  • Heap Fetches: 89595
10. 1.221 48.312 ↓ 32.4 3,626 1

Hash (cost=33,604.79..33,604.79 rows=112 width=16) (actual time=48.312..48.312 rows=3,626 loops=1)

  • Buckets: 4096 (originally 1024) Batches: 1 (originally 1) Memory Usage: 217kB
11. 1.495 47.091 ↓ 32.4 3,626 1

Subquery Scan on last_event_subquery (cost=33,603.11..33,604.79 rows=112 width=16) (actual time=41.248..47.091 rows=3,626 loops=1)

12. 2.542 45.596 ↓ 32.4 3,626 1

Unique (cost=33,603.11..33,603.67 rows=112 width=16) (actual time=41.247..45.596 rows=3,626 loops=1)

13. 6.038 43.054 ↓ 69.9 7,831 1

Sort (cost=33,603.11..33,603.39 rows=112 width=16) (actual time=41.245..43.054 rows=7,831 loops=1)

  • Sort Key: companies_persons.company_id, person_smart_attributes.last_event_date DESC NULLS LAST
  • Sort Method: quicksort Memory: 560kB
14. 8.942 37.016 ↓ 69.9 7,831 1

Nested Loop (cost=0.73..33,599.30 rows=112 width=16) (actual time=0.030..37.016 rows=7,831 loops=1)

15. 3.249 3.249 ↓ 1.0 8,275 1

Index Scan using person_smart_attributes_temp_organization_id_person_id_idx on person_smart_attributes (cost=0.29..676.54 rows=8,221 width=16) (actual time=0.015..3.249 rows=8,275 loops=1)

  • Index Cond: (organization_id = 7)
16. 24.825 24.825 ↑ 1.0 1 8,275

Index Scan using companies_persons_person_id_index on companies_persons (cost=0.43..3.99 rows=1 width=8) (actual time=0.003..0.003 rows=1 loops=8,275)

  • Index Cond: (person_id = person_smart_attributes.person_id)
  • Filter: (organization_id = 7)