Subject | [firebird-support] Re: performance of subselect with group by |
---|---|
Author | Svein Erling Tysvær |
Post date | 2014-12-16T17:19:07Z |
>Hello,Hi Björn!
>
> Thanks for the answer.
> How can I optimize if I want to use a DML command in conjunction
> with a subselect, e.g.
>
> delete from test where Id in (
> select min(t.Id) FROM test t
> group by t.reference, t.key
> having count(*) > 1
> )
>
I don't think there is any simple way to make a delete with a subselect as the only part of a where clause perform great on largish tables. That is, using EXECUTE BLOCK (which doesn't exist on older Firebird versions) should perform OK:
execute block as
declare variable id integer;
begin
for select min(t.Id) FROM test t
group by t.reference, t.key
having count(*) > 1
into :id do
delete from test where Id = :id;
end
HTH,
Set