ziv
ziv

Reputation: 37

Is it possible to dynamically force index usage in Sybase?

Good day,

Per the title, Is it possible to dynamically force the usage of a certain index in a query?

Example of what I'm trying to do:

*Table:

EmployeeID(numeric) | EmployeeName(varchar) | Month(datetime) | Sallary(int)

Query:

insert into #Employees 
select * from Employees (index @index)
where Month between 'Jan' and 'Dec'

With this code, Sybase simply says there is an error near @index.

Q1: Can I do this?  
Q2: If so, how? 
Q3: If not, is there anything else I can do?

The query will NOT complete unless that index is used, and the inid I know with 100% certainty is not the same in all servers this needs to run on, and although I did not check, there is also no guarantee the index name itself is the same. I have a query that can find this index, based on its column, the column name being something I can assure will always be the same.

Thanks in advance, ziv.

Upvotes: 2

Views: 3796

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521457

It appears that you must use a hard-coded index name when providing the hint. For example, if the index on the month column were called month_index then the following would work:

insert into #Employees 
select * from Employees (index month_index)
where Month between '2016-01-01' and '2016-12-31'

But if you specify no index then Sybase might use whatever single inxex you have as a default.

Upvotes: 3

Related Questions