explain.depesz.com

PostgreSQL's explain analyze made readable

Result: xg3S

Settings
# exclusive inclusive rows x rows loops node
1. 0.068 1,106.981 ↓ 1.3 67 1

Sort (cost=6,578,503.90..6,578,504.03 rows=52 width=952) (actual time=1,106.979..1,106.981 rows=67 loops=1)

  • Sort Key: abt.referencia_bico, (min(COALESCE((min((b_1.abt_vl_encerrante - b_1.abt_vl_abastecimento))), (COALESCE(min(abt.encerrante_inicial_abt) FILTER (WHERE ((abt.data_abt >= $6) OR (NOT (SubPlan 3)))), '0'::numeric)))) OVER (?)), (max(CASE WHEN ((((max(abt.encerrante_final_abt)) - (COALESCE(min(abt.encerrante_inicial_abt) FILTER (WHERE ((abt.data_abt >= $6) OR (NOT (SubPlan 3)))), '0'::numeric))) - (sum(abt.quantidade_afericao))) > (COALESCE(sum(b.abt_vl_volume_abastecido), '0'::numeric))) THEN ((max(abt.encerrante_final_abt)) - (COALESCE(sum(b.abt_vl_volume_abastecido), '0'::numeric))) ELSE (max(abt.encerrante_final_abt)) END) OVER (?)), abt.preco_bomba
  • Sort Method: quicksort Memory: 42kB
2.          

CTE caixa_meta

3. 0.009 0.016 ↑ 1.0 1 1

Aggregate (cost=2.65..2.66 rows=1 width=24) (actual time=0.015..0.016 rows=1 loops=1)

4. 0.007 0.007 ↑ 1.0 1 1

Index Scan using caixa_pkey on caixa cai_6 (cost=0.42..2.64 rows=1 width=12) (actual time=0.007..0.007 rows=1 loops=1)

  • Index Cond: (cai_cd_caixa = 1506645)
5. 0.274 1,106.913 ↓ 1.3 67 1

WindowAgg (cost=6,578,494.69..6,578,499.76 rows=52 width=952) (actual time=1,106.653..1,106.913 rows=67 loops=1)

6. 0.067 1,106.639 ↓ 1.3 67 1

Sort (cost=6,578,494.69..6,578,494.82 rows=52 width=728) (actual time=1,106.635..1,106.639 rows=67 loops=1)

  • Sort Key: abt.bico, abt.substituicao, abt.produto
  • Sort Method: quicksort Memory: 40kB
7. 0.043 1,106.572 ↓ 1.3 67 1

Group (cost=6,578,489.69..6,578,493.20 rows=52 width=728) (actual time=1,106.529..1,106.572 rows=67 loops=1)

  • Group Key: abt.referencia_bico, abt.descricao_produto, (sum(abt.quantidade_afericao)), (sum(abt.qtd_abastecimento)), abt.preco_bomba, (CASE WHEN (sum((abt.valor_venda_item - abt.valor_abastecimento)) > '0'::numeric) THEN sum((abt.valor_venda_item - abt.valor_abastecimento)) ELSE '0'::numeric END), (CASE WHEN (sum((abt.valor_venda_item - abt.valor_abastecimento)) < '0'::numeric) THEN abs(sum((abt.valor_venda_item - abt.valor_abastecimento))) ELSE '0'::numeric END), (COALESCE(sum(abt.valor_venda_item), '0'::numeric)), abt.substituicao, abt.descricao_bomba, (COALESCE(min(abt.encerrante_inicial_abt) FILTER (WHERE ((abt.data_abt >= $6) OR (NOT (SubPlan 3)))), '0'::numeric)), (COALESCE(sum(b_1.abt_vl_volume_abastecido), '0'::numeric)), (max(abt.encerrante_final_abt)), (COALESCE(sum(b.abt_vl_volume_abastecido), '0'::numeric)), abt.bico, abt.produto, (((((abt.bico)::character varying)::text || ((abt.substituicao)::character varying)::text) || ((abt.produto)::character varying)::text)), (min((b_1.abt_vl_encerrante - b_1.abt_vl_abastecimento)))
8. 0.133 1,106.529 ↓ 1.3 67 1

