Subject Query Optimization
Author marc_guillot
Hello.

¿ Somebody knows why a very simple query like that doesn't optimizes
with indexes ?

select VTA_ID
from VT_VENTAS
inner join CL_CLIENTES on CLI_ID = VTA_CLI_ID
inner join VT_GAFAS on GAF_VTA_ID = VTA_ID
where VTA_FECHA is not null

PLAN JOIN (CL_CLIENTES NATURAL,VT_VENTAS INDEX
(VT_VENTAS_IDX1),VT_GAFAS INDEX (VT_GAFAS_IDX1))

CLI_ID is a primary key of CL_CLIENTES.

If I changes the query to

select VTA_ID
from VT_VENTAS
left outer join CL_CLIENTES on CLI_ID = VTA_CLI_ID
inner join VT_GAFAS on GAF_VTA_ID = VTA_ID
where VTA_FECHA is not null

PLAN JOIN (JOIN (VT_VENTAS NATURAL,CL_CLIENTES INDEX
(PK_CL_CLIENTES)),VT_GAFAS INDEX (VT_GAFAS_IDX1))

Now CL_CLIENTES uses Index in primary key but VT_VENTAS not uses Index
VT_VENTAS_IDX1 for field VTA_FECHA. (but the result set is not exactly
what I'am looking for).

¿ How can I optimize it ? I have tried in FB 1.0,2 and 1.5.2.

Thank you.