Subject 2.5.1 terribly slower than 2.0 in views + expressions
Author kokok_kokok
I have found that some queries to views are terribly slower in 2.5.1 versus 2.0
It seems that 2.5 reads unnecessary records in comparison to 2.0.

For example, typical example a Order table with a FK to Customer table.

My view is something like:

CREATE VIEW ORDERVIEW(
OrderId,
OrderDone,
CustomerName,
)
AS SELECT O.OrderId, O.OrderDone, C.Name, IIF(O.DoneDate IS NULL,0,1)
FROM Order O LEFT JOIN Customer C ON O.CustomerId=C.CustomerId

If I execute
SELECT OrderId FROM ORDERVIEW WHERE OrderDone=1
I can see using PlanAnalyzer that Firebird 2.5 reads all Order records BUT ALSO the same number of records for the Customer table.
It does not seem necessary to me since if OrderDone<>1, then FB does not need to read the joined table.


The same query in FB 2.0, Firebird reads all Order records, BUT ONLY the number of records that matches with WHERE clause for the Customer table. It is optimized.

For example, there are 1000 orders but only 5 are OrderDone=1.
Using Firebird 2.5, it reads 1000 orders and 1000 customers
Using Firebird 2.0, it reads 1000 orders and only 5 customers.

It seems that the expression IIF(O.DoneDate IS NULL,0,1) "forces" to read all customers but I cannot see the reason.
Talking about millions of records, the time are minutes of difference.
Is there are way to avoid this behavior?

Thank you