Subject Re: Using VIEW (or not)
Author Svein Erling
--- In firebird-support@yahoogroups.com, "Riho-Rene Ellermaa" wrote:
> The time went from 9.4 sec to 8.2 - small improvement.
> I think it is slow, because when I run the 2 parts of the union
> separately (without UNION), then the result is 20 ms.
>
> Any ideas, how to get correct account number without UNION

OK, Riho, then I understand that you're not expecting to return 35000
records in less than 9 seconds, just that you want an initial reply in
a matter of milliseconds.

I suggest you show us the PLANS generated by the 9.4 sec and 20 ms
selects. Or, if you use Fb 1.5, you could try

CREATE VIEW V_STAT_HISTORY(ACCID,ACCOUNT,SDATE,ROW,...)
AS

SELECT accid,
CASE
WHEN (account.ibandate<=SDATE) THEN account.ACCOUNT
ELSE account.OLDACCOUNT
END,
SDATE,
ROW ,
....
from stat_history
join account on stat_history.accID=account.id
where account.ibandate<=SDATE

HTH,
Set