Subject Re: Plan question
Author Svein Erling
--- In firebird-support@yahoogroups.com, Milan TomeĀš - Position wrote:
> There are around 4000 records with ID_CSYMBOL = 1360 in table
> STREETS and let's say (without any calculations) that 90% of all
> records in STREETS have unique LINK_ID and ALTSTREETS = 'F' and
> other 5% have duplicate LINK_ID with ALTSTREETS = 'T'.

Assuming that SRC.LINK_ID also is very selective, I'd guess that

PLAN JOIN (STR INDEX (FK_STREETS_CSYMBOL), SRC
INDEX (IX_ZLEVELS_LINK)) (I don't know the name of this last index) would be good, you should be able to force that plan by changing to:

SELECT ID_ZLEVELS
FROM STREETS STR
LEFT JOIN ZLEVELS SRC ON STR.LINK_ID = SRC.LINK_ID
WHERE
STR.ID_CSYMBOL = 1360 AND
(2=0 OR
(STR.ALTSTREETS = 'F' AND
SRC.SRC_DIR_NAME IN ('C1', 'C4') AND
SRC.ID_CSYMBOL IN (2000, 2010)))

The 2=0 is just to get a false condition that prevents indexes from being used. Experiment with and without this to see whether the plan differs and which is faster.

HTH,
Set