Hi All,
Need some help in tuning the SELECT statement.
Below SELECT query is taking a long time to execute under a specific database.
Brief description about the Issue
=============================
- sql ver :Microsoft SQL Server 2012 (SP4) Standard Edition (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) (Hypervisor)
- We have 2 databases say db1 and db2. under db1 query completes in 5 secs but in db2 its taking 30-40 mins.
- Both databases reside on same SQL instance
- max server memory = 85 GB , OS memory = 96 GB RAM
select TOP (50000) * from EXT_data_Hist_TbL
WHERE CREATE_DATE < dateadd(year,-1,GETDATE())
- Table in qustion: EXT_data_Hist_TbL and it is a HEAP table
- In db1 table rowcount = 24534283 tablesize=187 GB
- In db2 table rowcount = 13290417 tablesize 191 GB
- no blocking
- waittype observed for db2 query is "(5ms)PAGEIOLATCH_SH:db2:3(*)"
- Only difference is that, Initially when both databases are restored on to non-prod env, in db2 , application team has run below DELETE statement twice or thrice ( I don't know the exact number)
and then if they run above SELECT stmt, it runs over 30mins. My doubt is whether these batch DELETES here is causing any issues under the covers? can anyone shed some light here.
DELETE TOP (50000) EXT_data_Hist_TbL
WHERE CREATE_DATE < dateadd(year,-1,GETDATE())
- I tried updating the statistics ( there is only 1 though which is a system created one) and run the SELECT query, it didn't help.
- index fragmentation in both the db's is almost same but rowcount differs.
- The execution plan(s) i also same for both query.. i.e. Full table scan since it is a HEAP
How can we make this SELECT faster on db2 as well? Any inputs here please?
Thanks,
Sam