Subject Re: With Subquery, Master table is not using index
Author Svein Erling Tysvær
--- In firebird-support@yahoogroups.com, "ibrahim bulut" wrote:
> Hi,
> i am using firebird 1.5.2
> i have a problem about subquery and index using
>
> i have a table for stock details and another table for stocks.
> stock detail table is indexed with stokck_id.
>
> the query is that
> SELECT STOCK_ID, TRDATE, TRTIME, AMOUNT, TOTAL FROM STOCK_DETAIL
> WHERE STOCK_ID IN (SELECT STOCK_TYPE IN (1,2,3,4,5))
>
> this query returns this plan
> STOCK_DETAIL Natural, STOCK X_STYPE
>
> but if i use this query
> SELECT STOCK_ID, TRDATE, TRTIME, AMOUNT, TOTAL FROM STOCK_DETAIL
> WHERE STOCK_ID IN (15,250,125)
> plan is that
> STOCK_DETAIL XSD_STOCK_ID,XSD_STOCK_ID,XSD_STOCK_ID
>
> how can i solve this problem
> can i use my own plan for the first query
> how can i use the index

In general, Firebird cannot use the index. However, if you change to a
JOIN rather than IN indexes can be used. Also, take a look at the
answer I just gave Greg on this list.

HTH,
Set