Subject Re: Slow Update
Author Adam
--- In firebird-support@yahoogroups.com, "Maxisoft - Luciano
Enzweiler" <enzweiler@s...> wrote:
>
> Hi.
>
> I made an update SQL but it takes too much time to execute, and
there seem to be no reason for that.
>
> The update is like this one:
>
> The field T1.CODTB is the Primary Key of TABLE1 and all the other
fields are integers, but none is indexed. Both tables have about 2000
records.
>
> update TABLE1 T1 set T1.MARCA = 0 where (T1.MARCA = 1) and
(T1.CODTB not in (select T2.CODREF from TABLE2 T2 where (T2.CODREF is
not null) and (T2.FILTRO = 1)))

Your select example contains a fixed list, the update uses a query in
the in statement, which is executed for every record.

try the following, it may help.

update TABLE1 T1 set
T1.MARCA = 0
where
(T1.MARCA = 1) and
not Exists(
select T2.CODREF
from TABLE2 T2
where (T2.CODREF is not null
and T1.CODTB <> T2.CODREF ) and (T2.FILTRO = 1))
)

Adam