explain.depesz.com

PostgreSQL's explain analyze made readable

Result: 4j0y

Settings
# exclusive inclusive rows x rows loops node
1. 0.002 60,020.550 ↓ 0.0 0 1

GroupAggregate (cost=8,942.43..8,942.49 rows=1 width=48) (actual time=60,020.550..60,020.550 rows=0 loops=1)

  • Output: param.contract_item_id, sum((((fi.quantity * (tuomc.rate / suomc.rate)) / ((upper(fi.date_range) - lower(fi.date_range)))::numeric) * ((upper((fi.date_range * param.date_range)) - lower((fi.date_range * param.date_range))))::numeric))
  • Group Key: param.contract_item_id
  • Buffers: shared hit=70,245, temp read=598,181 written=1,096,097
2.          

CTE param

3. 3,053.517 4,690.915 ↓ 139.6 22,507,830 1

Nested Loop (cost=935.94..4,401.76 rows=161,205 width=78) (actual time=77.049..4,690.915 rows=22,507,830 loops=1)

  • Output: contract_product_materialized.contract_item_id, crv.date_range, cmp.company_id, contract_product_materialized.product_id, contract_product_materialized.uom_type_id
  • Buffers: shared hit=70,178
4. 4.780 5.041 ↓ 2.5 2,397 1

Bitmap Heap Scan on client_kronos.contract_product_materialized (cost=47.13..1,486.90 rows=977 width=64) (actual time=0.270..5.041 rows=2,397 loops=1)

  • Output: contract_product_materialized.contract_item_id, contract_product_materialized.contract_id, contract_product_materialized.product_id, contract_product_materialized.estimated_quantity, contract_product_materialized.uom_type_id, contract_product_materialized.rebate_deviated_value, contract_product_materialized.rebate_deviated_type, contract_product_materialized.inactive_override, contract_product_materialized.rebate_direct_value, contract_product_materialized.rebate_direct_type, contract_product_materialized.rebate_direct_decimal_model, contract_product_materialized.rebate_deviated_decimal_model, contract_product_materialized.won, contract_product_materialized.rebate_growth_type, contract_product_materialized.rebate_growth_decimal_model, contract_product_materialized.lift_quantity
  • Recheck Cond: (contract_product_materialized.contract_id = '68a454a3-15e7-11ea-be40-e981416a043d'::uuid)
  • Heap Blocks: exact=47
  • Buffers: shared hit=151
5. 0.261 0.261 ↓ 2.5 2,397 1

Bitmap Index Scan on contract_product_materialized_pkey (cost=0.00..46.88 rows=977 width=0) (actual time=0.261..0.261 rows=2,397 loops=1)

  • Index Cond: (contract_product_materialized.contract_id = '68a454a3-15e7-11ea-be40-e981416a043d'::uuid)
  • Buffers: shared hit=104
6. 1,551.835 1,632.357 ↓ 56.9 9,390 2,397

Materialize (cost=888.81..900.21 rows=165 width=46) (actual time=0.033..0.681 rows=9,390 loops=2,397)

  • Output: cav.contract_amend_version_id, crv.date_range, cmp.company_id
  • Buffers: shared hit=70,027
7. 1.141 80.522 ↓ 56.9 9,390 1

Nested Loop (cost=888.81..899.38 rows=165 width=46) (actual time=76.774..80.522 rows=9,390 loops=1)

  • Output: cav.contract_amend_version_id, crv.date_range, cmp.company_id
  • Buffers: shared hit=70,027
8. 0.004 0.028 ↑ 1.0 1 1

Nested Loop (cost=0.56..6.60 rows=1 width=30) (actual time=0.020..0.028 rows=1 loops=1)

  • Output: cav.contract_amend_version_id, crv.date_range
  • Inner Unique: true
  • Buffers: shared hit=6
9. 0.016 0.016 ↑ 1.0 1 1

Index Scan using contract_amend_version_pkey on client_kronos.contract_amend_version cav (cost=0.28..3.30 rows=1 width=32) (actual time=0.009..0.016 rows=1 loops=1)

  • Output: cav.contract_amend_version_id, cav.contract_renew_version_id, cav.contract_state, cav.contract_amend_version_parent_id, cav.contract_name, cav.contact_name, cav.contact_email, cav.contact_phone, cav.create_timestamp, cav.amend_version
  • Index Cond: (cav.contract_amend_version_id = '68a454a3-15e7-11ea-be40-e981416a043d'::uuid)
  • Buffers: shared hit=3
