explain.depesz.com

PostgreSQL's explain analyze made readable

Result: jp6B

Settings

Optimization(s) for this plan:

# exclusive inclusive rows x rows loops node
1. 0.000 0.000 ↓ 0.0

Sort (cost=143,607.53..143,607.92 rows=153 width=265) (actual rows= loops=)

  • Sort Key: (round(((((sum((sum(si.total_import)))) / (date_part('month'::text, now()) - '1'::double precision)) * '12'::double precision))::numeric, 2)) DESC
2. 0.000 0.000 ↓ 0.0

Hash Left Join (cost=111,189.55..143,601.98 rows=153 width=265) (actual rows= loops=)

  • Hash Cond: ((cust.company_id = cpurlast.company_id) AND (cust.id = cpurlast.customer_id))
3. 0.000 0.000 ↓ 0.0

Nested Loop Left Join (cost=60,539.48..92,890.23 rows=153 width=133) (actual rows= loops=)

4. 0.000 0.000 ↓ 0.0

Merge Left Join (cost=60,335.37..61,656.43 rows=153 width=101) (actual rows= loops=)

  • Merge Cond: (cust.id = statistics_delivery_note_summaries.customer_id)
  • Join Filter: (statistics_delivery_note_summaries.company_id = cust.company_id)
5. 0.000 0.000 ↓ 0.0

Nested Loop (cost=40,084.38..41,390.37 rows=153 width=97) (actual rows= loops=)

6. 0.000 0.000 ↓ 0.0

GroupAggregate (cost=40,084.10..40,134.87 rows=200 width=20) (actual rows= loops=)

  • Group Key: si.company_id, si.customer_id, si.alc_ano, si.alc_fec
7. 0.000 0.000 ↓ 0.0

Result (cost=40,084.10..40,128.54 rows=346 width=20) (actual rows= loops=)

8. 0.000 0.000 ↓ 0.0

Merge Append (cost=40,084.10..40,125.08 rows=346 width=20) (actual rows= loops=)

  • Sort Key: si.customer_id, si.alc_ano, si.alc_fec
9. 0.000 0.000 ↓ 0.0

GroupAggregate (cost=30,829.17..30,860.45 rows=200 width=20) (actual rows= loops=)

  • Group Key: si.company_id, si.customer_id, si.alc_ano, si.alc_fec
10. 0.000 0.000 ↓ 0.0

Sort (cost=30,829.17..30,834.05 rows=1,952 width=20) (actual rows= loops=)

  • Sort Key: si.customer_id, si.alc_ano, si.alc_fec
11. 0.000 0.000 ↓ 0.0

Subquery Scan on si (cost=30,614.60..30,722.48 rows=1,952 width=20) (actual rows= loops=)

12. 0.000 0.000 ↓ 0.0

GroupAggregate (cost=30,614.60..30,702.96 rows=1,952 width=122) (actual rows= loops=)

  • Group Key: st.company_id, st.alc_nri, st.alc_nro, st.customer_id, st.customer_name, st.fac_ano, st.fac_nro, st.fac_ser_cod, st.fac_emp_doc, st.alc_fec, st.alc_ano
13. 0.000 0.000 ↓ 0.0

Sort (cost=30,614.60..30,619.52 rows=1,967 width=66) (actual rows= loops=)

  • Sort Key: st.alc_nri, st.alc_nro, st.customer_id, st.customer_name, st.fac_ano, st.fac_nro, st.fac_ser_cod, st.fac_emp_doc, st.alc_fec, st.alc_ano
14. 0.000 0.000 ↓ 0.0

Seq Scan on statistics_albarans st (cost=0.00..30,506.99 rows=1,967 width=66) (actual rows= loops=)

  • Filter: ((company_id = 1) AND ((fac_ser_cod)::text = ANY ('{F,C,FR,""}'::text[])) AND (alc_fec <= (date_trunc('month'::text, now()) - '1 day'::interval)) AND ((alc_ano)::double precision = date_part('year'::text, now())))
15. 0.000 0.000 ↓ 0.0

GroupAggregate (cost=9,254.92..9,258.57 rows=146 width=20) (actual rows= loops=)

  • Group Key: sis.company_id, sis.customer_id, sis.fac_ano, sis.alc_fec
