Subject Re: How to optimize this query using Firebird?
Author partsi
The plan for this particular case (two data conditions) is:

PLAN JOIN (C5 INDEX (IX_PV_LOOKUP_PD_DATA_TARGETVER), C4 INDEX
(IX_DV_PV_PV), C2 INDEX (PK_DV_PV), C3 INDEX (PK_PV_TIMESTAMP))

The query processing starts from C5. This can be a good or bad
choice. Because IX_PV_LOOKUP_PD_DATA_TARGETVER is unique, no more
than one row is found in C5. But the join to C4 (DV_PV) can produce
hundreds of thousands of rows indicating that very many object
versions meet this condition. This fact can kill the overall query
performance because these rows are used in joining to C2 (DV_PV) and
finally to C3 for checking the second (timestamp) condition. If the
initial guess is bad, the database is subject to a big amount of
index seeks even though there are a few results in the result set.

Hopefully you understand this query structure. If there were three
data conditions instead of two, performance problems could be even
worse because of more joins involved.

Timo