10. 0.008 0.008 ↑ 1.0 1 1

Index Scan using contract_version_pkey on client_kronos.contract_renew_version crv (cost=0.28..3.30 rows=1 width=30) (actual time=0.008..0.008 rows=1 loops=1)

  • Output: crv.contract_renew_version_id, crv.contract_family_id, crv.date_range, crv.create_timestamp, crv.dead, crv.renew_version
  • Index Cond: (crv.contract_renew_version_id = cav.contract_renew_version_id)
  • Buffers: shared hit=3
11. 1.937 79.353 ↓ 56.9 9,390 1

Unique (cost=888.24..889.48 rows=165 width=36) (actual time=76.752..79.353 rows=9,390 loops=1)

  • Output: cav_1.contract_amend_version_id, cmp.company_id, ct.internal_company_type
  • Buffers: shared hit=70,021
12. 4.760 77.416 ↓ 62.5 10,305 1

Sort (cost=888.24..888.66 rows=165 width=36) (actual time=76.751..77.416 rows=10,305 loops=1)

  • Output: cav_1.contract_amend_version_id, cmp.company_id, ct.internal_company_type
  • Sort Key: cmp.company_id, ct.internal_company_type
  • Sort Method: quicksort Memory: 1,190kB
  • Buffers: shared hit=70,021
13. 3.264 72.656 ↓ 62.5 10,305 1

Hash Join (cost=360.03..882.17 rows=165 width=36) (actual time=0.096..72.656 rows=10,305 loops=1)

  • Output: cav_1.contract_amend_version_id, cmp.company_id, ct.internal_company_type
  • Inner Unique: true
  • Hash Cond: (cmp.company_type_id = ct.company_type_id)
  • Buffers: shared hit=70,021
14. 1.998 69.382 ↓ 62.5 10,305 1

Nested Loop (cost=358.98..879.78 rows=165 width=48) (actual time=0.081..69.382 rows=10,305 loops=1)

  • Output: cav_1.contract_amend_version_id, cmp.company_id, cmp.company_type_id
  • Inner Unique: true
  • Buffers: shared hit=70,020
15. 0.819 46.774 ↓ 58.2 10,305 1

Nested Loop (cost=358.70..819.15 rows=177 width=32) (actual time=0.072..46.774 rows=10,305 loops=1)

  • Output: cav_1.contract_amend_version_id, cagg.agg_company_id
  • Buffers: shared hit=39,066
16. 1.431 25.507 ↓ 58.1 10,224 1

Nested Loop Left Join (cost=358.29..663.93 rows=176 width=48) (actual time=0.060..25.507 rows=10,224 loops=1)

  • Output: c.contractee_company_id, cav_1.contract_amend_version_id, cg_1.company_id
  • Buffers: shared hit=7,971
17. 0.040 0.516 ↓ 19.0 19 1

Hash Right Join (cost=357.87..373.54 rows=1 width=48) (actual time=0.046..0.516 rows=19 loops=1)

  • Output: c.contractee_company_id, cav_1.contract_amend_version_id, groupings_list.grouping_id
  • Hash Cond: (groupings_list.original_grouping_id = c.contractee_grouping_id)
  • Buffers: shared hit=85
18. 0.461 0.461 ↑ 6.0 77 1

CTE Scan on groupings_list (cost=350.94..360.22 rows=464 width=52) (actual time=0.009..0.461 rows=77 loops=1)

  • Output: groupings_list.original_grouping_id, NULL::uuid, groupings_list.grouping_id, NULL::integer
  • Buffers: shared hit=76
19.          

CTE groupings_list

20. 0.073 0.401 ↑ 6.0 77 1

Recursive Union (cost=0.00..350.94 rows=464 width=52) (actual time=0.007..0.401 rows=77 loops=1)

  • Buffers: shared hit=76
21. 0.049 0.049 ↑ 1.0 34 1

Seq Scan on client_kronos.grouping_company pg (cost=0.00..19.34 rows=34 width=52) (actual time=0.006..0.049 rows=34 loops=1)

  • Output: pg.grouping_id, pg.parent_grouping_id, pg.grouping_id, 0
  • Buffers: shared hit=19
22. 0.114 0.279 ↑ 3.1 14 3

Hash Join (cost=11.05..32.23 rows=43 width=52) (actual time=0.046..0.093 rows=14 loops=3)

  • Output: gl.original_grouping_id, cg.parent_grouping_id, cg.grouping_id, (gl.level + 1)
  • Hash Cond: (cg.parent_grouping_id = gl.grouping_id)
  • Buffers: shared hit=57
