In Ax2012 R3 CU9 (with SQL 2014) I have select with 6 tables. But this simple query takes about 70 seconds:
while
Select ValidTimeState(validFrom, validTo) PPLPayrollCalculatePreparedSet //1-10 rows
where PPLPayrollCalculatePreparedSet.RandomNumber == MyNumber
Join PPLEmplBase where ... //6000 rows
Join PPLCalendarPeriodForEmpl where ... //8000 rows
Join PPLCalendar where ... //1 mln rows
Join PPLCalendarDayTypeTable where ... //20 rows
Join PPLContract where ... //6000 rows
Query plan is wrong becouse joins PPLContract (6000 rows) x PPLCalendar(1 mln rows) x …
After changing query:
where PPLPayrollCalculatePreparedSet.RandomNumber == MyNumber
to
where PPLPayrollCalculatePreparedSet.RandomNumber >= MyNumber
query takes only 0.02 sec.
New query plan is quite good becouse starting from PPLPayrollCalculatePreparedSet (10 rows) x PPLContract (6000 rows) x …
I can send via email this slow and fast execution plan.
What can I do to force create new query plan (or delete this slow query plan) ? I tryed:
DBCC FREEPROCCACHE;
GO
DBCC FREESYSTEMCACHE ('SQL Plans');
GO
DECLARE @intDBID INT;
SET @intDBID = (SELECT [dbid]
FROM master.dbo.sysdatabases
WHERE name = N'DynamicsAX_TEST');
DBCC FLUSHPROCINDB (@intDBID);
GO
but always select with == MyNumber is using slow query plan but select with >= MyNumber is using fast query plan. Can I delete this slow query plan?
*This post is locked for comments
I have the same question (0)