Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

T-SQL Query help

$
0
0
select  top 100 COUNT(Categorydelta)as hits,Categorydelta from Category WITH (NOLOCK) 
where Product like '%/_api/search%' 
and DATEDIFF(MINUTE,CONVERT(datetime, SWITCHOFFSET(CONVERT(datetimeoffset, LogTime), DATENAME(TzOffset, SYSDATETIMEOFFSET()))),getdate())<=60
and Categorydelta not like '?&QueryTemplate%'
and Categorydelta not like  '%fakekeyword%'
and Categorydelta not like  '?Querytext=''''%'
and Categorydelta not like  '%dlcstoreall%'
group by Categorydelta order by hits desc

I have the above sql executing on one of the Source to pull the data, the above query never ends and my CPU usage is hitting 100%. I cannot add any index or make any changes to the schema.

The "Category" is a view with a UNION on 4 tables.

Can anyone let me know how can I break this query and make it fast. 

It's a very huge database with millions of records.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>