explain.depesz.com

PostgreSQL's explain analyze made readable

Result: XP4m

Settings
# exclusive inclusive rows x rows loops node
1. 700.464 13,487.856 ↑ 1.0 1,001 1

HashAggregate (cost=2,690.86..2,703.38 rows=1,001 width=36) (actual time=13,481.209..13,487.856 rows=1,001 loops=1)

  • Group Key: tr.user_id
2.          

CTE _

3. 19.112 114.657 ↓ 1.0 1,462 1

Append (cost=136.75..225.31 rows=1,460 width=112) (actual time=23.350..114.657 rows=1,462 loops=1)

4.          

CTE last_rates

5. 10.546 20.249 ↑ 1.3 3 1

HashAggregate (cost=35.52..35.55 rows=4 width=16) (actual time=20.224..20.249 rows=3 loops=1)

  • Group Key: exchange_rates.from_currency, exchange_rates.to_currency
6. 9.703 9.703 ↑ 1.0 1,458 1

Seq Scan on exchange_rates (cost=0.00..24.58 rows=1,458 width=16) (actual time=0.010..9.703 rows=1,458 loops=1)

7. 21.766 54.947 ↑ 1.0 1,458 1

WindowAgg (cost=101.20..134.00 rows=1,458 width=28) (actual time=23.335..54.947 rows=1,458 loops=1)

8. 22.363 33.181 ↑ 1.0 1,458 1

Sort (cost=101.20..104.84 rows=1,458 width=20) (actual time=23.312..33.181 rows=1,458 loops=1)

  • Sort Key: exchange_rates_1.from_currency, exchange_rates_1.to_currency, exchange_rates_1.ts
  • Sort Method: quicksort Memory: 162kB
9. 10.818 10.818 ↑ 1.0 1,458 1

Seq Scan on exchange_rates exchange_rates_1 (cost=0.00..24.58 rows=1,458 width=20) (actual time=0.012..10.818 rows=1,458 loops=1)

10. 0.030 0.051 ↑ 1.0 1 1

Subquery Scan on *SELECT* 2 (cost=0.00..0.02 rows=1 width=112) (actual time=0.027..0.051 rows=1 loops=1)

11. 0.021 0.021 ↑ 1.0 1 1

Result (cost=0.00..0.01 rows=1 width=84) (actual time=0.008..0.021 rows=1 loops=1)

12. 10.365 40.547 ↓ 3.0 3 1

Hash Join (cost=0.15..41.14 rows=1 width=28) (actual time=20.613..40.547 rows=3 loops=1)

  • Hash Cond: (((er_1.from_currency)::text = (lr.from_currency)::text) AND ((er_1.to_currency)::text = (lr.to_currency)::text) AND (er_1.ts = lr.ts))
13. 9.830 9.830 ↑ 1.0 1,458 1

Seq Scan on exchange_rates er_1 (cost=0.00..24.58 rows=1,458 width=20) (actual time=0.022..9.830 rows=1,458 loops=1)

14. 0.051 20.352 ↑ 1.3 3 1

Hash (cost=0.08..0.08 rows=4 width=40) (actual time=20.346..20.352 rows=3 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
15. 20.301 20.301 ↑ 1.3 3 1

CTE Scan on last_rates lr (cost=0.00..0.08 rows=4 width=40) (actual time=20.239..20.301 rows=3 loops=1)

16. 12,071.979 12,787.392 ↑ 1.0 86,412 1

Hash Left Join (cost=32.94..1,817.46 rows=86,412 width=40) (actual time=146.625..12,787.392 rows=86,412 loops=1)

  • Hash Cond: ((tr.currency)::text = (er.from_currency)::text)
  • Join Filter: ((tr.ts >= er.start_ts) AND (tr.ts < er.end_ts))
  • Rows Removed by Join Filter: 62947342
17. 568.971 568.971 ↑ 1.0 86,412 1

Seq Scan on transactions tr (cost=0.00..1,415.12 rows=86,412 width=20) (actual time=0.016..568.971 rows=86,412 loops=1)

18. 10.711 146.442 ↓ 208.6 1,460 1

Hash (cost=32.85..32.85 rows=7 width=80) (actual time=146.436..146.442 rows=1,460 loops=1)

  • Buckets: 2048 (originally 1024) Batches: 1 (originally 1) Memory Usage: 102kB
19. 135.731 135.731 ↓ 208.6 1,460 1

CTE Scan on _ er (cost=0.00..32.85 rows=7 width=80) (actual time=23.374..135.731 rows=1,460 loops=1)

  • Filter: ((to_currency)::text = 'GBP'::text)
  • Rows Removed by Filter: 2
Planning time : 0.352 ms
Execution time : 13,494.354 ms