I have a stored procedure which returns results from an indexed view via a covering index. Usually, it runs fast (~10ms), sometimes it can run up to 8 seconds.
Here’s an example random execution (note: this isn’t a slow one, but the query text is the same apart from the value passed through):
declare @p2 dbo.IdentityType insert into @p2 values(5710955) insert into @p2 values(5710896) insert into @p2 values(5710678) insert into @p2 values(5710871) insert into @p2 values(5711103) insert into @p2 values(6215197) insert into @p2 values(5710780) exec ListingSearch_ByLocationAndStatus @statusType=1,@locationIds=@p2
Here’s the SPROC:
ALTER PROCEDURE [dbo].[ListingSearch_ByLocationAndStatus] @LocationIds IdentityType READONLY, @StatusType TINYINT AS BEGIN SET NOCOUNT ON; SELECT -- lots of fields FROM [dbo].[ListingSearchView][a] WITH (NOEXPAND) INNER JOIN @LocationIds [b] ON [a].[LocationId] = [b].[Id] WHERE [a].[StatusType] = @statusType OPTION (RECOMPILE);
(note: i added the
OPTION (RECOMPILE) hint recently after some advice, but it hasn’t helped.
Here’s the covering index (note: the view also has a clustered index on
ListingId, which is unique)
CREATE NONCLUSTERED INDEX [IX_ListingSearchView_ForAPI] ON [dbo].[ListingSearchView] ( [LocationId] ASC, [StatusType] ASC ) INCLUDE ( -- all the fields in the query) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) GO
I put a profiler trace on, with showplan XML statistics.
Here’s a slow one (6 seconds), and the relevant plan:
Looks exactly as i’d expect, and is the same plan when the query is fast.
Here’s the zoom in on the costly part of the plan, if that helps:
Here is the full schema of the view/backing tables, if that helps: https://pastebin.com/wh1sRcbQ
- Indexes have been defrag’d, statistics up to date.
- Originally query was inline against the view, but i moved to SPROC to try and help stabilize. Hasn’t helped.
WITH OPTION (RECOMPILE);hint (didn’t work, so can’t be parameter sniffing?)
- Other queries in the system also sometimes run slow, and they also have no obvious issues in their plan.
- Could be locking? Not sure how to confirm.
Any ideas on what i could try next?
✓ Extra quality
ExtraProxies brings the best proxy quality for you with our private and reliable proxies
✓ Extra anonymity
Top level of anonymity and 100% safe proxies – this is what you get with every proxy package
✓ Extra speed
1,ooo mb/s proxy servers speed – we are way better than others – just enjoy our proxies!
USA proxy location
We offer premium quality USA private proxies – the most essential proxies you can ever want from USA
Our proxies have TOP level of anonymity + Elite quality, so you are always safe and secure with your proxies
Use your proxies as much as you want – we have no limits for data transfer and bandwidth, unlimited usage!
Superb fast proxy servers with 1,000 mb/s speed – sit back and enjoy your lightning fast private proxies!
99,9% servers uptime
Alive and working proxies all the time – we are taking care of our servers so you can use them without any problems
No usage restrictions
You have freedom to use your proxies with every software, browser or website you want without restrictions
Perfect for SEO
We are 100% friendly with all SEO tasks as well as internet marketing – feel the power with our proxies
Buy more proxies and get better price – we offer various proxy packages with great deals and discounts
We are working 24/7 to bring the best proxy experience for you – we are glad to help and assist you!