explain.depesz.com

PostgreSQL's explain analyze made readable

Result: WTns

Settings
# exclusive inclusive rows x rows loops node
1. 636.611 14,648.291 ↓ 20.9 1,001 1

GroupAggregate (cost=1,928.70..1,929.78 rows=48 width=36) (actual time=13,443.499..14,648.291 rows=1,001 loops=1)

  • Group Key: tr.user_id
2.          

CTE _

3. 18.321 133.357 ↓ 162.3 1,461 1

Append (cost=51.81..181.50 rows=9 width=112) (actual time=24.499..133.357 rows=1,461 loops=1)

4.          

CTE last_rates

5. 10.445 19.673 ↑ 66.7 3 1

HashAggregate (cost=35.52..37.52 rows=200 width=40) (actual time=19.648..19.673 rows=3 loops=1)

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

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

7. 20.630 54.659 ↓ 208.1 1,457 1

WindowAgg (cost=14.30..14.45 rows=7 width=80) (actual time=24.483..54.659 rows=1,457 loops=1)

8. 21.714 34.029 ↓ 208.1 1,457 1

Sort (cost=14.30..14.31 rows=7 width=72) (actual time=24.460..34.029 rows=1,457 loops=1)

  • Sort Key: exchange_rates_1.from_currency, exchange_rates_1.ts
  • Sort Method: quicksort Memory: 162kB
9. 12.179 12.315 ↓ 208.1 1,457 1

Bitmap Heap Scan on exchange_rates exchange_rates_1 (cost=4.05..14.20 rows=7 width=72) (actual time=0.160..12.315 rows=1,457 loops=1)

  • Recheck Cond: ((to_currency)::text = 'GBP'::text)
  • Heap Blocks: exact=10
10. 0.136 0.136 ↓ 208.1 1,457 1

Bitmap Index Scan on to_curr_hash (cost=0.00..4.05 rows=7 width=0) (actual time=0.130..0.136 rows=1,457 loops=1)

  • Index Cond: ((to_currency)::text = 'GBP'::text)
11. 0.029 0.048 ↑ 1.0 1 1

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

12. 0.019 0.019 ↑ 1.0 1 1

Result (cost=0.00..0.01 rows=1 width=84) (actual time=0.007..0.019 rows=1 loops=1)

13. 9.625 60.329 ↓ 3.0 3 1

Merge Join (cost=112.84..129.43 rows=1 width=80) (actual time=50.266..60.329 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))
14. 0.060 19.786 ↑ 66.7 3 1

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

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

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

16. 21.167 30.918 ↑ 1.0 1,458 1

Sort (cost=101.20..104.84 rows=1,458 width=72) (actual time=21.497..30.918 rows=1,458 loops=1)

  • Sort Key: er_1.from_currency, er_1.to_currency, er_1.ts
  • Sort Method: quicksort Memory: 162kB
17. 9.751 9.751 ↑ 1.0 1,458 1

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

18. 1,218.908 14,011.680 ↓ 1,800.2 86,412 1

Sort (cost=1,747.20..1,747.32 rows=48 width=68) (actual time=13,442.918..14,011.680 rows=86,412 loops=1)

  • Sort Key: tr.user_id
  • Sort Method: external merge Disk: 1944kB
19. 12,058.638 12,792.772 ↓ 1,800.2 86,412 1

Hash Join (cost=0.21..1,745.86 rows=48 width=68) (actual time=163.758..12,792.772 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: 62950505
20. 570.485 570.485 ↑ 1.0 86,412 1

Seq Scan on transactions tr (cost=0.00..1,415.12 rows=86,412 width=60) (actual time=0.012..570.485 rows=86,412 loops=1)

21. 10.172 163.649 ↓ 1,460.0 1,460 1

Hash (cost=0.20..0.20 rows=1 width=80) (actual time=163.643..163.649 rows=1,460 loops=1)

  • Buckets: 2048 (originally 1024) Batches: 1 (originally 1) Memory Usage: 102kB
22. 153.477 153.477 ↓ 1,460.0 1,460 1

CTE Scan on _ er (cost=0.00..0.20 rows=1 width=80) (actual time=24.521..153.477 rows=1,460 loops=1)

  • Filter: ((to_currency)::text = 'GBP'::text)
  • Rows Removed by Filter: 1
Planning time : 0.429 ms
Execution time : 14,656.255 ms