Sort (cost=6,578,489.69..6,578,489.82 rows=52 width=728) (actual time=1,106.526..1,106.529 rows=67 loops=1)

  • Sort Key: abt.referencia_bico, abt.descricao_produto, (sum(abt.quantidade_afericao)), (sum(abt.qtd_abastecimento)), abt.preco_bomba, (CASE WHEN (sum((abt.valor_venda_item - abt.valor_abastecimento)) > '0'::numeric) THEN sum((abt.valor_venda_item - abt.valor_abastecimento)) ELSE '0'::numeric END), (CASE WHEN (sum((abt.valor_venda_item - abt.valor_abastecimento)) < '0'::numeric) THEN abs(sum((abt.valor_venda_item - abt.valor_abastecimento))) ELSE '0'::numeric END), (COALESCE(sum(abt.valor_venda_item), '0'::numeric)), abt.substituicao, abt.descricao_bomba, (COALESCE(min(abt.encerrante_inicial_abt) FILTER (WHERE ((abt.data_abt >= $6) OR (NOT (SubPlan 3)))), '0'::numeric)), (COALESCE(sum(b_1.abt_vl_volume_abastecido), '0'::numeric)), (max(abt.encerrante_final_abt)), (COALESCE(sum(b.abt_vl_volume_abastecido), '0'::numeric)), abt.bico, abt.produto, (((((abt.bico)::character varying)::text || ((abt.substituicao)::character varying)::text) || ((abt.produto)::character varying)::text)), (min((b_1.abt_vl_encerrante - b_1.abt_vl_abastecimento)))
  • Sort Method: quicksort Memory: 40kB
9. 0.112 1,106.396 ↓ 1.3 67 1

Nested Loop (cost=3,931,930.76..6,578,488.21 rows=52 width=728) (actual time=706.422..1,106.396 rows=67 loops=1)

10. 0.114 730.883 ↓ 1.3 67 1

Nested Loop (cost=3,930,582.02..6,508,351.01 rows=52 width=632) (actual time=704.541..730.883 rows=67 loops=1)

11. 0.881 714.957 ↓ 1.3 67 1

GroupAggregate (cost=3,930,569.10..6,507,677.14 rows=52 width=604) (actual time=704.511..714.957 rows=67 loops=1)

  • Group Key: abt.referencia_bico, abt.descricao_produto, abt.preco_bomba, abt.substituicao, abt.descricao_bomba, abt.produto, abt.bico
12.          

Initplan (for GroupAggregate)

13. 0.003 0.009 ↑ 1.0 1 1

Aggregate (cost=2.65..2.65 rows=1 width=4) (actual time=0.008..0.009 rows=1 loops=1)

14. 0.006 0.006 ↑ 1.0 1 1

Index Scan using caixa_pkey on caixa caii (cost=0.42..2.64 rows=1 width=4) (actual time=0.006..0.006 rows=1 loops=1)

  • Index Cond: (cai_cd_caixa = 1506645)
15. 1.059 704.581 ↓ 11.9 621 1

Sort (cost=3,930,566.45..3,930,566.58 rows=52 width=580) (actual time=704.489..704.581 rows=621 loops=1)

  • Sort Key: abt.referencia_bico, abt.descricao_produto, abt.preco_bomba, abt.substituicao, abt.descricao_bomba, abt.produto, abt.bico
  • Sort Method: quicksort Memory: 148kB
16. 0.296 703.522 ↓ 11.9 621 1

Subquery Scan on abt (cost=3.11..3,930,564.97 rows=52 width=580) (actual time=0.115..703.522 rows=621 loops=1)

17. 0.132 703.226 ↓ 11.9 621 1

Append (cost=3.11..3,930,564.45 rows=52 width=612) (actual time=0.113..703.226 rows=621 loops=1)

18. 0.465 15.257 ↓ 36.4 618 1

Subquery Scan on *SELECT* 1 (cost=3.11..3,450.62 rows=17 width=192) (actual time=0.112..15.257 rows=618 loops=1)

19. 1.025 14.792 ↓ 36.4 618 1

