distinct + group by ?! Note que você está agrupando alguns campos 2
vezes. Procure só usar o "group by" (ou só o "distinct").
De resto, o pessoal já falou: dê um explain e crie índices com base na
resposta do explain; use JOINs para ficar mais legível e deixar
explícito como o postgresql deve relacionar as tabelas (senão ele vai
tentar usar o geqo); etc.
Sds,
Daniel Loureiro.
João Paulo escreveu:
Olá pessoal,
Tenho a seguinte query que funciona perfeitamente, porém acho que ela
está demorando mais para executar. Passei pelo analyze e onde a query
demora mais é quando são feitos os dois in's quase no final da query,
alguem sabe me dizer se tenho como otimizar esta query para ela ficar
mas rápida.
select distinct
tabela1.campo1,t1.campo5,t1.campo6,tabela3.campo3,tabela6.campo2,count(*)
from tabela1,tabela2,tabela3,tabela4 t1,tabela4
t2,tabela5,tabela6,tabela7 t3,tabela7 t4
where tabela1.campo2=tabela2.campo2
and tabela1.campo3=tabela2.campo3
and tabela2.campo4='U'
and tabela1.datal between '2006-06-01' and '2006-06-30'
and tabela2.campo5=tabela3.campo3
and tabela3.campo4='A'
and tabela1.campo5=t1.campo6
and t1.campo7='A'
and t1.campo6=t2.campo5
and tabela1.campo8=tabela5.campo2
and tabela5.campo3=tabela6.campo2
and tabela1.campo1=t3.campo1
and t3.campo2=t4.campo3
and t3.campo2 in (1,2,3,4,5,6,7,8,9,10,11,12,13,14)
and t4.campo3 in (1000,1001,1002,1003,1004,1005)
group by tabela1.campo1,t1.campo5,t1.campo6,tabela3.campo3,tabela6.campo2;
João Paulo.
--------------------------
E-mail Seguro Vetorial.net
Mensagem classificada como NÃO-SPAM. Para classificar como SPAM,
encaminhe para [EMAIL PROTECTED]
Chave de Identificação: 26110,465b03d5786841300320092
------------------------------------------------------------------------
_______________________________________________
pgbr-geral mailing list
pgbr-geral@listas.postgresql.org.br
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral
--------------------------
E-mail Seguro Vetorial.net
Mensagem classificada como NÃO-SPAM. Para classificar como SPAM,
encaminhe para [EMAIL PROTECTED]
Chave de Identificação: 26110,465b03d5786841300320092
begin:vcard
fn:Daniel Loureiro
n:Loureiro;Daniel
org:Terminal Maritimo Luiz Fogliatto S/A;Setor de TI
email;internet:[EMAIL PROTECTED]
tel;work:(53) 32341500 Ramal 166
version:2.1
end:vcard
_______________________________________________
pgbr-geral mailing list
pgbr-geral@listas.postgresql.org.br
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral