I have an application that sometimes runs slow and I think it is related to database cursors.
Don't have any access to the application source so I can't control the database calls but the database is open so I can add index where needed.
Problem is that I don't know really know how to speed up cursors with index.
The cursor queries are simple and look like
SELECT * FROM table WHERE field1=1 AND field2=2 ORDER BY field3, field4
(Table contains about a 1M rows. Sometimes there is a single left join as well)
If I run the query directly in SSMS it takes less than a second but when it is run from the application in a cursor it can take 30 seconds to fetch the first row (verified with sql-trace).
The fields in WHERE and ORDER BY clauses are all indexed separately.
I guess a combined index on field1,field2,field3,field4 would make it faster. Is there a way to speed it up without creating an index for each combination and order of fields?
(Just to repeat: I have no influence on how the application accesses the database. Performance can only be tuned via index)