23. 0.123 0.123 ↑ 1.0 29 3

Seq Scan on client_kronos.grouping_company cg (cost=0.00..19.34 rows=29 width=32) (actual time=0.006..0.041 rows=29 loops=3)

  • Output: cg.grouping_id, cg.client_id, cg.grouping_description, cg.grouping_cd, cg.grouping_type, cg.parent_grouping_id, cg.active_ind, cg.company_type_id, cg.grouping_company_type
  • Filter: cg.active_ind
  • Rows Removed by Filter: 5
  • Buffers: shared hit=57
24. 0.021 0.042 ↑ 13.1 26 3

Hash (cost=6.80..6.80 rows=340 width=36) (actual time=0.014..0.014 rows=26 loops=3)

  • Output: gl.original_grouping_id, gl.level, gl.grouping_id
  • Buckets: 1,024 Batches: 1 Memory Usage: 10kB
25. 0.021 0.021 ↑ 13.1 26 3

WorkTable Scan on groupings_list gl (cost=0.00..6.80 rows=340 width=36) (actual time=0.002..0.007 rows=26 loops=3)

  • Output: gl.original_grouping_id, gl.level, gl.grouping_id
26. 0.001 0.015 ↑ 1.0 1 1

Hash (cost=6.91..6.91 rows=1 width=48) (actual time=0.015..0.015 rows=1 loops=1)

  • Output: c.contractee_grouping_id, c.contractee_company_id, cav_1.contract_amend_version_id
  • Buckets: 1,024 Batches: 1 Memory Usage: 9kB
  • Buffers: shared hit=9
27. 0.002 0.014 ↑ 1.0 1 1

Nested Loop (cost=0.84..6.91 rows=1 width=48) (actual time=0.013..0.014 rows=1 loops=1)

  • Output: c.contractee_grouping_id, c.contractee_company_id, cav_1.contract_amend_version_id
  • Inner Unique: true
  • Buffers: shared hit=9
28. 0.001 0.006 ↑ 1.0 1 1

Nested Loop (cost=0.56..6.60 rows=1 width=32) (actual time=0.006..0.006 rows=1 loops=1)

  • Output: crv_1.contract_family_id, cav_1.contract_amend_version_id
  • Inner Unique: true
  • Buffers: shared hit=6
29. 0.003 0.003 ↑ 1.0 1 1

Index Scan using contract_amend_version_pkey on client_kronos.contract_amend_version cav_1 (cost=0.28..3.30 rows=1 width=32) (actual time=0.003..0.003 rows=1 loops=1)

  • Output: cav_1.contract_amend_version_id, cav_1.contract_renew_version_id, cav_1.contract_state, cav_1.contract_amend_version_parent_id, cav_1.contract_name, cav_1.contact_name, cav_1.contact_email, cav_1.contact_phone, cav_1.create_timestamp, cav_1.amend_version
  • Index Cond: (cav_1.contract_amend_version_id = '68a454a3-15e7-11ea-be40-e981416a043d'::uuid)
  • Buffers: shared hit=3
30. 0.002 0.002 ↑ 1.0 1 1

Index Scan using contract_version_pkey on client_kronos.contract_renew_version crv_1 (cost=0.28..3.30 rows=1 width=32) (actual time=0.002..0.002 rows=1 loops=1)

  • Output: crv_1.contract_renew_version_id, crv_1.contract_family_id, crv_1.date_range, crv_1.create_timestamp, crv_1.dead, crv_1.renew_version
  • Index Cond: (crv_1.contract_renew_version_id = cav_1.contract_renew_version_id)
  • Buffers: shared hit=3
31. 0.006 0.006 ↑ 1.0 1 1

Index Scan using contract_family_pkey on client_kronos.contract_family c (cost=0.28..0.31 rows=1 width=48) (actual time=0.006..0.006 rows=1 loops=1)

  • Output: c.contract_family_id, c.client_id, c.contractee_company_id, c.contractee_grouping_id, c.creator_id, c.contract_sequence, c.cost_basis_type, c.contract_type, c.contract_title, c.contract_template_id, c.payment_calendar_id, c.catch_all, c.accrual_quantity_source, c.import_contract_number, c.accrual_lumpsum_spread
  • Index Cond: (c.contract_family_id = crv_1.contract_family_id)
  • Buffers: shared hit=3
32. 23.560 23.560 ↑ 2.3 538 19