Nested Loop (cost=3.11..3,450.37 rows=17 width=136) (actual time=0.110..14.792 rows=618 loops=1)

20. 0.548 12.531 ↓ 36.4 618 1

Nested Loop (cost=2.83..3,411.63 rows=17 width=91) (actual time=0.099..12.531 rows=618 loops=1)

21. 0.844 10.129 ↓ 36.4 618 1

Nested Loop (cost=2.41..3,368.62 rows=17 width=63) (actual time=0.089..10.129 rows=618 loops=1)

22. 0.349 8.049 ↓ 36.4 618 1

Nested Loop (cost=2.12..3,328.88 rows=17 width=51) (actual time=0.064..8.049 rows=618 loops=1)

23. 0.483 4.360 ↓ 35.2 668 1

Nested Loop (cost=1.56..3,278.06 rows=19 width=18) (actual time=0.051..4.360 rows=668 loops=1)

24. 0.150 0.902 ↓ 74.4 595 1

Nested Loop (cost=0.99..350.31 rows=8 width=12) (actual time=0.040..0.902 rows=595 loops=1)

25. 0.019 0.019 ↑ 1.0 1 1

Index Scan using caixa_pkey on caixa cai (cost=0.42..2.65 rows=1 width=12) (actual time=0.018..0.019 rows=1 loops=1)

  • Index Cond: (cai_cd_caixa = 1506645)
  • Filter: (cai_cd_unidade_negocio = 180)
26. 0.733 0.733 ↓ 74.4 595 1

Index Scan using venda_idx_caixa on venda ven (cost=0.56..347.59 rows=8 width=12) (actual time=0.019..0.733 rows=595 loops=1)

  • Index Cond: (ven_cd_caixa = 1506645)
  • Filter: ((ven_cd_unidade_negocio = 180) AND (ven_fl_cancelada = 'N'::bpchar))
  • Rows Removed by Filter: 3
27. 2.975 2.975 ↑ 412.0 1 595

Index Scan using venda_item_idx_venda_rebuild_1 on venda_item vei (cost=0.57..361.85 rows=412 width=14) (actual time=0.004..0.005 rows=1 loops=595)

  • Index Cond: (vei_cd_venda = ven.ven_cd_venda)
28. 3.340 3.340 ↑ 1.0 1 668

Index Scan using abastecimento_abt_cd_venda_item_key on abastecimento abt_1 (cost=0.57..2.67 rows=1 width=41) (actual time=0.005..0.005 rows=1 loops=668)

  • Index Cond: (abt_cd_venda_item = vei.vei_cd_venda_item)
  • Filter: (NOT abt_bl_afericao)
29. 1.236 1.236 ↑ 1.0 1 618

Index Scan using bico_pkey on bico bic (cost=0.28..2.34 rows=1 width=16) (actual time=0.002..0.002 rows=1 loops=618)

  • Index Cond: (bic_cd_bico = abt_1.abt_cd_bico)
30. 1.854 1.854 ↑ 1.0 1 618

Index Scan using produto_pkey on produto pro (cost=0.42..2.53 rows=1 width=32) (actual time=0.003..0.003 rows=1 loops=618)

  • Index Cond: (pro_cd_produto = bic.bic_cd_produto)
31. 1.236 1.236 ↑ 1.0 1 618

Index Scan using bomba_pkey on bomba bom (cost=0.28..2.28 rows=1 width=13) (actual time=0.002..0.002 rows=1 loops=618)

  • Index Cond: (bom_cd_bomba = bic.bic_cd_bomba)
32. 0.001 0.252 ↓ 0.0 0 1

Subquery Scan on *SELECT* 2 (cost=2.40..60.53 rows=1 width=218) (actual time=0.251..0.252 rows=0 loops=1)

33. 0.001 0.251 ↓ 0.0 0 1

Nested Loop (cost=2.40..60.51 rows=1 width=134) (actual time=0.251..0.251 rows=0 loops=1)

  • Join Filter: (abt_2.abt_dt_abastecimento >= cai_1.cai_dt_movimento)
34. 0.000 0.250 ↓ 0.0 0 1

Nested Loop (cost=1.97..57.85 rows=1 width=90) (actual time=0.250..0.250 rows=0 loops=1)

