                                                                                                                                                                        QUERY PLAN                                                                                                                                                                        
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Aggregate  (cost=100026328.98..100026329.01 rows=1 width=818) (actual time=106092.48..112238.80 rows=376 loops=1)
   ->  Group  (cost=100026328.98..100026328.99 rows=1 width=818) (actual time=106050.06..106661.82 rows=24226 loops=1)
         ->  Sort  (cost=100026328.98..100026328.98 rows=1 width=818) (actual time=106050.03..106094.99 rows=24226 loops=1)
               Sort Key: ftnfco00.estado_cliente, ftcofi00.grupo_faturamento, ((ftprod00.tipo_cadastro)::text || (ftprod00.codigo_produto)::text), ftprod00.descricao_produto
               ->  Nested Loop  (cost=100025735.51..100026328.97 rows=1 width=818) (actual time=94979.72..104033.78 rows=24226 loops=1)
                     Join Filter: (("inner".fil = "outer".fil) AND ("inner".emp = "outer".emp))
                     ->  Nested Loop  (cost=100025735.51..100026324.45 rows=1 width=791) (actual time=94971.00..102469.26 rows=24226 loops=1)
                           Join Filter: (("inner".emp = "outer".emp) AND ("inner".fil = "outer".empfil) AND ("inner".codigo_supervisor = "outer".codigo_supervisor))
                           ->  Nested Loop  (cost=100025735.51..100026319.76 rows=1 width=759) (actual time=94962.36..99991.74 rows=24226 loops=1)
                                 Join Filter: ("inner".estado_sigla = "outer".estado_cliente)
                                 ->  Nested Loop  (cost=100025735.51..100026316.19 rows=1 width=753) (actual time=94946.43..97157.96 rows=24226 loops=1)
                                       Join Filter: (("inner".fil = "outer".fil) AND ("inner".emp = "outer".emp) AND ("outer".codigo = "inner".cla_marca))
                                       ->  Index Scan using ftcgma00_pkey on ftcgma00  (cost=0.00..4.68 rows=1 width=32) (actual time=4.00..4.01 rows=1 loops=1)
                                       ->  Materialize  (cost=100026311.50..100026311.50 rows=1 width=721) (actual time=94942.29..95103.06 rows=24226 loops=1)
                                             ->  Nested Loop  (cost=100025735.51..100026311.50 rows=1 width=721) (actual time=83572.42..94644.51 rows=24226 loops=1)
                                                   Join Filter: (("outer".emp = "inner".emp) AND ("outer".fil = "inner".fil) AND ("outer".codigo = "inner".cla_categoria))
                                                   ->  Nested Loop  (cost=100025735.51..100026305.73 rows=1 width=631) (actual time=83565.45..91392.74 rows=24226 loops=1)
                                                         Join Filter: (("inner".emp = "outer".emp) AND ("outer".codigo_grupo_rep = "inner".codigo_grupo_rep))
                                                         ->  Nested Loop  (cost=100025735.51..100026300.30 rows=1 width=578) (actual time=83558.12..88817.53 rows=24226 loops=1)
                                                               Join Filter: (("inner".emp = "outer".emp) AND ("inner".fil = "outer".empfil))
                                                               ->  Nested Loop  (cost=100025735.51..100026295.79 rows=1 width=545) (actual time=83551.88..86597.21 rows=24226 loops=1)
                                                                     Join Filter: (("inner".emp = "outer".emp) AND ("inner".fil = "outer".empfil) AND ("inner".codigo = "outer".bandeira_cliente))
                                                                     ->  Nested Loop  (cost=100025735.51..100026291.09 rows=1 width=513) (actual time=83539.92..84910.68 rows=24226 loops=1)
                                                                           Join Filter: (("outer".emp = "inner".emp) AND ("outer".fil = "inner".empfil))
                                                                           ->  Index Scan using ftgrep00_pkey on ftgrep00  (cost=0.00..4.68 rows=1 width=32) (actual time=6.90..6.91 rows=1 loops=1)
                                                                           ->  Materialize  (cost=100026286.40..100026286.40 rows=1 width=481) (actual time=83532.93..83684.60 rows=24226 loops=1)
                                                                                 ->  Nested Loop  (cost=100025735.51..100026286.40 rows=1 width=481) (actual time=2487.21..83280.50 rows=24226 loops=1)
                                                                                       Join Filter: (("inner".ano_mes)::text = to_char("outer".data_emissao, 'YYYYMM'::text))
                                                                                       ->  Nested Loop  (cost=25735.51..26274.10 rows=1 width=471) (actual time=2485.76..8266.04 rows=24226 loops=1)
                                                                                             Join Filter: (("inner".empfil = "outer".fil) AND ("inner".emp = "outer".emp))
                                                                                             ->  Nested Loop  (cost=25735.51..26213.67 rows=10 width=359) (actual time=2449.03..3656.00 rows=7705 loops=1)
                                                                                                   Join Filter: (("inner".emp = "outer".emp) AND ("inner".fil = "outer".empfil))
                                                                                                   ->  Nested Loop  (cost=25735.51..26156.31 rows=10 width=319) (actual time=2410.02..2664.68 rows=7705 loops=1)
                                                                                                         Join Filter: (("outer".emp = "inner".emp) AND ("outer".fil = "inner".empfil) AND ("outer".codigo = "inner".codigo_grupo_cliente))
                                                                                                         ->  Index Scan using ftclgr00_pkey on ftclgr00  (cost=0.00..4.68 rows=1 width=32) (actual time=9.20..9.21 rows=1 loops=1)
                                                                                                         ->  Materialize  (cost=26151.46..26151.46 rows=10 width=287) (actual time=2400.75..2415.80 rows=7705 loops=1)
                                                                                                               ->  Nested Loop  (cost=25735.51..26151.46 rows=10 width=287) (actual time=1349.89..2369.24 rows=7705 loops=1)
                                                                                                                     Join Filter: (("inner".emp = "outer".emp) AND ("inner".emp_estado = "outer".estado_cliente))
                                                                                                                     ->  Merge Join  (cost=25735.51..25892.65 rows=44 width=193) (actual time=1322.36..1452.94 rows=7705 loops=1)
                                                                                                                           Merge Cond: (("outer".emp = "inner".emp) AND ("outer".fil = "inner".empfil) AND ("outer".codigo_fiscal = "inner".cod_fiscal))
                                                                                                                           ->  Index Scan using ftcofi00_pkey on ftcofi00  (cost=0.00..152.73 rows=72 width=52) (actual time=21.60..27.46 rows=64 loops=1)
                                                                                                                                 Filter: ((grupo_faturamento >= '01'::character varying) AND ((atual_fatura = '+'::character varying) OR (atual_fatura = '-'::character varying) OR (nf_prodgratis = 'S'::character varying)))
                                                                                                                           ->  Sort  (cost=25735.51..25736.25 rows=294 width=141) (actual time=1298.22..1310.44 rows=9453 loops=1)
                                                                                                                                 Sort Key: ftnfco00.emp, ftnfco00.empfil, ftnfco00.cod_fiscal
                                                                                                                                 ->  Nested Loop  (cost=0.00..25723.46 rows=294 width=141) (actual time=652.62..1085.08 rows=9453 loops=1)
                                                                                                                                       Join Filter: ("inner".emp = "outer".emp)
                                                                                                                                       ->  Index Scan using ftcgca00_pkey on ftcgca00  (cost=0.00..4.68 rows=1 width=32) (actual time=23.78..23.79 rows=1 loops=1)
                                                                                                                                       ->  Index Scan using ftnfco02 on ftnfco00  (cost=0.00..25715.11 rows=294 width=109) (actual time=628.80..973.69 rows=9453 loops=1)
                                                                                                                                             Filter: ((emp = 909::numeric) AND (situacao_nf = 'N'::character varying) AND (to_char(data_emissao, 'YYYYMM'::text) >= '200208'::text) AND (to_char(data_emissao, 'YYYYMM'::text) <= '200303'::text))
                                                                                                                     ->  Index Scan using ftclcr00_pkey on ftclcr00  (cost=0.00..5.83 rows=1 width=94) (actual time=0.09..0.09 rows=1 loops=7705)
                                                                                                                           Index Cond: ((ftclcr00.emp = "outer".emp) AND (ftclcr00.fil = "outer".empfil) AND (ftclcr00.tipo_cadastro = "outer".tipo_cad_clicre) AND (ftclcr00.codigo = "outer".cod_cliente))
                                                                                                   ->  Index Scan using ftredc00_pkey on ftredc00  (cost=0.00..5.83 rows=1 width=40) (actual time=0.09..0.09 rows=1 loops=7705)
                                                                                                         Index Cond: ((ftredc00.emp = "outer".emp) AND (ftredc00.fil = "outer".fil) AND (ftredc00.tipo_contribuinte = "outer".tipo_contribuinte) AND (ftredc00.codigo_rede = "outer".codigo_rede))
                                                                                             ->  Index Scan using ftnfpr00_pkey on ftnfpr00  (cost=0.00..5.95 rows=1 width=112) (actual time=0.22..0.48 rows=3 loops=7705)
                                                                                                   Index Cond: (("outer".emp = ftnfpr00.emp) AND ("outer".fil = ftnfpr00.fil) AND (ftnfpr00.fil = 101::numeric) AND ("outer".nota_fiscal = ftnfpr00.nota_fiscal) AND ("outer".serie = ftnfpr00.serie) AND ("outer".data_emissao = ftnfpr00.data_emissao))
                                                                                       ->  Seq Scan on gsames00  (cost=100000000.00..100000006.72 rows=372 width=10) (actual time=0.01..0.88 rows=372 loops=24226)
                                                                     ->  Index Scan using ftband00_pkey on ftband00  (cost=0.00..4.68 rows=1 width=32) (actual time=0.01..0.02 rows=1 loops=24226)
                                                               ->  Index Scan using fttcli00_pkey on fttcli00  (cost=0.00..4.50 rows=1 width=33) (actual time=0.03..0.03 rows=1 loops=24226)
                                                                     Index Cond: ((fttcli00.emp = "outer".emp) AND (fttcli00.fil = "outer".fil) AND (fttcli00.cod_tipocliente = "outer".codigo_tipo_cliente))
                                                         ->  Index Scan using ftrepr00_pkey on ftrepr00  (cost=0.00..5.41 rows=1 width=53) (actual time=0.04..0.04 rows=1 loops=24226)
                                                               Index Cond: ((ftrepr00.emp = "outer".emp) AND (ftrepr00.fil = "outer".empfil) AND (ftrepr00.codigo_repr = "outer".cod_repres))
                                                   ->  Index Scan using ftprod00_pkey on ftprod00  (cost=0.00..5.74 rows=1 width=90) (actual time=0.06..0.06 rows=1 loops=24226)
                                                         Index Cond: ((ftprod00.emp = "outer".emp) AND (ftprod00.fil = "outer".empfil) AND (ftprod00.tipo_cadastro = "outer".tipo_cad_promat) AND (ftprod00.codigo_produto = "outer".cod_produto))
                                 ->  Index Scan using gsesta00_pkey on gsesta00  (cost=0.00..3.55 rows=1 width=6) (actual time=0.03..0.03 rows=1 loops=24226)
                                       Index Cond: (gsesta00.estado_sigla = "outer".emp_estado)
                           ->  Index Scan using ftsupv00_pkey on ftsupv00  (cost=0.00..4.68 rows=1 width=32) (actual time=0.01..0.02 rows=1 loops=24226)
                     ->  Index Scan using ftspro00_pkey on ftspro00  (cost=0.00..4.50 rows=1 width=27) (actual time=0.03..0.03 rows=1 loops=24226)
                           Index Cond: ((ftspro00.emp = "outer".emp) AND (ftspro00.fil = "outer".fil) AND (ftspro00.codigo = "outer".situacao))
 Total runtime: 112287.10 msec
(69 rows)

