Is there a way to force optimizer to use indexes without hints? (some
server setting or index type...)
I'll give an example to clarify :
I have a table with fields
Customer_Code char(10) not null
Invoice_Number int not null
and an index on those fields IX_1.
there are about 2,000,000 records in the table and those two fields are
not unique, and I cant use clustered index because of the nature of the
table (need it for something else).
When I use query like :
Select * from CustInv where Customer_Code=' ABC' and invoice_Number= 2
depending on the ammount of data statistics computes, query is executed
using the IX_1 or IX_1 is ignored. The documentation says that using of
indexes is determened by the uniqueness of the data, but my tests show
that every usage of index is faster.
I can fool the optimizer when using query like
Select * from CustInv where Customer_Code=' ABC' and invoice_Number> =2
and invoice_number< =2
but all that it does is extends the optimizer's tolerance (IX_1) is
ignored for some queries in that form also.
Because my database and indexes are dynamically created, I cannot use
hints for indexes, so if anyone knows a way to tell the database
something like : "If you have an index on where fields, use it ALWAYS",
the knowledge would be gratly appretiated! :)
Thanx in advance! Sorry for a longer post and maybe fuzzy explanation of
the problem...
Igor
server setting or index type...)
I'll give an example to clarify :
I have a table with fields
Customer_Code char(10) not null
Invoice_Number int not null
and an index on those fields IX_1.
there are about 2,000,000 records in the table and those two fields are
not unique, and I cant use clustered index because of the nature of the
table (need it for something else).
When I use query like :
Select * from CustInv where Customer_Code=' ABC' and invoice_Number= 2
depending on the ammount of data statistics computes, query is executed
using the IX_1 or IX_1 is ignored. The documentation says that using of
indexes is determened by the uniqueness of the data, but my tests show
that every usage of index is faster.
I can fool the optimizer when using query like
Select * from CustInv where Customer_Code=' ABC' and invoice_Number> =2
and invoice_number< =2
but all that it does is extends the optimizer's tolerance (IX_1) is
ignored for some queries in that form also.
Because my database and indexes are dynamically created, I cannot use
hints for indexes, so if anyone knows a way to tell the database
something like : "If you have an index on where fields, use it ALWAYS",
the knowledge would be gratly appretiated! :)
Thanx in advance! Sorry for a longer post and maybe fuzzy explanation of
the problem...
Igor
Comment