Index Only Scan using company_grouping_pkey on client_kronos.company_grouping cg_1 (cost=0.41..277.84 rows=1,255 width=32) (actual time=0.159..1.240 rows=538 loops=19)

  • Output: cg_1.company_id, cg_1.grouping_id
  • Index Cond: (cg_1.grouping_id = groupings_list.grouping_id)
  • Heap Fetches: 0
  • Buffers: shared hit=7,886
33. 20.448 20.448 ↑ 1.0 1 10,224

Index Only Scan using company_agg_pkey on client_kronos.company_agg cagg (cost=0.41..0.87 rows=1 width=32) (actual time=0.002..0.002 rows=1 loops=10,224)

  • Output: cagg.company_id, cagg.agg_company_id
  • Index Cond: (cagg.company_id = COALESCE(c.contractee_company_id, cg_1.company_id))
  • Heap Fetches: 0
  • Buffers: shared hit=31,095
34. 20.610 20.610 ↑ 1.0 1 10,305

Index Scan using company_pkey on client_kronos.company cmp (cost=0.29..0.34 rows=1 width=32) (actual time=0.002..0.002 rows=1 loops=10,305)

  • Output: cmp.company_id, cmp.client_id, cmp.company_name, cmp.company_number, cmp.company_type_id, cmp.active_ind, cmp.address_1, cmp.address_2, cmp.address_3, cmp.address_4, cmp.city, cmp.region, cmp.postal_code, cmp.country, cmp.company_agg_id, cmp.deduction_interval, cmp.alt_address_active, cmp.alt_address_1, cmp.alt_address_2, cmp.alt_address_3, cmp.alt_address_4, cmp.alt_city, cmp.alt_region, cmp.alt_postal_code, cmp.alt_country, cmp.atlas_company_id, cmp.email, cmp.tax_type_id, cmp.redistributor_ind, cmp.operator_request, cmp.early_payment_discount, cmp.vip, cmp.deduction_contact_email, cmp.is_unipro, cmp.is_golbon, cmp.is_ima, cmp.cross_ship_company_id, cmp.tpo_ind, cmp.auto_submit_eclaim, cmp.auto_approve_eclaim
  • Index Cond: (cmp.company_id = cagg.agg_company_id)
  • Buffers: shared hit=30,954
35. 0.003 0.010 ↑ 1.0 2 1

Hash (cost=1.02..1.02 rows=2 width=20) (actual time=0.010..0.010 rows=2 loops=1)

  • Output: ct.internal_company_type, ct.company_type_id
  • Buckets: 1,024 Batches: 1 Memory Usage: 9kB
  • Buffers: shared hit=1
36. 0.007 0.007 ↑ 1.0 2 1

Seq Scan on client_kronos.company_type ct (cost=0.00..1.02 rows=2 width=20) (actual time=0.006..0.007 rows=2 loops=1)

  • Output: ct.internal_company_type, ct.company_type_id
  • Buffers: shared hit=1
37. 0.004 60,020.548 ↓ 0.0 0 1

Sort (cost=4,540.67..4,540.67 rows=1 width=122) (actual time=60,020.548..60,020.548 rows=0 loops=1)

  • Output: param.contract_item_id, fi.quantity, tuomc.rate, suomc.rate, fi.date_range, param.date_range
  • Sort Key: param.contract_item_id
  • Sort Method: quicksort Memory: 25kB
  • Buffers: shared hit=70,245, temp read=598,181 written=1,096,097
38. 0.001 60,020.544 ↓ 0.0 0 1

Nested Loop (cost=4,516.20..4,540.66 rows=1 width=122) (actual time=60,020.543..60,020.544 rows=0 loops=1)

  • Output: param.contract_item_id, fi.quantity, tuomc.rate, suomc.rate, fi.date_range, param.date_range
  • Inner Unique: true
  • Join Filter: ((fi.product_id = suomc.product_id) AND (fi.uom_type_id = suomc.uom_type_id))
  • Buffers: shared hit=70,245, temp read=598,181 written=1,096,097
39. 0.002 60,020.543 ↓ 0.0 0 1

Nested Loop (cost=4,515.92..4,540.28 rows=1 width=197) (actual time=60,020.543..60,020.543 rows=0 loops=1)

  • Output: param.contract_item_id, param.date_range, param.product_id, fi.quantity, fi.date_range, fi.product_id, fi.uom_type_id, pro.product_id, tuomc.rate, tuomc.product_id
  • Inner Unique: true
  • Join Filter: (fi.product_id = pro.product_id)
  • Buffers: shared hit=70,245, temp read=598,181 written=1,096,097