16. 0.000 0.000 ↓ 0.0

Sort (cost=9,254.92..9,255.28 rows=146 width=20) (actual rows= loops=)

  • Sort Key: sis.customer_id, sis.fac_ano, sis.alc_fec
17. 0.000 0.000 ↓ 0.0

Subquery Scan on sis (cost=9,240.91..9,249.67 rows=146 width=20) (actual rows= loops=)

18. 0.000 0.000 ↓ 0.0

GroupAggregate (cost=9,240.91..9,248.21 rows=146 width=95) (actual rows= loops=)

  • Group Key: st_1.company_id, st_1.fac_emp_doc, st_1.fac_ser_cod, st_1.customer_id, st_1.alc_fec, st_1.fac_ano, st_1.fac_nro, st_1.fpg_cod, pm.expiration_days, st_1.fac_vto, inv."FacImpBase", inv."FacImpIva
19. 0.000 0.000 ↓ 0.0

Sort (cost=9,240.91..9,241.27 rows=146 width=64) (actual rows= loops=)

  • Sort Key: st_1.fac_emp_doc, st_1.customer_id, st_1.alc_fec, st_1.fac_ano, st_1.fac_nro, st_1.fpg_cod, pm.expiration_days, st_1.fac_vto, inv."FacImpBase", inv."FacImpIva
20. 0.000 0.000 ↓ 0.0

Nested Loop Left Join (cost=0.72..9,235.66 rows=146 width=64) (actual rows= loops=)

21. 0.000 0.000 ↓ 0.0

Nested Loop Left Join (cost=0.43..8,301.30 rows=146 width=48) (actual rows= loops=)

22. 0.000 0.000 ↓ 0.0

Nested Loop Left Join (cost=0.29..8,277.43 rows=146 width=48) (actual rows= loops=)

23. 0.000 0.000 ↓ 0.0

Seq Scan on statistics_invoices st_1 (cost=0.00..7,306.72 rows=146 width=44) (actual rows= loops=)

  • Filter: ((company_id = 1) AND ((fac_ser_cod)::text = 'C'::text) AND (alc_fec <= (date_trunc('month'::text, now()) - '1 day'::interval)) AND ((fac_ano)::double precision = date_part('year'::text, now())))
24. 0.000 0.000 ↓ 0.0

Index Scan using pk_clients on customers cus (cost=0.29..6.64 rows=1 width=12) (actual rows= loops=)

  • Index Cond: (id = st_1.customer_id)
  • Filter: ((company_id = 1) AND (company_id = st_1.company_id))
25. 0.000 0.000 ↓ 0.0

Index Scan using pk_payment_methods on payment_methods pm (cost=0.14..0.16 rows=1 width=8) (actual rows= loops=)

  • Index Cond: (id = cus.payment_method_id)
26. 0.000 0.000 ↓ 0.0

Index Scan using invoices_pkey on invoices inv (cost=0.29..6.40 rows=1 width=34) (actual rows= loops=)

  • Index Cond: (("EmpCod" = st_1.company_id) AND ("EmpCod" = 1) AND ("FacEmpDoc" = (st_1.fac_emp_doc)::bpchar) AND ("FacAno" = st_1.fac_ano) AND ("FacSerCod" = (st_1.fac_ser_cod)::bpchar) AND ("FacNro" = st_1.fac_nro))
27. 0.000 0.000 ↓ 0.0

Index Scan using pk_clients on customers cust (cost=0.29..6.27 rows=1 width=93) (actual rows= loops=)

  • Index Cond: (id = si.customer_id)
  • Filter: (company_id = 1)
28. 0.000 0.000 ↓ 0.0

Materialize (cost=20,250.98..20,265.15 rows=200 width=12) (actual rows= loops=)

29. 0.000 0.000 ↓ 0.0

GroupAggregate (cost=20,250.98..20,262.65 rows=200 width=12) (actual rows= loops=)

  • Group Key: statistics_delivery_note_summaries.company_id, statistics_delivery_note_summaries.customer_id
30. 0.000 0.000 ↓ 0.0