35. 0.000 0.250 ↓ 0.0 0 1

Nested Loop (cost=1.69..56.00 rows=1 width=85) (actual time=0.250..0.250 rows=0 loops=1)

36. 0.001 0.250 ↓ 0.0 0 1

Nested Loop (cost=1.27..53.36 rows=1 width=57) (actual time=0.250..0.250 rows=0 loops=1)

37. 0.028 0.249 ↓ 0.0 0 1

Nested Loop (cost=0.99..51.39 rows=1 width=45) (actual time=0.249..0.249 rows=0 loops=1)

38. 0.029 0.029 ↓ 3.7 48 1

Index Scan using abastecimento_afericao_idx_aba_cd_caixa on abastecimento_afericao aba (cost=0.42..15.15 rows=13 width=8) (actual time=0.010..0.029 rows=48 loops=1)

  • Index Cond: (aba_cd_caixa = 1506645)
39. 0.192 0.192 ↓ 0.0 0 48

Index Scan using abastecimento_pkey on abastecimento abt_2 (cost=0.57..2.79 rows=1 width=45) (actual time=0.004..0.004 rows=0 loops=48)

  • Index Cond: (abt_cd_abastecimento = aba.aba_cd_abastecimento)
  • Filter: ((NOT abt_bl_afericao) AND (abt_cd_unidade_negocio = 180))
  • Rows Removed by Filter: 1
40. 0.000 0.000 ↓ 0.0 0

Index Scan using bico_pkey on bico bic_1 (cost=0.28..1.88 rows=1 width=20) (never executed)

  • Index Cond: (bic_cd_bico = abt_2.abt_cd_bico)
  • Filter: (bic_cd_unidade_negocio = 180)
41. 0.000 0.000 ↓ 0.0 0

Index Scan using produto_pkey on produto pro_1 (cost=0.42..2.64 rows=1 width=32) (never executed)

  • Index Cond: (pro_cd_produto = bic_1.bic_cd_produto)
42. 0.000 0.000 ↓ 0.0 0

Index Scan using bomba_pkey on bomba bom_1 (cost=0.28..1.85 rows=1 width=13) (never executed)

  • Index Cond: (bom_cd_bomba = bic_1.bic_cd_bomba)
43. 0.000 0.000 ↓ 0.0 0

Index Scan using caixa_pkey on caixa cai_1 (cost=0.42..2.65 rows=1 width=12) (never executed)

  • Index Cond: (cai_cd_caixa = 1506645)
  • Filter: (cai_cd_unidade_negocio = 180)
44. 0.006 687.585 ↑ 11.3 3 1

Subquery Scan on *SELECT* 3 (cost=3.83..3,927,053.03 rows=34 width=321) (actual time=51.194..687.585 rows=3 loops=1)

45. 0.295 687.579 ↑ 11.3 3 1

Nested Loop Anti Join (cost=3.83..3,927,052.18 rows=34 width=153) (actual time=51.191..687.579 rows=3 loops=1)

  • Join Filter: (abt_3.abt_cd_bico = bic_2.bic_cd_bico)
  • Rows Removed by Join Filter: 3744
46. 2.326 680.790 ↑ 1.0 34 1

Nested Loop (cost=1.70..3,926,329.42 rows=34 width=93) (actual time=44.747..680.790 rows=34 loops=1)

  • Join Filter: (bic_2.bic_cd_bomba = bom_2.bom_cd_bomba)
  • Rows Removed by Join Filter: 33542
47. 0.072 676.764 ↑ 1.0 34 1

Nested Loop (cost=1.70..3,925,252.72 rows=34 width=88) (actual time=44.231..676.764 rows=34 loops=1)

48. 0.059 2.710 ↑ 1.0 34 1

Nested Loop (cost=0.70..7,076.46 rows=34 width=52) (actual time=0.241..2.710 rows=34 loops=1)

49. 0.047 2.447 ↑ 1.0 34 1

Nested Loop (cost=0.28..6,986.70 rows=34 width=24) (actual time=0.234..2.447 rows=34 loops=1)

50. 2.366 2.366 ↑ 1.0 34 1

Index Scan using bico_pkey on bico bic_2 (cost=0.28..6,986.01 rows=34 width=16) (actual time=0.213..2.366 rows=34 loops=1)

  • Filter: (bic_cd_unidade_negocio = 180)
  • Rows Removed by Filter: 6586
51. 0.034 0.034 ↑ 1.0 1 34

CTE Scan on caixa_meta cm (cost=0.00..0.02 rows=1 width=8) (actual time=0.001..0.001 rows=1 loops=34)

52. 0.204 0.204 ↑ 1.0 1 34

Index Scan using produto_pkey on produto pro_2 (cost=0.42..2.64 rows=1 width=32) (actual time=0.006..0.006 rows=1 loops=34)

  • Index Cond: (pro_cd_produto = bic_2.bic_cd_produto)
53. 0.102 673.982 ↑ 1.0 1 34

Limit (cost=1.00..115,240.46 rows=1 width=36) (actual time=19.821..19.823 rows=1 loops=34)

54. 2.176 673.880 ↑ 1.0 1 34

GroupAggregate (cost=1.00..115,240.46 rows=1 width=36) (actual time=19.820..19.820 rows=1 loops=34)

  • Group Key: 0
55. 45.050 671.704 ↑ 10.4 76 34

Nested Loop (cost=1.00..115,230.60 rows=788 width=36) (actual time=0.558..19.756 rows=76 loops=34)

56. 9.554 62.832 ↓ 3.0 2,369 34

Nested Loop (cost=0.99..113,646.71 rows=788 width=1,399) (actual time=0.016..1.848 rows=2,369 loops=34)

57. 0.170 0.918 ↑ 24.8 14 34

Nested Loop (cost=0.43..397.79 rows=347 width=8) (actual time=0.011..0.027 rows=14 loops=34)

58. 0.034 0.034 ↑ 1.0 1 34

CTE Scan on caixa_meta cm_2 (cost=0.00..0.02 rows=1 width=16) (actual time=0.000..0.001 rows=1 loops=34)

59. 0.714 0.714 ↑ 24.8 14 34

Index Scan using caixa_idx_unidade_negocio_dt_movimento_ts_abertura on caixa cai_3 (cost=0.43..394.30 rows=347 width=20) (actual time=0.008..0.021 rows=14 loops=34)

  • Index Cond: ((cai_cd_unidade_negocio = 180) AND (cai_dt_movimento >= (cm_2.min_dt_movimento - 2)) AND (cai_dt_movimento <= (cm_2.max_dt_movimento + 2)) AND (cai_ts_abertura < cm_2.min_ts_abertura))
60. 52.360 52.360 ↓ 21.1 169 476

Index Scan using venda_idx_caixa on venda ven_2 (cost=0.56..326.29 rows=8 width=1,407) (actual time=0.006..0.110 rows=169 loops=476)

  • Index Cond: (ven_cd_caixa = cai_3.cai_cd_caixa)
  • Filter: ((ven_cd_unidade_negocio = 180) AND (ven_fl_cancelada = 'N'::bpchar))
  • Rows Removed by Filter: 2
61. 563.822 563.822 ↓ 0.0 0 80,546

Function Scan on jsonb_array_elements vei_2 (cost=0.01..2.00 rows=1 width=32) (actual time=0.007..0.007 rows=0 loops=80,546)

  • Filter: (((value ->> 'abt_cd_bico'::text))::integer = bic_2.bic_cd_bico)
  • Rows Removed by Filter: 1
62. 1.348 1.700 ↑ 2.0 988 34

Materialize (cost=0.00..57.14 rows=2,009 width=13) (actual time=0.001..0.050 rows=988 loops=34)

63. 0.352 0.352 ↑ 1.1 1,901 1

Seq Scan on bomba bom_2 (cost=0.00..47.09 rows=2,009 width=13) (actual time=0.022..0.352 rows=1,901 loops=1)

64. 0.223 6.494 ↓ 55.5 111 34

Materialize (cost=2.12..721.75 rows=2 width=4) (actual time=0.002..0.191 rows=111 loops=34)

65. 0.254 6.271 ↓ 309.0 618 1

Nested Loop (cost=2.12..721.74 rows=2 width=4) (actual time=0.063..6.271 rows=618 loops=1)

66. 0.387 4.013 ↓ 334.0 668 1

Nested Loop (cost=1.56..716.39 rows=2 width=4) (actual time=0.050..4.013 rows=668 loops=1)

67. 0.082 1.841 ↓ 595.0 595 1

Nested Loop (cost=0.99..350.42 rows=1 width=4) (actual time=0.026..1.841 rows=595 loops=1)

68. 0.118 0.569 ↓ 595.0 595 1

Nested Loop (cost=0.56..347.77 rows=1 width=8) (actual time=0.017..0.569 rows=595 loops=1)

  • Join Filter: ((ven_1.ven_dt_fiscal >= (cm_1.min_dt_movimento - 2)) AND (ven_1.ven_dt_fiscal <= (cm_1.max_dt_movimento + 2)))
69. 0.001 0.001 ↑ 1.0 1 1

CTE Scan on caixa_meta cm_1 (cost=0.00..0.02 rows=1 width=8) (actual time=0.001..0.001 rows=1 loops=1)

70. 0.450 0.450 ↓ 74.4 595 1

Index Scan using venda_idx_caixa on venda ven_1 (cost=0.56..347.59 rows=8 width=12) (actual time=0.014..0.450 rows=595 loops=1)

  • Index Cond: (ven_cd_caixa = 1506645)
  • Filter: ((ven_cd_unidade_negocio = 180) AND (ven_fl_cancelada = 'N'::bpchar))
  • Rows Removed by Filter: 3
71. 1.190 1.190 ↑ 1.0 1 595

Index Only Scan using caixa_pkey on caixa cai_2 (cost=0.42..2.64 rows=1 width=4) (actual time=0.002..0.002 rows=1 loops=595)

  • Index Cond: (cai_cd_caixa = 1506645)
  • Heap Fetches: 595
72. 1.785 1.785 ↑ 412.0 1 595

Index Scan using venda_item_idx_venda_rebuild_1 on venda_item vei_1 (cost=0.57..361.85 rows=412 width=8) (actual time=0.003..0.003 rows=1 loops=595)

  • Index Cond: (vei_cd_venda = ven_1.ven_cd_venda)
73. 2.004 2.004 ↑ 1.0 1 668

Index Scan using abastecimento_abt_cd_venda_item_key on abastecimento abt_3 (cost=0.57..2.67 rows=1 width=8) (actual time=0.003..0.003 rows=1 loops=668)

  • Index Cond: (abt_cd_venda_item = vei_1.vei_cd_venda_item)
74.          

SubPlan (for GroupAggregate)

75. 0.027 9.486 ↑ 1.0 1 3

Hash Join (cost=351.04..49,559.68 rows=1 width=0) (actual time=3.162..3.162 rows=1 loops=3)

  • Hash Cond: (vei_6.vei_cd_venda = ven_6.ven_cd_venda)
76. 0.016 8.574 ↑ 2,711.3 3 3

Nested Loop (cost=1.14..49,188.42 rows=8,134 width=4) (actual time=2.849..2.858 rows=3 loops=3)

77. 1.974 8.526 ↑ 2,711.3 3 3

Nested Loop (cost=0.57..26,886.87 rows=8,134 width=4) (actual time=2.839..2.842 rows=3 loops=3)

  • Join Filter: (abtc.abt_dt_abastecimento >= cm_5.min_dt_movimento)
  • Rows Removed by Join Filter: 3810
78. 0.000 0.000 ↑ 1.0 1 3

CTE Scan on caixa_meta cm_5 (cost=0.00..0.02 rows=1 width=4) (actual time=0.000..0.000 rows=1 loops=3)

79. 6.552 6.552 ↑ 6.4 3,813 3

Index Scan using abastecimento_idx_cd_bico on abastecimento abtc (cost=0.57..26,581.82 rows=24,402 width=8) (actual time=0.009..2.184 rows=3,813 loops=3)

  • Index Cond: (abt_cd_bico = abt.bico)
80. 0.032 0.032 ↑ 1.0 1 8

