[firebase-br] Interbase rápido x Firebird muito lento. Me ajudem com esse problema por favor.

Magno System magno em speet.com.br
Qui Maio 14 09:58:47 -03 2009


Segue um teste. Mesmo usando o IN sem o NOT o EXISTS ainda mostrou-se um 
pouco mais eficiente. O teste foi feito em uma base com a tabela VENDAS com 
28052 registros e a tabela PRODUTOS com 987 registros. O servidor foi 
FIREBIRD 2.1.1.

Verifique a comparação:

SELECT P.CODIGO FROM PRODUTOS P WHERE EXISTS (SELECT V.CODIGOPRODUTO FROM 
VENDAS V WHERE V.CODIGOPRODUTO = P.CODIGO)

Plan
PLAN (V INDEX (VENDAS_IDX3))
PLAN (P NATURAL)

Adapted Plan
PLAN (V INDEX (VENDAS_IDX3)) PLAN (P NATURAL)

------ Performance info ------
Prepare time = 10ms
Execute time = 20ms
Avg fetch time = 2,22 ms
Current memory = 9.141.012
Max memory = 9.371.888
Memory buffers = 2.048
Reads from disk to cache = 0
Writes from cache to disk = 0
Fetches from cache = 6.984

SELECT P.CODIGO FROM PRODUTOS WHERE P.CODIGO NOT IN

Plan
PLAN (V INDEX (VENDAS_IDX3))
PLAN (P NATURAL)

Adapted Plan
PLAN (V INDEX (VENDAS_IDX3)) PLAN (P NATURAL)

------ Performance info ------
Prepare time = 0ms
Execute time = 30ms
Avg fetch time = 3,33 ms
Current memory = 9.141.124
Max memory = 9.371.888
Memory buffers = 2.048
Reads from disk to cache = 0
Writes from cache to disk = 0
Fetches from cache = 6.984

SELECT P.CODIGO FROM PRODUTOS P WHERE P.CODIGO NOT IN (SELECT 
V.CODIGOPRODUTO FROM VENDAS V)


Plan
PLAN (V NATURAL)
PLAN (P NATURAL)

Adapted Plan
PLAN (V NATURAL) PLAN (P NATURAL)

------ Performance info ------
Prepare time = 0ms
Execute time = 3s 455ms
Current memory = 9.137.120
Max memory = 9.371.888
Memory buffers = 2.048
Reads from disk to cache = 0
Writes from cache to disk = 0
Fetches from cache = 2.757.951


SELECT P.CODIGO FROM PRODUTOS P WHERE NOT EXISTS (SELECT V.CODIGOPRODUTO 
FROM VENDAS V WHERE V.CODIGOPRODUTO = P.CODIGO)

Plan
PLAN (V INDEX (VENDAS_IDX3))
PLAN (P NATURAL)

Adapted Plan
PLAN (V INDEX (VENDAS_IDX3)) PLAN (P NATURAL)

------ Performance info ------
Prepare time = 0ms
Execute time = 20ms
Avg fetch time = 2,22 ms
Current memory = 9.141.044
Max memory = 9.371.888
Memory buffers = 2.048
Reads from disk to cache = 0
Writes from cache to disk = 0
Fetches from cache = 6.984


----- Original Message ----- 
From: "Sandro Souza" <escovadordebits em gmail.com>
To: "Carlos H. Cantu" <listas em warmboot.com.br>; "FireBase" 
<lista em firebase.com.br>
Sent: Thursday, May 14, 2009 9:18 AM
Subject: Re: [firebase-br]Interbase rápido x Firebird muito lento. Me ajudem 
com esse problema por favor.


Bom dia/tarde Carlos.

Grande Carlos, muito obrigado por nos esclarecer sobre esse ponto
importante.

Tenho a esperança que um dia o Firebird possa utilizar um mecanismo mais
eficiente nesses tipo de pesquisa (NOT IN (<SELECT>)).

Mais uma vez muito obrigado pelos esclarecimentos.

2009/5/14 Carlos H. Cantu <listas em warmboot.com.br>

> EdB> Aproveitando a oportunidade, achei muito interessante o que
> EdB> disse nosso amigo Carlos H. Cantu sobre o operador NOT IN não
> EdB> mais utilizar índices nessas últimas versões do Firebird para não
> EdB> trazer resultados inconsistentes.
>
> Sendo mais preciso, o NOT IN não usará índices somente se a
> construção for do tipo ... NOT IN (<select>)
>
> EdB> Grande Carlos, você poderia dar um exemplo de como o NOT IN
> EdB> poderia gerar resultados inconsistentes se ainda utilizasse os
> EdB> índices? Fiquei muito curioso a respeito desse ponto.
>
> Retirado do release notes do FB 2.0:
>
> Existence Predicates NOT IN and ALL May Be Slow
> Firebird and, before that, InterBase, have produced incorrect results for
> the logical existence predicates ALL
> and NOT IN for many years. That problem has bee corrected in Firebird 2.0,
> but the change means that
> indexes on the inner tables cannot be used and performance may be slow
> compared to the same query's
> performance in V.1.5.
>
>
> []s
> Carlos H. Cantu
> www.FireBase.com.br - www.firebirdnews.org
> www.warmboot.com.br - blog.firebase.com.br
>
>
>
> ______________________________________________
> FireBase-BR (www.firebase.com.br) - Hospedado em www.locador.com.br
> Para saber como gerenciar/excluir seu cadastro na lista, use:
> http://www.firebase.com.br/fb/artigo.php?id=1107
> Para consultar mensagens antigas: http://firebase.com.br/pesquisa
>
______________________________________________
FireBase-BR (www.firebase.com.br) - Hospedado em www.locador.com.br
Para saber como gerenciar/excluir seu cadastro na lista, use: 
http://www.firebase.com.br/fb/artigo.php?id=1107
Para consultar mensagens antigas: http://firebase.com.br/pesquisa


--------------------------------------------------------------------------------



No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.0.238 / Virus Database: 270.12.27/2112 - Release Date: 05/13/09 
07:04:00





Mais detalhes sobre a lista de discussão lista