Sort (cost=20,250.98..20,253.40 rows=967 width=12) (actual rows= loops=)

  • Sort Key: statistics_delivery_note_summaries.customer_id
31. 0.000 0.000 ↓ 0.0

Subquery Scan on statistics_delivery_note_summaries (cost=20,047.67..20,203.03 rows=967 width=12) (actual rows= loops=)

32. 0.000 0.000 ↓ 0.0

Finalize GroupAggregate (cost=20,047.67..20,193.36 rows=967 width=122) (actual rows= loops=)

  • Group Key: st_2.company_id, st_2.alc_nri, st_2.alc_nro, st_2.customer_id, st_2.customer_name, st_2.fac_ano, st_2.fac_nro, st_2.fac_ser_cod, st_2.fac_emp_doc, st_2.alc_fec, st_2.alc_ano
33. 0.000 0.000 ↓ 0.0

Gather Merge (cost=20,047.67..20,159.39 rows=810 width=62) (actual rows= loops=)

  • Workers Planned: 2
34. 0.000 0.000 ↓ 0.0

Partial GroupAggregate (cost=19,047.65..19,065.87 rows=405 width=62) (actual rows= loops=)

  • Group Key: st_2.company_id, st_2.alc_nri, st_2.alc_nro, st_2.customer_id, st_2.customer_name, st_2.fac_ano, st_2.fac_nro, st_2.fac_ser_cod, st_2.fac_emp_doc, st_2.alc_fec, st_2.alc_ano
35. 0.000 0.000 ↓ 0.0

Sort (cost=19,047.65..19,048.66 rows=405 width=66) (actual rows= loops=)

  • Sort Key: st_2.alc_nri, st_2.alc_nro, st_2.customer_id, st_2.customer_name, st_2.fac_ano, st_2.fac_nro, st_2.fac_ser_cod, st_2.fac_emp_doc, st_2.alc_fec, st_2.alc_ano
36. 0.000 0.000 ↓ 0.0

Parallel Seq Scan on statistics_albarans st_2 (cost=0.00..19,030.11 rows=405 width=66) (actual rows= loops=)

  • Filter: ((((fac_ser_cod)::text = ''::text) OR (fac_ser_cod IS NULL)) AND (company_id = 1) AND ((fac_ser_cod)::text = ANY ('{F,C,FR,""}'::text[])))
37. 0.000 0.000 ↓ 0.0

Subquery Scan on obs (cost=204.11..204.13 rows=1 width=40) (actual rows= loops=)

  • Filter: ((obs.company_id = 1) AND (obs.company_id = cust.company_id) AND (obs.entity_id = cust.id))
38. 0.000 0.000 ↓ 0.0

Limit (cost=204.11..204.11 rows=1 width=624) (actual rows= loops=)

39. 0.000 0.000 ↓ 0.0

Sort (cost=204.11..204.11 rows=1 width=624) (actual rows= loops=)

  • Sort Key: obs_1.created_at DESC
40. 0.000 0.000 ↓ 0.0

Index Scan using idx_obs on observations obs_1 (cost=0.29..204.10 rows=1 width=624) (actual rows= loops=)

  • Index Cond: (entity_id = cust.id)
  • Filter: ((entity)::text = 'segmentation'::text)
41. 0.000 0.000 ↓ 0.0

Hash (cost=50,631.44..50,631.44 rows=1,242 width=12) (actual rows= loops=)

42. 0.000 0.000 ↓ 0.0

Subquery Scan on cpurlast (cost=50,606.60..50,631.44 rows=1,242 width=12) (actual rows= loops=)

43. 0.000 0.000 ↓ 0.0

HashAggregate (cost=50,606.60..50,619.02 rows=1,242 width=20) (actual rows= loops=)

  • Group Key: st_3.company_id, st_3.customer_id, st_3.alc_ano, st_3.alc_fec
44. 0.000 0.000 ↓ 0.0

Result (cost=38,510.19..50,451.41 rows=12,415 width=20) (actual rows= loops=)

45. 0.000 0.000 ↓ 0.0

Append (cost=38,510.19..50,327.26 rows=12,415 width=20) (actual rows= loops=)

46. 0.000 0.000 ↓ 0.0

