X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 15322D1B8A2 for ; Mon, 25 Aug 2003 09:18:03 -0300 (ADT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 97745-04 for ; Mon, 25 Aug 2003 09:17:35 -0300 (ADT) Received: from host2.hostseguro.com (unknown [200.198.188.133]) by svr1.postgresql.org (Postfix) with ESMTP id 9F601D1BA21 for ; Mon, 25 Aug 2003 09:17:31 -0300 (ADT) Received: from cpanel by host2.hostseguro.com with local (Exim 4.20) id 19rGHd-0006St-5h for pgsql-admin@postgresql.org; Mon, 25 Aug 2003 09:17:17 -0300 Received: from 200.203.33.227 ([200.203.33.227]) by sistemica.info (IMP) with HTTP for ; Mon, 25 Aug 2003 09:17:17 -0300 Message-ID: <1061813837.3f49fe4d20844@sistemica.info> Date: Mon, 25 Aug 2003 09:17:17 -0300 From: Rhaoni Chiu Pereira To: Lista PostgreSQL Subject: Query to slow MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: Internet Messaging Program (IMP) 3.2.1 X-Originating-IP: 200.203.33.227 X-MailScanner-Information: Verificado pelo McAfee VirusScan / Scanned by McAfee VirusScan X-MailScanner: Nao infectado / Found to be clean X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - host2.hostseguro.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [32001 32001] / [47 12] X-AntiAbuse: Sender Address Domain - sistemica.info X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/278 X-Sequence-Number: 9999 Hi List, As I said before, I'm not a DBA " yet" , but I'm learning ... and I already have a PostgreSQL running, so I have to ask some help... I got a SQL as folows : SELECT /*+ */ ftnfco00.estado_cliente , ftcofi00.grupo_faturamento , SUM( DECODE( ftcofi00.atual_fatura, '-', -(NVL (ftnfpr00.qtde_duzias,0)), '+', NVL(ftnfpr00.qtde_duzias,0), 0) ) , SUM( DECODE( ftcofi00.atual_fatura, '-', -(NVL(ftnfpr00.vlr_liquido,0)), '+', NVL(ftnfpr00.vlr_liquido,0), 0) ) , ftprod00.tipo_cadastro||ftprod00.codigo_produto||'||'||gsames00.ano_mes , ftprod00.descricao_produto||'||'||gsames00.descricao , DIVIDE( SUM( DECODE( ftcofi00.atual_fatura, '-', -(NVL (ftnfpr00.vlr_liquido,0)), '+', NVL(ftnfpr00.vlr_liquido,0), 0) *ftnfpr00.margem_comercial ), SUM( DECODE( ftcofi00.atual_fatura, '-', -(NVL (ftnfpr00.vlr_liquido,0)), '+', NVL(ftnfpr00.vlr_liquido,0), 0)) ) , SUM( DECODE( ftcofi00.nf_prodgratis, 'S', NVL(ftnfpr00.qtde_duzias,0), 0 ) ) , SUM( DECODE( ftcofi00.nf_prodgratis, 'S', NVL(ftnfpr00.vlr_liquido,0), 0 ) ) FROM ftprod00 , ftnfco00 , ftcgma00 , ftcgca00 , ftspro00 , ftclcr00 , gsames00 , ftcofi00 , ftrepr00 , gsesta00 , ftsupv00 , ftgrep00 , ftclgr00 , ftband00 , fttcli00 , ftredc00 , ftnfpr00 WHERE ftnfco00.emp = 909 AND ftnfpr00.fil IN ('101') AND ftnfco00.situacao_nf = 'N' AND TO_CHAR(ftnfco00.data_emissao,'YYYYMM') >= '200208' AND TO_CHAR(ftnfco00.data_emissao,'YYYYMM') <= '200304' AND ftcofi00.grupo_faturamento >= '01' AND (ftcofi00.atual_fatura IN ('+','-') OR ftcofi00.nf_prodgratis = 'S') AND ftcgma00.emp = ftprod00.emp AND ftcgma00.fil = ftprod00.fil AND ftcgma00.codigo = ftprod00.cla_marca AND ftcgca00.emp = ftprod00.emp AND ftcgca00.fil = ftprod00.fil AND ftcgca00.codigo = ftprod00.cla_categoria AND ftspro00.emp = ftprod00.emp AND ftspro00.fil = ftprod00.fil AND ftspro00.codigo = ftprod00.situacao AND ftclcr00.emp = ftnfco00.emp AND ftclcr00.fil = ftnfco00.empfil AND ftclcr00.tipo_cadastro = ftnfco00.tipo_cad_clicre AND ftclcr00.codigo = ftnfco00.cod_cliente AND gsames00.ano_mes = TO_CHAR(ftnfco00.data_emissao,'YYYYMM') AND ftcofi00.emp = ftnfco00.emp AND ftcofi00.fil = ftnfco00.empfil AND ftcofi00.codigo_fiscal = ftnfco00.cod_fiscal AND ftrepr00.emp = ftnfco00.emp AND ftrepr00.fil = ftnfco00.empfil AND ftrepr00.codigo_repr = ftnfco00.cod_repres AND gsesta00.estado_sigla = ftnfco00.estado_cliente AND ftsupv00.emp = ftrepr00.emp AND ftsupv00.fil = ftrepr00.fil AND ftsupv00.codigo_supervisor = ftrepr00.codigo_supervisor AND ftgrep00.emp = ftrepr00.emp AND ftgrep00.fil = ftrepr00.fil AND ftgrep00.codigo_grupo_rep = ftrepr00.codigo_grupo_rep AND ftclgr00.emp = ftclcr00.emp AND ftclgr00.fil = ftclcr00.fil AND ftclgr00.codigo = ftclcr00.codigo_grupo_cliente AND ftband00.emp = ftclcr00.emp AND ftband00.fil = ftclcr00.fil AND ftband00.codigo = ftclcr00.bandeira_cliente AND fttcli00.emp = ftclcr00.emp AND fttcli00.fil = ftclcr00.fil AND fttcli00.cod_tipocliente = ftclcr00.codigo_tipo_cliente AND ftredc00.emp = ftclcr00.emp AND ftredc00.fil = ftclcr00.fil AND ftredc00.tipo_contribuinte = ftclcr00.tipo_contribuinte AND ftredc00.codigo_rede = ftclcr00.codigo_rede AND gsesta00.estado_sigla = ftclcr00.emp_estado AND ftnfco00.emp = ftnfpr00.emp AND ftnfco00.fil = ftnfpr00.fil AND ftnfco00.nota_fiscal = ftnfpr00.nota_fiscal AND ftnfco00.serie = ftnfpr00.serie AND ftnfco00.data_emissao = ftnfpr00.data_emissao AND ftprod00.emp = ftnfpr00.emp AND ftprod00.fil = ftnfpr00.empfil AND ftprod00.tipo_cadastro = ftnfpr00.tipo_cad_promat AND ftprod00.codigo_produto= ftnfpr00.cod_produto GROUP BY ftnfco00.estado_cliente , ftcofi00.grupo_faturamento , ftprod00.tipo_cadastro||ftprod00.codigo_produto||'||'||gsames00.ano_mes , ftprod00.descricao_produto||'||'||gsames00.descricao I have created the decode, NVL and DIVIDE functions.... the problem is that the where condition makes this query to slow ( about 4 min ) and the same query in my Oracle database takes less than 40 seconds. I have tried to isolate the problem taking off some fields and I left justa the two first fields in the query ( ftnfco00.estado_cliente , ftcofi00.grupo_faturamento ) and it still taking almost 4 min to return. Does anyone have a hint to give me to make it faster ? Atenciosamente, Rhaoni Chiu Pereira Sistêmica Computadores Visite-nos na Web: http://sistemica.info Fone/Fax : +55 51 3328 1122