Buenas
tente
Create index xxxx on TABELA1 (campo,datahora);
analyze tabela1;
explain DELETE FROM Esquema.TABELA1 WHERE CAMPO2 IN(
SELECT CAMPO2 from Esquema.TABELA1
WHERE CAMPO1 = 'D_E_L'
AND datahora BETWEEN '2011/01/01' AND '2011/01/27 23:59:'
mostre ai o plano gerado
[]s
Luiz
> Existe um índice para esta tabela que é justamente a data de cadastro.
> Posso
> tentar mudar para:
>
> DELETE FROM Esquema.TABELA1 WHERE CAMPO2 IN(
> SELECT CAMPO2 from Esquema.TABELA1
> WHERE CAMPO1 = 'D_E_L'
> AND datahora BETWEEN '2011/01/01' AND '2011/01/27 23:59:'
> LIMIT 30000
> );
>
> acho que melhorar um pouco pois assim vai usar um índice, veja:
>
> "Nested Loop (cost=11074.07..12757.22 rows=200 width=6)"
> " -> HashAggregate (cost=11074.07..11076.07 rows=200 width=4)"
> " -> Limit (cost=0.00..11070.32 rows=300 width=4)"
> " -> Index Scan using idx_TABELA1_datahora on TABELA1
> (cost=0.00..30959.99 rows=839 width=4)"
> " Index Cond: ((datahora >= '2011-01-01
> 00:00:00'::timestamp without time zone) AND (datahora <= '2011-01-27
> 23:59:00'::timestamp without time zone))"
> " Filter: ((CAMPO1)::text = 'D_E_L'::text)"
> " -> Index Scan using TABELA1_pkey on TABELA1 (cost=0.00..8.39 rows=1
> width=10)"
> " Index Cond: (Esquema.TABELA1.CAMPO2 = Esquema.TABELA1.CAMPO2)"
>
>
> Sérgio Antônio dos Santos
> Bacharel em Sistemas de Informação
>
> Cel: (31) 8601-5207
> Residencia: (31) 3885-2346
> site: http://www.clientside.com.br
> Twitter: @serginhosant
> Linkedin: http://br.linkedin.com/in/serginhosant
> Delicious: http://www.delicious.com/serginhosant
> Fotos: http://picasaweb.google.com/sergio.serginhosant
>
>
> -----------
> Rogo a Deus como se esperasse tudo dEle, mas trabalho como se esperasse
> tudo de mim S.Tomás de Aquino
>
>
> Em 27 de janeiro de 2011 14:52, Fabrízio de Royes Mello <
> [email protected]> escreveu:
>
>>
>>
>> Em 27 de janeiro de 2011 14:32, sergio santos <
>> [email protected]> escreveu:
>>
>>
>>> DELETE FROM Esquema.TABELA1 WHERE CAMPO2 IN(
>>> SELECT CAMPO2 from Esquema.TABELA1
>>> WHERE CAMPO1 = 'D_E_L'
>>> LIMIT 30000
>>> );
>>>
>>>
>>>
>> Não sei se entendi muito bem, mas vc esta tentando excluir os registros
>> da
>> tabela fazendo uma consulta na própria tabela??? Será que isso é
>> necessário???
>>
>> Vc não poderia simplesmente:
>>
>> DELETE FROM Esquema.TABELA1 WHERE CAMPO1 = 'D_E_L' ;
>>
>>
>> E pelo que vi o Pg esta fazendo um seqscan com esse 'CAMPO1', não está
>> faltando um indice para ele ?
>>
>>
>> --
>> Fabrízio de Royes Mello
>> >> Blog sobre TI: http://fabriziomello.blogspot.com
>> >> Perfil Linkedin: http://br.linkedin.com/in/fabriziomello
>>
>>
>> _______________________________________________
>> pgbr-geral mailing list
>> [email protected]
>> https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral
>>
>>
> _______________________________________________
> pgbr-geral mailing list
> [email protected]
> https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral
>
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral