Question

I am SQL Server devloper who is trying to optimize a Sybase query. I am trying to get a non cluster index to seek, but it keeps doing scan, just wanted to confirm is "seek" possible in Sybase if yes how to acheve a non cluster index seek?

I have a query like below (* is actually some 32 columns)

SELECT t.* FROM dbo.g1_positions t WHERE t.source_date = (select max(source_date) from g1_positions)

I have 3 non cluster index (no cluster index) on table as below

  1. index named primary_key on columns entity_id, bgnref, retnum, source_date
  2. index named idx_entdte on columns entity_id, source_date
  3. index named idx_bgndte on columns bgnref, source_date

The inner query (which calculates max does index scan on idx_entdte), outer index by default does a table scan, if I force an index it does index scan and some thing extra which is decribe by "Using I/O Size 2 Kbytes for data pages. With MRU Buffer Replacement Strategy for data pages. "

My guess is this equivalent to "look up" we have in SQL Server. After forcing index i do not see performance gain I was just wondering what can i do get performance improvement.

I can not do any changes on table like creating/droping/modifying index.

Just to give idea of lookup in SQL Server work.

Suppose we have table Employee with 4 records.

enter image description here

If a query uses non cluster index on Emp_id it will reach Leaf Node and to get actual data will use pointer to read actual data(row) on heap. This process using pointer is called LookUp

Was it helpful?

Solution

It's possible!

If it's not using it supposedly it's because the table scan is better. That might be because the statistics are off! Update them as well.

If needed, you can force the use of the index, for more info check this example.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top