explain.depesz.com

PostgreSQL's explain analyze made readable

Result: lrAW

Settings
# exclusive inclusive rows x rows loops node
1. 6.124 8,931.244 ↑ 1.0 15 1

Limit (cost=28,548.27..28,549.92 rows=15 width=2,212) (actual time=8,925.101..8,931.244 rows=15 loops=1)

2. 0.000 8,925.120 ↑ 48.9 15 1

Group (cost=28,548.27..28,628.90 rows=733 width=2,212) (actual time=8,925.099..8,925.120 rows=15 loops=1)

  • Group Key: (CASE WHEN ((transactions_invoices.type)::text = 'Transactions::MonthlyInvoice'::text) THEN transactions_invoices.created_at ELSE transactions_payments.created_at END), transactions_invoices.id, insurance_claims.id
3. 0.000 8,931.206 ↑ 40.7 15 1

Gather Merge (cost=28,548.27..28,622.49 rows=610 width=2,211) (actual time=8,925.095..8,931.206 rows=15 loops=1)

  • Workers Planned: 2
  • Workers Launched: 2
4. 0.060 26,732.562 ↑ 10.9 28 3

Group (cost=27,548.25..27,552.06 rows=305 width=2,211) (actual time=8,910.830..8,910.854 rows=28 loops=3)

  • Group Key: (CASE WHEN ((transactions_invoices.type)::text = 'Transactions::MonthlyInvoice'::text) THEN transactions_invoices.created_at ELSE transactions_payments.created_at END), transactions_invoices.id, insurance_claims.id
5. 0.138 26,732.502 ↑ 10.9 28 3

Sort (cost=27,548.25..27,549.01 rows=305 width=2,211) (actual time=8,910.828..8,910.834 rows=28 loops=3)

  • Sort Key: (CASE WHEN ((transactions_invoices.type)::text = 'Transactions::MonthlyInvoice'::text) THEN transactions_invoices.created_at ELSE transactions_payments.created_at END) DESC, transactions_invoices.id, insurance_claims.id
  • Sort Method: quicksort Memory: 25kB
6. 855.438 26,732.364 ↑ 10.9 28 3

Hash Join (cost=25,602.52..27,535.66 rows=305 width=2,211) (actual time=8,910.653..8,910.788 rows=28 loops=3)

  • Hash Cond: (transactions_sub_payments.payment_id = transactions_payments.id)
7. 2,607.819 25,876.392 ↓ 3.9 241,108 3

Nested Loop (cost=15,740.73..17,512.83 rows=61,058 width=2,207) (actual time=5,515.640..8,625.464 rows=241,108 loops=3)

8. 1,598.175 18,969.891 ↓ 21,710.5 238,816 3

Merge Left Join (cost=15,740.30..15,740.68 rows=11 width=2,207) (actual time=5,515.620..6,323.297 rows=238,816 loops=3)

  • Merge Cond: (transactions_invoices.id = insurance_claims.invoice_id)
9. 3,189.042 17,371.461 ↓ 21,710.4 238,814 3

Sort (cost=15,735.79..15,735.81 rows=11 width=2,203) (actual time=5,515.539..5,790.487 rows=238,814 loops=3)

  • Sort Key: transactions_invoices.id
  • Sort Method: external merge Disk: 25352kB
10. 2,156.259 14,182.419 ↓ 21,710.4 238,814 3

Nested Loop (cost=0.85..15,735.60 rows=11 width=2,203) (actual time=0.040..4,727.473 rows=238,814 loops=3)

11. 1,631.395 7,727.514 ↓ 21,710.4 238,814 3

Nested Loop (cost=0.43..15,715.84 rows=11 width=2,203) (actual time=0.025..2,575.838 rows=238,814 loops=3)

12. 1,081.032 1,081.032 ↓ 160.1 238,814 3

Parallel Seq Scan on transactions_invoices (cost=0.00..14,888.46 rows=1,492 width=2,199) (actual time=0.004..360.344 rows=238,814 loops=3)

  • Filter: (payment_receiver_id = 1)
13. 5,015.087 5,015.087 ↑ 27.0 1 716,441

Index Only Scan using index_tis_on_owner_id_and_owner_type on transactions_invoice_sequences (cost=0.43..3.86 rows=27 width=4) (actual time=0.007..0.007 rows=1 loops=716,441)

  • Index Cond: ((owner_id = transactions_invoices.id) AND (owner_type = 'Transactions::Invoice'::text))
  • Heap Fetches: 0
14. 4,298.646 4,298.646 ↑ 1.0 1 716,441

Index Only Scan using customers_pkey on customers (cost=0.42..1.80 rows=1 width=4) (actual time=0.006..0.006 rows=1 loops=716,441)

  • Index Cond: (id = transactions_invoices.customer_id)
  • Heap Fetches: 0
15. 0.129 0.255 ↑ 2.0 32 3

Sort (cost=4.51..4.67 rows=63 width=8) (actual time=0.075..0.085 rows=32 loops=3)

  • Sort Key: insurance_claims.invoice_id
  • Sort Method: quicksort Memory: 27kB
16. 0.126 0.126 ↑ 1.0 63 3

Seq Scan on insurance_claims (cost=0.00..2.63 rows=63 width=8) (actual time=0.020..0.042 rows=63 loops=3)

17. 4,298.682 4,298.682 ↑ 5,427.0 1 716,447

Index Scan using index_transactions_sub_payments_on_invoice_id on transactions_sub_payments (cost=0.43..106.83 rows=5,427 width=8) (actual time=0.005..0.006 rows=1 loops=716,447)

  • Index Cond: (invoice_id = transactions_invoice_sequences.owner_id)
18. 0.216 0.534 ↑ 24.9 218 3

Hash (cost=9,794.05..9,794.05 rows=5,419 width=12) (actual time=0.178..0.178 rows=218 loops=3)

  • Buckets: 8192 Batches: 1 Memory Usage: 74kB
19. 0.258 0.318 ↑ 24.9 218 3

Bitmap Heap Scan on transactions_payments (cost=12.77..9,794.05 rows=5,419 width=12) (actual time=0.026..0.106 rows=218 loops=3)

  • Recheck Cond: ((created_at >= '2019-03-30 22:00:00'::timestamp without time zone) AND (created_at <= '2019-10-25 21:59:59.999999'::timestamp without time zone))
  • Heap Blocks: exact=14
20. 0.060 0.060 ↑ 24.9 218 3

Bitmap Index Scan on payment_idx (cost=0.00..11.42 rows=5,419 width=0) (actual time=0.020..0.020 rows=218 loops=3)

  • Index Cond: ((created_at >= '2019-03-30 22:00:00'::timestamp without time zone) AND (created_at <= '2019-10-25 21:59:59.999999'::timestamp without time zone))
Planning time : 2.096 ms
Execution time : 8,934.690 ms