Subject Re: Strange performance on a VIEW
Author Adam
Ben,

OK, this appears to be a limitation of the FB 1.5 optimiser when
handling "complex" views (ie, group bys etc).

The reason for the horrible performance is that basically it is doing
the same as it would do if you did not have a where clause internally
within the view, but then applying the where after it has done all the
joining and grouping.

V2 looks promising, but it is still alpha. If you only query this for
a single ID, a stored procedure thankfully is a bit better so you are
not all lost.

Change the data types as applicable

CREATE PROCEDURE V_VIEW
(
ID INTEGER
)
RETURNS
(
A INTEGER,
B INTEGER,
C INTEGER,
D INTEGER
)
AS
BEGIN
for select t1.ID, t1.A, t1.B, t2.C, sum(t2.D)
from table1 t1
left join table2 t2 on t1.ID = t2.ID
where t1.ID = :ID
group by ID, A, B, C
into :A,:B,:C,:D
do
begin
suspend;
end
END;

Then at least you can run a query like.

SELECT A,B,C,D
from V_VIEW(100);

There is also no alter view syntax yet so if you do use a view, make
sure you do not create and stored procedure of view that internally
uses that view or it becomes a mission to change the internal view.

Adam