Index Scan using venda_item_pkey on venda_item vei_6 (cost=0.57..2.74 rows=1 width=8) (actual time=0.004..0.004 rows=1 loops=8)

  • Index Cond: (vei_cd_venda_item = abtc.abt_cd_venda_item)
81. 0.210 0.885 ↓ 1.9 598 3

Hash (cost=346.04..346.04 rows=309 width=4) (actual time=0.295..0.295 rows=598 loops=3)

  • Buckets: 1024 Batches: 1 Memory Usage: 30kB
82. 0.675 0.675 ↓ 1.9 598 3

Index Scan using venda_idx_caixa on venda ven_6 (cost=0.56..346.04 rows=309 width=4) (actual time=0.007..0.225 rows=598 loops=3)

  • Index Cond: (ven_cd_caixa = abt.caixa)
83. 0.201 15.812 ↑ 1.0 1 67

Aggregate (cost=12.92..12.93 rows=1 width=32) (actual time=0.236..0.236 rows=1 loops=67)

84. 0.335 15.611 ↓ 10.0 10 67

Nested Loop (cost=2.12..12.91 rows=1 width=6) (actual time=0.065..0.233 rows=10 loops=67)

  • Join Filter: (cai_4.cai_ts_abertura > cm_3.max_ts_abertura)
  • Rows Removed by Join Filter: 1
85. 0.179 15.276 ↓ 11.0 11 67

Nested Loop (cost=2.12..12.88 rows=1 width=14) (actual time=0.033..0.228 rows=11 loops=67)

86. 0.371 13.601 ↓ 11.0 11 67

Nested Loop (cost=1.70..10.35 rows=1 width=14) (actual time=0.030..0.203 rows=11 loops=67)

87. 0.365 7.839 ↓ 27.0 27 67

Nested Loop (cost=1.14..7.61 rows=1 width=14) (actual time=0.017..0.117 rows=27 loops=67)

88. 2.077 2.077 ↓ 27.0 27 67

Index Scan using abt_unidade_dtfiscal_bico on abastecimento b (cost=0.57..4.83 rows=1 width=14) (actual time=0.012..0.031 rows=27 loops=67)

  • Index Cond: ((abt_cd_bico = abt.bico) AND (abt_cd_unidade_negocio = 180) AND (abt_dt_fiscal >= (max(abt.maior_data))) AND (abt_vl_encerrante < (max(abt.encerrante_final_abt))) AND (abt_cd_substituicao = abt.substituicao))
89. 5.397 5.397 ↑ 1.0 1 1,799

Index Scan using venda_item_pkey on venda_item vei_3 (cost=0.57..2.79 rows=1 width=8) (actual time=0.003..0.003 rows=1 loops=1,799)

  • Index Cond: (vei_cd_venda_item = b.abt_cd_venda_item)
  • Filter: (vei_cd_produto = abt.produto)
90. 5.391 5.391 ↓ 0.0 0 1,797

Index Scan using venda_pkey on venda ven_3 (cost=0.56..2.74 rows=1 width=12) (actual time=0.003..0.003 rows=0 loops=1,797)

  • Index Cond: (ven_cd_venda = vei_3.vei_cd_venda)
  • Filter: ((ven_cd_caixa <> 1506645) AND (ven_cd_unidade_negocio = 180) AND (ven_fl_cancelada = 'N'::bpchar))
  • Rows Removed by Filter: 1
91. 1.496 1.496 ↑ 1.0 1 748

Index Scan using caixa_pkey on caixa cai_4 (cost=0.42..2.53 rows=1 width=16) (actual time=0.002..0.002 rows=1 loops=748)

  • Index Cond: (cai_cd_caixa = ven_3.ven_cd_caixa)
  • Filter: (cai_cd_unidade_negocio = 180)
92. 0.000 0.000 ↑ 1.0 1 748

CTE Scan on caixa_meta cm_3 (cost=0.00..0.02 rows=1 width=8) (actual time=0.000..0.000 rows=1 loops=748)

93. 0.067 375.401 ↑ 1.0 1 67

Aggregate (cost=1,348.74..1,348.75 rows=1 width=64) (actual time=5.603..5.603 rows=1 loops=67)

94. 0.670 375.334 ↓ 0.0 0 67

