Microsoft SQL Server: How to improve the performance of a dumb query? -


i have been asked performance issue of sql server installation. not sql server expert, decided take look. using closed source application appears work ok. after sql server upgrade 2000 2005, application performance has reportedly suffered considerably. ran sql profiler , caught following query (field names changed protect innocent) taking 30 seconds run. first thought should optimize query. not possible, given application closed source , vendor not helpful. left, trying figure out how make query run fast without changing it. not clear me how query ran faster on older sql server 2000 product. perhaps there sort of performance tuning applied on instance did not carry on or not work on new sql server. dbcc pintable comes mind.

anyway, here offending query:

select min(row_id) table1 calendar_id = 'test1'  , exists      (select id table1 calendar_id = 'test1' ,          datediff(day, '12/30/2010 09:21', start_datetime) = 0      )  , exists      (select id table1 calendar_id = 'test1' ,          datediff(day, end_datetime, '01/17/2011 09:03') = 0      );   

table1 has 6200 entries , looks this. have tried creating various indices no effect.

id                 calendar_id  start_datetime  end_datetime int, primary key   varchar(10)  datetime        datetime 1                  test1        2005-01-01...   2005-01-01... 2                  test1        2005-01-02...   2005-01-02... 3                  test1        2005-01-03...   2005-01-03... ... 

i grateful if resolve mystery.

thanks in advance.

the 1 thing should covering index on calendar_id:

create index <indexname>      on table (calendar_id, id)      include (start_datetime, end_datetime); 

this satisfy calendar_id = 'test1' predicates, min(row_id) sort , provide material evaluate non-sarg-able datefiff predicates. if there no other columns in table, clustered index need , id primary key should non-clustered one.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -