explain.depesz.com

PostgreSQL's explain analyze made readable

Result: lHRp

Settings
# exclusive inclusive rows x rows loops node
1. 0.149 2,530.440 ↓ 67.0 67 1

Sort (cost=860,884.58..860,884.59 rows=1 width=148) (actual time=2,530.434..2,530.440 rows=67 loops=1)

  • Sort Key: (to_char(date_trunc('MONTH'::text, co1.operation_date), 'YYYY, MONTH'::text)), ((SubPlan 2)), ((SubPlan 3)), ((SubPlan 4)), (avg((date_part('epoch'::text, (co2.operation_date - co1.operation_date)) / '3600'::double precision)))
  • Sort Method: quicksort Memory: 34kB
2.          

CTE container_operations

3. 68.099 1,355.199 ↓ 223.7 451,478 1

Subquery Scan on t (cost=846,635.30..860,760.15 rows=2,018 width=42) (actual time=928.674..1,355.199 rows=451,478 loops=1)

  • Filter: (t.rn = 1)
  • Rows Removed by Filter: 93,355
4. 280.417 1,287.100 ↓ 1.4 544,833 1

WindowAgg (cost=846,635.30..855,715.56 rows=403,567 width=50) (actual time=928.663..1,287.100 rows=544,833 loops=1)

5. 472.677 1,006.683 ↓ 1.4 544,833 1

Sort (cost=846,635.30..847,644.22 rows=403,567 width=42) (actual time=928.647..1,006.683 rows=544,833 loops=1)

  • Sort Key: container_operation.container_id, container_operation.operation_type, container_operation.operation_date
  • Sort Method: external merge Disk: 26,168kB
6. 401.398 534.006 ↓ 1.4 544,833 1

Bitmap Heap Scan on container_operation (cost=38,432.17..809,058.27 rows=403,567 width=42) (actual time=142.050..534.006 rows=544,833 loops=1)

  • Recheck Cond: ((operation_date >= '2019-02-01 00:00:00+03'::timestamp with time zone) AND (operation_date <= '2019-02-15 00:00:00+03'::timestamp with time zone))
  • Filter: (operation_type = ANY ('{CONTAINER_SORTING,CONTAINER_IS_SENT,CONTAINER_IS_SENT_INSIDE_CONTAINER}'::text[]))
  • Rows Removed by Filter: 1,222,610
  • Heap Blocks: exact=51,267
7. 132.608 132.608 ↑ 1.0 1,767,462 1

Bitmap Index Scan on idx_container_operation_operation_date (cost=0.00..38,331.28 rows=1,768,272 width=0) (actual time=132.608..132.608 rows=1,767,462 loops=1)

  • Index Cond: ((operation_date >= '2019-02-01 00:00:00+03'::timestamp with time zone) AND (operation_date <= '2019-02-15 00:00:00+03'::timestamp with time zone))
8. 71.816 2,530.291 ↓ 67.0 67 1

GroupAggregate (cost=99.50..124.43 rows=1 width=148) (actual time=2,435.073..2,530.291 rows=67 loops=1)

  • Group Key: (to_char(date_trunc('MONTH'::text, co1.operation_date), 'YYYY, MONTH'::text)), sc.container_type_id, sc.container_category_id, sc.class_id
9. 120.382 2,458.140 ↓ 177,103.0 177,103 1

Sort (cost=99.50..99.50 rows=1 width=60) (actual time=2,434.847..2,458.140 rows=177,103 loops=1)

  • Sort Key: (to_char(date_trunc('MONTH'::text, co1.operation_date), 'YYYY, MONTH'::text)), sc.container_type_id, sc.container_category_id, sc.class_id
  • Sort Method: quicksort Memory: 19,981kB
10. 217.926 2,337.758 ↓ 177,103.0 177,103 1

Nested Loop (cost=45.96..99.49 rows=1 width=60) (actual time=1,549.912..2,337.758 rows=177,103 loops=1)

11. 106.203 1,765.626 ↓ 177,103.0 177,103 1

Hash Join (cost=45.53..91.02 rows=1 width=32) (actual time=1,549.863..1,765.626 rows=177,103 loops=1)

  • Hash Cond: (co2.container_id = co1.container_id)
  • Join Filter: (co1.operation_date < co2.operation_date)
  • Rows Removed by Join Filter: 7
12. 1,038.283 1,038.283 ↓ 9,881.9 197,638 1

CTE Scan on container_operations co2 (cost=0.00..45.41 rows=20 width=16) (actual time=928.683..1,038.283 rows=197,638 loops=1)

  • Filter: (operation_type = ANY ('{CONTAINER_IS_SENT,CONTAINER_IS_SENT_INSIDE_CONTAINER}'::text[]))
  • Rows Removed by Filter: 253,840
13. 39.208 621.140 ↓ 25,384.0 253,840 1

Hash (cost=45.41..45.41 rows=10 width=16) (actual time=621.140..621.140 rows=253,840 loops=1)

  • Buckets: 262,144 (originally 1024) Batches: 1 (originally 1) Memory Usage: 13,947kB
14. 581.932 581.932 ↓ 25,384.0 253,840 1

CTE Scan on container_operations co1 (cost=0.00..45.41 rows=10 width=16) (actual time=0.016..581.932 rows=253,840 loops=1)

  • Filter: (operation_type = 'CONTAINER_SORTING'::text)
  • Rows Removed by Filter: 197,638
15. 354.206 354.206 ↑ 1.0 1 177,103

Index Scan using session_container_pkey on session_container sc (cost=0.43..8.45 rows=1 width=20) (actual time=0.002..0.002 rows=1 loops=177,103)

  • Index Cond: (id = co1.container_id)
16.          

SubPlan (for GroupAggregate)

17. 0.201 0.201 ↑ 1.0 1 67

Index Scan using pk_dict on dict (cost=0.28..8.29 rows=1 width=31) (actual time=0.003..0.003 rows=1 loops=67)

  • Index Cond: ((dict_class_id = 2) AND (code = sc.container_type_id))
18. 0.067 0.067 ↑ 1.0 1 67

Index Scan using pk_dict on dict dict_1 (cost=0.28..8.29 rows=1 width=31) (actual time=0.001..0.001 rows=1 loops=67)

  • Index Cond: ((dict_class_id = 3) AND (code = sc.container_category_id))
19. 0.067 0.067 ↑ 1.0 1 67

Index Scan using pk_dict on dict dict_2 (cost=0.28..8.29 rows=1 width=31) (actual time=0.001..0.001 rows=1 loops=67)

  • Index Cond: ((dict_class_id = 4) AND (code = sc.class_id))
Planning time : 0.713 ms
Execution time : 2,545.075 ms