Nested Loop (cost=2.69..1,348.73 rows=1 width=19) (actual time=5.340..5.602 rows=0 loops=67)

  • Join Filter: (b_1.abt_dt_abastecimento < cm_4.min_dt_movimento)
  • Rows Removed by Join Filter: 19
95. 2.695 374.664 ↓ 19.0 19 67

Nested Loop Semi Join (cost=2.69..1,348.70 rows=1 width=23) (actual time=0.614..5.592 rows=19 loops=67)

  • Join Filter: (((vei_5.value ->> 'abt_ts_abastecimento'::text))::date >= cai_5.cai_dt_movimento)
  • Rows Removed by Join Filter: 0
96. 0.436 128.305 ↓ 19.0 19 67

Nested Loop (cost=2.12..375.38 rows=1 width=35) (actual time=0.218..1.915 rows=19 loops=67)

97. 0.000 125.357 ↓ 19.0 19 67

Nested Loop (cost=1.70..372.73 rows=1 width=35) (actual time=0.216..1.871 rows=19 loops=67)

98. 0.871 101.237 ↓ 126.0 126 67

Nested Loop (cost=1.13..369.97 rows=1 width=12) (actual time=0.025..1.511 rows=126 loops=67)

99. 20.636 20.636 ↓ 74.4 595 67

Index Scan using venda_idx_caixa on venda ven_4 (cost=0.56..347.59 rows=8 width=12) (actual time=0.005..0.308 rows=595 loops=67)

  • Index Cond: (ven_cd_caixa = 1506645)
  • Filter: ((ven_cd_unidade_negocio = 180) AND (ven_fl_cancelada = 'N'::bpchar))
  • Rows Removed by Filter: 3
100. 79.730 79.730 ↓ 0.0 0 39,865

Index Scan using idx_tst_01_rebuild_1 on venda_item vei_4 (cost=0.57..2.79 rows=1 width=8) (actual time=0.002..0.002 rows=0 loops=39,865)

  • Index Cond: ((vei_cd_venda = ven_4.ven_cd_venda) AND (vei_cd_produto = abt.produto))
101. 25.242 25.242 ↓ 0.0 0 8,414

Index Scan using abastecimento_abt_cd_venda_item_key on abastecimento b_1 (cost=0.57..2.75 rows=1 width=35) (actual time=0.003..0.003 rows=0 loops=8,414)

  • Index Cond: (abt_cd_venda_item = vei_4.vei_cd_venda_item)
  • Filter: ((abt_cd_unidade_negocio = 180) AND (abt_cd_bico = abt.bico))
  • Rows Removed by Filter: 1
102. 2.512 2.512 ↑ 1.0 1 1,256

Index Scan using caixa_pkey on caixa cai_5 (cost=0.42..2.65 rows=1 width=12) (actual time=0.002..0.002 rows=1 loops=1,256)

  • Index Cond: (cai_cd_caixa = 1506645)
  • Filter: (cai_cd_unidade_negocio = 180)
103. 13.826 243.664 ↑ 309.0 1 1,256

Nested Loop (cost=0.57..967.14 rows=309 width=36) (actual time=0.188..0.194 rows=1 loops=1,256)

104. 17.584 17.584 ↑ 12.9 24 1,256

Index Scan using venda_idx_caixa on venda ven_5 (cost=0.56..346.04 rows=309 width=1,403) (actual time=0.005..0.014 rows=24 loops=1,256)

  • Index Cond: (ven_cd_caixa = 1506645)
105. 212.254 212.254 ↓ 0.0 0 30,322

Function Scan on jsonb_array_elements vei_5 (cost=0.01..2.00 rows=1 width=32) (actual time=0.007..0.007 rows=0 loops=30,322)

  • Filter: (((value ->> 'abt_cd_bico'::text))::integer = abt.bico)
  • Rows Removed by Filter: 1
106. 0.000 0.000 ↑ 1.0 1 1,256

CTE Scan on caixa_meta cm_4 (cost=0.00..0.02 rows=1 width=4) (actual time=0.000..0.000 rows=1 loops=1,256)

Planning time : 15.800 ms
Execution time : 1,107.694 ms