Hello,
I am using FirebirdSQL 5.0.2 Win64.
I have a situation where I need to use an SQL like below:
select autoinc,marketplaceordercode,marketplacepackageno
from orders
where marketplacecode=2 and marketplacepackageno is not null and cargotrackingnumber is null
Above
marketplacepackageno and cargotrackingnumber columns are varchar columns.
Since table is due to grow large, I added an index like below
CREATE INDEX IDX_ORDERS3 ON ORDERS (MARKETPLACECODE, MARKETPLACEPACKAGENO, CARGOTRACKINGNUMBER);
When I check the execution plan I see the index is not used. Instead a foreign key which only is based on MARKETPLACECODE column is used.
Select Expression
-> Filter
-> Table "ORDERS" Access By ID
-> Bitmap
-> Index "FK_ORDERS2" Range Scan (full match)
When I check the index statistics they are like below:
FK_ORDERS2=0.5
IDX_ORDERS3=0.0106382975354791
PK_AUTOINC=0.00934579409658909
Comparing PK_AUTOINC (primary key) and IDX_ORDERS3 and it has a nice selectivity.
I don't know the internals of FirebirdSQL and cannot be sure if there is a way to make it use the index rather than foreign key.
Any help is appreciated.
Thanks & Regards,
Ertan