HashAggregate (cost=38,510.19..38,605.14 rows=9,495 width=20) (actual rows= loops=)

  • Group Key: st_3.company_id, st_3.customer_id, st_3.alc_ano, st_3.alc_fec
47. 0.000 0.000 ↓ 0.0

HashAggregate (cost=35,424.38..36,373.86 rows=94,948 width=122) (actual rows= loops=)

  • Group Key: st_3.company_id, st_3.alc_nri, st_3.alc_nro, st_3.customer_id, st_3.customer_name, st_3.fac_ano, st_3.fac_nro, st_3.fac_ser_cod, st_3.fac_emp_doc, st_3.alc_fec, st_3.alc_ano
48. 0.000 0.000 ↓ 0.0

Seq Scan on statistics_albarans st_3 (cost=0.00..22,637.13 rows=393,454 width=66) (actual rows= loops=)

  • Filter: ((company_id = 1) AND ((fac_ser_cod)::text = ANY ('{F,C,FR,""}'::text[])))
49. 0.000 0.000 ↓ 0.0

HashAggregate (cost=11,568.77..11,597.97 rows=2,920 width=20) (actual rows= loops=)

  • Group Key: st_4.company_id, st_4.customer_id, st_4.fac_ano, st_4.alc_fec
50. 0.000 0.000 ↓ 0.0

HashAggregate (cost=10,619.84..10,911.82 rows=29,198 width=95) (actual rows= loops=)

  • Group Key: st_4.company_id, st_4.fac_emp_doc, st_4.fac_ser_cod, st_4.customer_id, st_4.alc_fec, st_4.fac_ano, st_4.fac_nro, st_4.fpg_cod, pm_1.expiration_days, st_4.fac_vto, inv_1."FacImpBase", inv_1."FacImpIva
51. 0.000 0.000 ↓ 0.0

Hash Left Join (cost=3,236.02..9,524.91 rows=29,198 width=64) (actual rows= loops=)

  • Hash Cond: ((st_4.company_id = inv_1."EmpCod") AND ((st_4.fac_emp_doc)::bpchar = inv_1."FacEmpDoc") AND (st_4.fac_ano = inv_1."FacAno") AND ((st_4.fac_ser_cod)::bpchar = inv_1."FacSerCod") AND (st_4.fac_nro = inv_1."FacNro"))
52. 0.000 0.000 ↓ 0.0

Hash Left Join (cost=1,833.01..7,738.66 rows=29,198 width=48) (actual rows= loops=)

  • Hash Cond: (cus_1.payment_method_id = pm_1.id)
53. 0.000 0.000 ↓ 0.0

Hash Left Join (cost=1,827.32..7,654.36 rows=29,198 width=48) (actual rows= loops=)

  • Hash Cond: ((st_4.company_id = cus_1.company_id) AND (st_4.customer_id = cus_1.id))
54. 0.000 0.000 ↓ 0.0

Seq Scan on statistics_invoices st_4 (cost=0.00..5,673.73 rows=29,198 width=44) (actual rows= loops=)

  • Filter: ((company_id = 1) AND ((fac_ser_cod)::text = 'C'::text))
55. 0.000 0.000 ↓ 0.0

Hash (cost=1,612.10..1,612.10 rows=14,348 width=12) (actual rows= loops=)

56. 0.000 0.000 ↓ 0.0

Seq Scan on customers cus_1 (cost=0.00..1,612.10 rows=14,348 width=12) (actual rows= loops=)

  • Filter: (company_id = 1)
57. 0.000 0.000 ↓ 0.0

Hash (cost=3.64..3.64 rows=164 width=8) (actual rows= loops=)

58. 0.000 0.000 ↓ 0.0

Seq Scan on payment_methods pm_1 (cost=0.00..3.64 rows=164 width=8) (actual rows= loops=)

59. 0.000 0.000 ↓ 0.0

Hash (cost=838.58..838.58 rows=25,086 width=34) (actual rows= loops=)

60. 0.000 0.000 ↓ 0.0

Seq Scan on invoices inv_1 (cost=0.00..838.58 rows=25,086 width=34) (actual rows= loops=)

  • Filter: ("EmpCod" = 1)