Subject Re: [firebird-support] Performance optimation?
Author Mark Rotteveel
On Mon, 15 Dec 2014 16:01:27 +0100, "'checkmail' check_mail@...
[firebird-support]" <firebird-support@yahoogroups.com> wrote:
> Now I would like to make an analysis. At the time, I do this:
>
> for select cast(ts as date) as mz from tablea where ts >= "criteria
from"
> and ts < "criteria to"
> group by mz)
> into :messzeit do
> begin
> f_messwert = null;
> MESSWERTE = '';
> for select a.id_counter, sum(a.value) from tableb a left join
tablea
> b
> on a.id_timestamp = b.id
> where cast(b.ts as date) = :messzeit
> group by a.id_counter
> into :i_zae, :f_messwert do
> begin
> if(f_messwert is null) then f_messwert = 0;
> MESSWERTE = MESSWERTE || cast(:i_zae as varchar(4)) || '=' ||
> cast(:f_messwert as varchar(8)) || ';';
> end
> suspend;
>
> end
>
> The Result is one returned record for each day (day, conter 1 = 123;
> counter
> 2 = 222;.)
>
> It takes a long time but I must integrate the tablea on the second part
of
> the statement. How can I optimize this in firebird?

That is not surprising. You are executing a query and for each row you are
executing another query. Use joins and/or subqueries instead.

Mark