Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 simple query run very slow

Author  Topic 

mahmood.p52
Starting Member

2 Posts

Posted - 2014-12-19 : 16:20:34
hi to all
i use sql 2012 in my application
one or more of tables go very slow in simple query.
i rebuild index but not change.
just when i create a new table and insert from old table to new
it will be normal and fast

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-12-19 : 16:27:13
Show us the query and the showplan xml for it. I would bet you are either missing an index or have out-of-date statistics. We need more info to help.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

mahmood.p52
Starting Member

2 Posts

Posted - 2014-12-19 : 16:37:33
select * from a where field1 in (
select field2 from b)
and field2='string'

in this query i have a index on field1,field2 on table a
and index on field2 on table b

i tested every thing that you may think .
for example i drop the index and recreate the index but not change.
but recreate a new table and export the data was the solution.
i do not know why it appear
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-12-19 : 16:43:40
We would need to see the showplan xml when the issue occurs again. I might have tried field2,field1 on a. I'd also not use * and would make the index covering.

select *
from a
join b on a.field1 = b.field2
where b.field2 = 'string'



Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -