explain.depesz.com

PostgreSQL's explain analyze made readable

Result: VQxF

Settings
# exclusive inclusive rows x rows loops node
1. 0.144 30,830.462 ↑ 1.0 15 1

Limit (cost=42,078.20..42,078.39 rows=15 width=2,212) (actual time=30,830.304..30,830.462 rows=15 loops=1)

2. 0.016 30,830.318 ↑ 48.9 15 1

Group (cost=42,078.20..42,087.36 rows=733 width=2,212) (actual time=30,830.302..30,830.318 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.090 30,830.302 ↑ 48.9 15 1

Sort (cost=42,078.20..42,080.03 rows=733 width=2,211) (actual time=30,830.298..30,830.302 rows=15 loops=1)

  • 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: 36kB
4. 330.988 30,830.212 ↑ 8.6 85 1

Hash Join (cost=21,541.67..42,043.32 rows=733 width=2,211) (actual time=30,807.135..30,830.212 rows=85 loops=1)

  • Hash Cond: (transactions_sub_payments.payment_id = transactions_payments.id)
5. 1,051.763 29,648.530 ↓ 4.9 723,324 1

Nested Loop (cost=1,001.28..21,116.43 rows=146,540 width=2,207) (actual time=9.870..29,648.530 rows=723,324 loops=1)

6. 13,672.336 25,730.979 ↓ 26,535.1 716,447 1

Nested Loop Left Join (cost=1,000.85..16,766.60 rows=27 width=2,207) (actual time=6.449..25,730.979 rows=716,447 loops=1)

  • Join Filter: (insurance_claims.invoice_id = transactions_invoices.id)
  • Rows Removed by Join Filter: 45135720
7. 0.000 595.587 ↓ 26,534.9 716,441 1

Gather (cost=1,000.85..16,738.30 rows=27 width=2,203) (actual time=6.370..595.587 rows=716,441 loops=1)

  • Workers Planned: 2
  • Workers Launched: 2
8. 1,093.282 2,301.917 ↓ 21,710.4 238,814 3

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

9. 1,066.917 1,208.631 ↓ 21,710.4 238,814 3

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

10. 141.710 141.710 ↓ 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.455..141.710 rows=238,814 loops=3)

  • Filter: (payment_receiver_id = 1)
11. 0.004 0.004 ↑ 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.004..0.004 rows=1 loops=716,441)

  • Index Cond: ((owner_id = transactions_invoices.id) AND (owner_type = 'Transactions::Invoice'::text))
  • Heap Fetches: 0
12. 0.004 0.004 ↑ 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.004..0.004 rows=1 loops=716,441)

  • Index Cond: (id = transactions_invoices.customer_id)
  • Heap Fetches: 0
13. 11,463.027 11,463.056 ↑ 1.0 63 716,441

Materialize (cost=0.00..2.94 rows=63 width=8) (actual time=0.000..0.016 rows=63 loops=716,441)

14. 0.029 0.029 ↑ 1.0 63 1

Seq Scan on insurance_claims (cost=0.00..2.63 rows=63 width=8) (actual time=0.006..0.029 rows=63 loops=1)

15. 2,865.788 2,865.788 ↑ 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.004..0.004 rows=1 loops=716,447)

  • Index Cond: (invoice_id = transactions_invoice_sequences.owner_id)
16. 0.047 850.694 ↑ 24.9 218 1

Hash (cost=20,472.65..20,472.65 rows=5,419 width=12) (actual time=850.693..850.694 rows=218 loops=1)

  • Buckets: 8192 Batches: 1 Memory Usage: 74kB
17. 5.778 850.647 ↑ 24.9 218 1

Gather (cost=1,000.00..20,472.65 rows=5,419 width=12) (actual time=2.855..850.647 rows=218 loops=1)

  • Workers Planned: 2
  • Workers Launched: 2
18. 844.869 844.869 ↑ 30.9 73 3

Parallel Seq Scan on transactions_payments (cost=0.00..18,930.75 rows=2,258 width=12) (actual time=364.253..844.869 rows=73 loops=3)

  • Filter: ((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))
  • Rows Removed by Filter: 361196