40. 0.007 60,020.541 ↓ 0.0 0 1

Merge Join (cost=4,515.64..4,539.97 rows=1 width=181) (actual time=60,020.541..60,020.541 rows=0 loops=1)

  • Output: param.contract_item_id, param.date_range, param.product_id, fi.quantity, fi.date_range, fi.product_id, fi.uom_type_id, tuomc.rate, tuomc.product_id
  • Merge Cond: ((param.product_id = fi.product_id) AND (param.company_id = fi.company_id))
  • Join Filter: (fi.date_range && param.date_range)
  • Buffers: shared hit=70,245, temp read=598,181 written=1,096,097
41. 38,566.202 60,020.500 ↑ 2,666.0 1 1

Sort (cost=4,476.98..4,483.64 rows=2,666 width=101) (actual time=60,020.500..60,020.500 rows=1 loops=1)

  • Output: param.contract_item_id, param.date_range, param.company_id, param.product_id, tuomc.rate, tuomc.product_id
  • Sort Key: param.product_id, param.company_id
  • Sort Method: external merge Disk: 2,048,224kB
  • Buffers: shared hit=70,245, temp read=598,181 written=1,096,097
42. 6,716.893 21,454.298 ↓ 8,442.5 22,507,830 1

Hash Join (cost=254.85..4,325.28 rows=2,666 width=101) (actual time=79.404..21,454.298 rows=22,507,830 loops=1)

  • Output: param.contract_item_id, param.date_range, param.company_id, param.product_id, tuomc.rate, tuomc.product_id
  • Inner Unique: true
  • Hash Cond: ((param.product_id = tuomc.product_id) AND (param.uom_type_id = tuomc.uom_type_id))
  • Buffers: shared hit=70,245, temp written=241,783
43. 14,735.078 14,735.078 ↓ 139.6 22,507,830 1

CTE Scan on param (cost=0.00..3,224.10 rows=161,205 width=96) (actual time=77.052..14,735.078 rows=22,507,830 loops=1)

  • Output: param.contract_item_id, param.date_range, param.company_id, param.product_id, param.uom_type_id
  • Buffers: shared hit=70,178, temp written=241,783
44. 1.334 2.327 ↓ 1.1 7,931 1

Hash (cost=142.14..142.14 rows=7,514 width=37) (actual time=2.327..2.327 rows=7,931 loops=1)

  • Output: tuomc.rate, tuomc.product_id, tuomc.uom_type_id
  • Buckets: 8,192 Batches: 1 Memory Usage: 600kB
  • Buffers: shared hit=67
45. 0.993 0.993 ↓ 1.1 7,931 1

Seq Scan on client_kronos.product_uom_conversion tuomc (cost=0.00..142.14 rows=7,514 width=37) (actual time=0.013..0.993 rows=7,931 loops=1)

  • Output: tuomc.rate, tuomc.product_id, tuomc.uom_type_id
  • Buffers: shared hit=67
46. 0.024 0.034 ↓ 0.0 0 1

Sort (cost=38.66..39.96 rows=520 width=112) (actual time=0.034..0.034 rows=0 loops=1)

  • Output: fi.quantity, fi.date_range, fi.company_id, fi.product_id, fi.uom_type_id
  • Sort Key: fi.product_id, fi.company_id
  • Sort Method: quicksort Memory: 25kB
47. 0.010 0.010 ↓ 0.0 0 1

Seq Scan on client_kronos.forecast_objective fi (cost=0.00..15.20 rows=520 width=112) (actual time=0.010..0.010 rows=0 loops=1)

  • Output: fi.quantity, fi.date_range, fi.company_id, fi.product_id, fi.uom_type_id
48. 0.000 0.000 ↓ 0.0 0

Index Only Scan using product_pkey on client_kronos.product pro (cost=0.28..0.30 rows=1 width=16) (never executed)

  • Output: pro.product_id
  • Index Cond: (pro.product_id = param.product_id)
  • Heap Fetches: 0
49. 0.000 0.000 ↓ 0.0 0

Index Scan using product_uom_conversion_pkey on client_kronos.product_uom_conversion suomc (cost=0.28..0.34 rows=3 width=37) (never executed)

  • Output: suomc.product_id, suomc.uom_type_id, suomc.rate
  • Index Cond: (suomc.product_id = param.product_id)
Planning time : 3.770 ms
Execution time : 60,555.569 ms