explain.depesz.com

PostgreSQL's explain analyze made readable

Result: w7h7

Settings
# exclusive inclusive rows x rows loops node
1. 655.186 14,758.456 ↓ 8.9 1,001 1

GroupAggregate (cost=1,474.15..1,476.69 rows=113 width=36) (actual time=13,517.337..14,758.456 rows=1,001 loops=1)

  • Group Key: tr.user_id
2.          

CTE _

3. 19.158 134.170 ↓ 1.8 1,462 1

Append (cost=83.41..188.75 rows=812 width=112) (actual time=23.614..134.170 rows=1,462 loops=1)

4.          

CTE last_rates

5. 10.333 19.827 ↑ 66.7 3 1

HashAggregate (cost=24.18..26.18 rows=200 width=40) (actual time=19.801..19.827 rows=3 loops=1)

  • Group Key: exchange_rates.from_currency, exchange_rates.to_currency
6. 9.494 9.494 ↓ 1.8 1,458 1

Seq Scan on exchange_rates (cost=0.00..18.10 rows=810 width=40) (actual time=0.020..9.494 rows=1,458 loops=1)

7. 21.021 54.553 ↓ 1.8 1,458 1

WindowAgg (cost=57.23..75.46 rows=810 width=80) (actual time=23.599..54.553 rows=1,458 loops=1)

8. 22.555 33.532 ↓ 1.8 1,458 1

Sort (cost=57.23..59.26 rows=810 width=72) (actual time=23.575..33.532 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.977 10.977 ↓ 1.8 1,458 1

Seq Scan on exchange_rates exchange_rates_1 (cost=0.00..18.10 rows=810 width=72) (actual time=0.014..10.977 rows=1,458 loops=1)

10. 0.053 0.073 ↑ 1.0 1 1

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

11. 0.020 0.020 ↑ 1.0 1 1

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

12. 9.902 60.386 ↓ 3.0 3 1

Merge Join (cost=68.87..78.98 rows=1 width=80) (actual time=50.763..60.386 rows=3 loops=1)

  • Merge Cond: (((lr.from_currency)::text = (er_1.from_currency)::text) AND ((lr.to_currency)::text = (er_1.to_currency)::text) AND (lr.ts = er_1.ts))
13. 0.069 19.950 ↑ 66.7 3 1

Sort (cost=11.64..12.14 rows=200 width=40) (actual time=19.925..19.950 rows=3 loops=1)

  • Sort Key: lr.from_currency, lr.to_currency, lr.ts
  • Sort Method: quicksort Memory: 25kB
14. 19.881 19.881 ↑ 66.7 3 1

CTE Scan on last_rates lr (cost=0.00..4.00 rows=200 width=40) (actual time=19.816..19.881 rows=3 loops=1)

15. 20.807 30.534 ↓ 1.8 1,458 1

Sort (cost=57.23..59.26 rows=810 width=72) (actual time=21.506..30.534 rows=1,458 loops=1)

  • Sort Key: er_1.from_currency, er_1.to_currency, er_1.ts
  • Sort Method: quicksort Memory: 162kB
16. 9.727 9.727 ↓ 1.8 1,458 1

Seq Scan on exchange_rates er_1 (cost=0.00..18.10 rows=810 width=72) (actual time=0.013..9.727 rows=1,458 loops=1)

17. 1,237.940 14,103.270 ↓ 764.7 86,412 1

Sort (cost=1,285.40..1,285.68 rows=113 width=68) (actual time=13,516.913..14,103.270 rows=86,412 loops=1)

  • Sort Key: tr.user_id
  • Sort Method: external merge Disk: 1944kB
18. 12,129.096 12,865.330 ↓ 764.7 86,412 1

Hash Join (cost=18.32..1,281.55 rows=113 width=68) (actual time=165.354..12,865.330 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: 62964370
19. 570.997 570.997 ↓ 1.7 86,412 1

Seq Scan on transactions tr (cost=0.00..1,057.92 rows=50,692 width=60) (actual time=0.017..570.997 rows=86,412 loops=1)

20. 10.280 165.237 ↓ 365.0 1,460 1

Hash (cost=18.27..18.27 rows=4 width=80) (actual time=165.232..165.237 rows=1,460 loops=1)

  • Buckets: 2048 (originally 1024) Batches: 1 (originally 1) Memory Usage: 102kB
21. 154.957 154.957 ↓ 365.0 1,460 1

CTE Scan on _ er (cost=0.00..18.27 rows=4 width=80) (actual time=23.637..154.957 rows=1,460 loops=1)

  • Filter: ((to_currency)::text = 'GBP'::text)
  • Rows Removed by Filter: 2
Planning time : 0.258 ms
Execution time : 14,766.890 ms