Previous question: SQL Server changes execution plan
We are using SQL Server 2014 Developer Edition.
SQL Server changes execution plan on identical query and the same database and SQL Server (I checked several times).
If I connect with Management Studio from my dev computer with AD account, it takes 18 seconds to finish the query (most of the time). If I go with remote connection to server and execute query in Management Studio it takes 2 seconds to finish. On my colleague's machine it takes 2 second with Management Studio and 18 if he connects with MVC application (Ado.Net).
Things we did
- Restart SQL Server
- DBCC FREEPROCCACHE
- sp_updatestats
- try with different users AD and SQL users
Slow execution plan
Fast execution plan
Query
SET ANSI_NULLS ON
GO
SET ANSI_PADDING ON
GO
SET ANSI_WARNINGS ON
GO
SET ARITHABORT ON
GO
SET CONCAT_NULL_YIELDS_NULL ON
GO
SET NUMERIC_ROUNDABORT OFF
GO
SET QUOTED_IDENTIFIER ON
GO
DECLARE @ccode varchar(500)
DECLARE @PageSize int
DECLARE @PageNumber int
SET @ccode = '%skd%'
SET @PageSize = 20
SET @PageNumber = 1
SELECT DISTINCT CLASSIFICATIONS.ABBREV_TEXT,
CLASSIFICATIONS.TITLE_TEXT,
CLASSIFICATIONS.CFN_UID
FROM klasje.dbo.CLASSIFICATIONS
inner join Klasje.dbo.CFN_VERSIONS on CLASSIFICATIONS.CFN_UID = CFN_VERSIONS.CFN_UID
inner join Klasje.dbo.VERSION_CATEGORY_XREFS on CFN_VERSIONS.CVN_UID = VERSION_CATEGORY_XREFS.CVN_UID
left outer join Klasje.dbo.VELJAVNOST on CFN_VERSIONS.LIFE_CYCLE_CODE = VELJAVNOST.RV_LOW_VALUE
WHERE CATEGORY_CODE like @ccode OR DESCRIPTOR_TEXT like @ccode OR DEFINITION_TEXT like @ccode
ORDER BY ABBREV_TEXT
OFFSET @PageSize * (@PageNumber - 1) ROWS FETCH NEXT @PageSize ROWS ONLY
Both execution plans on gist.
SELECT @@OPTIONS
returns 5496 in in both cases (slow and fast).