dedicatedtosql (5/9/2013)
There are lot of stuff u can do to improve this query. First thing I would recomend is Upadating the stats on most of the tables in the query.I have attached screen shot that contains one example. THe diffrence b/w the actual number of rows and estimated number of rows is huge. That is clear indication that statiscs are skewed.
Regards.
No luck, updated the statistics still same. Attached is the code, the column names are different from the original sql plan but it is for the same
Edit: Even if i change the query to update only 0 records, when i hover my mouse in the exec plan it still shows that it is using 20gb of memory.
BEGIN TRAN
UPDATE MYTable
SET [ID] = V.ID,
[FacilityPatientID] = V.FacilityPatientID,
[FirstName] = V.FirstName,
[MiddleInitial] = V.MiddleInitial,
[LastName] = V.LastName,
[SSN] = V.SSN,
[Sex] = V.Sex,
[DOB] = V.DOB,
[EncounterID] = V.EncounterID,
[IDX] = V.IDX,
[MS4] = V.MS4,
[PersonID] = V.PersonID,
[GuarantorID] = V.GuarantorID,
[PatientType] = V.PatientType,
[FacilityPatientType] = V.FacilityPatientType,
[AdmitDate] = V.AdmitDate,
[PayerType] = V.PayerType,
[FacilityCode] = V.FacilityCode,
[Phone] = V.Phone,
[Address] = V.Address,
[Address2] = V.Address2,
[City] = V.City,
[State] = V.State,
[Zip] = V.Zip,
[FacilityPlanCode] = V.FacilityPlanCode,
[VerificationStatus] = V.VerificationStatus,
[PayorCode] = V.PayorCode,
[PayorName] = V.PayorName,
[ServiceFieldCode] = V.ServiceFieldCode,
[ResidualBalance] = V.ResidualBalance,
[IsScheduled] = V.IsScheduled,
[IsAdmitted] = V.IsAdmitted,
[IsDischarged] = V.IsDischarged,
[IsFinalBilled] = V.IsFinalBilled,
[BilledDate] = V.BilledDate,
[BilledAmount] = V.BilledAmount,
[TotalBalance] = V.TotalBalance,
[PatientBalance] = V.PatientBalance,
[PayorBalance] = V.PayorBalance,
[WriteOff] = V.WriteOff,
[PriorBalance] = V.PriorBalance,
[Collected] = V.Collected,
[CollectionDate] = V.CollectionDate,
[CollectionMethod] = V.CollectionMethod,
[NonCollectionReasonId] = V.NonCollectionReasonId,
[CustomerSatisfaction] = V.CustomerSatisfaction,
[CollectedBy] = V.CollectedBy,
[EstimatedResidual] = V.EstimatedResidual,
[TaskStatus_P] = V.TaskStatus_P,
[TaskStatus_C] = V.TaskStatus_C,
[TaskStatus_S] = V.TaskStatus_S,
[TaskStatus_R] = V.TaskStatus_R,
[TaskStatus_MN] = V.TaskStatus_MN,
[TaskStatus_ATH] = V.TaskStatus_ATH,
[TaskStatus_HIS] = V.TaskStatus_HIS,
[InsertDate] = V.InsertDate,
[PlanType] = V.PlanType,
[SubscriberCode] = V.SubscriberCode,
[ServicePointCode] = V.ServicePointCode,
[CurrentFinancialClass] = V.CurrentFinancialClass,
[DischargeDate] = V.DischargeDate,
[BusinessRuleID] = V.BusinessRuleID,
[TaskExceptionID] = V.TaskExceptionID,
[TotalCharges] = V.TotalCharges,
[BadDebt] = V.BadDebt
FROM MyView AS V (nolock)
INNER JOIN [MYTable] AS A (nolock)
ON A.Id = V.Id
WHERE A.Pid = 9
AND ( Isnull(A.ID, 0) <> Isnull(V.ID, 0)
OR Isnull(A.FacilityPatientID, '') <> Isnull(V.FacilityPatientID, '')
OR Isnull(A.FirstName, '') <> Isnull(V.FirstName, '')
OR Isnull(A.MiddleInitial, '') <> Isnull(V.MiddleInitial, '')
OR Isnull(A.LastName, '') <> Isnull(V.LastName, '')
OR Isnull(A.SSN, '') <> Isnull(V.SSN, '')
OR Isnull(A.Sex, '') <> Isnull(V.Sex, '')
OR Isnull(A.DOB, '') <> Isnull(V.DOB, '')
OR Isnull(A.EncounterID, '') <> Isnull(V.EncounterID, '')
OR Isnull(A.IDX, '') <> Isnull(V.IDX, '')
OR Isnull(A.MS4, '') <> Isnull(V.MS4, '')
OR Isnull(A.PersonID, 0) <> Isnull(V.PersonID, 0)
OR Isnull(A.GuarantorID, 0) <> Isnull(V.GuarantorID, 0)
OR Isnull(A.PatientType, '') <> Isnull(V.PatientType, '')
OR Isnull(A.FacilityPatientType, '') <> Isnull(V.FacilityPatientType, '')
OR Isnull(A.AdmitDate, '') <> Isnull(V.AdmitDate, '')
OR Isnull(A.PayerType, '') <> Isnull(V.PayerType, '')
OR Isnull(A.FacilityCode, '') <> Isnull(V.FacilityCode, '')
OR Isnull(A.Phone, '') <> Isnull(V.Phone, '')
OR Isnull(A.Address, '') <> Isnull(V.Address, '')
OR Isnull(A.Address2, '') <> Isnull(V.Address2, '')
OR Isnull(A.City, '') <> Isnull(V.City, '')
OR Isnull(A.State, '') <> Isnull(V.State, '')
OR Isnull(A.Zip, '') <> Isnull(V.Zip, '')
OR Isnull(A.FacilityPlanCode, '') <> Isnull(V.FacilityPlanCode, '')
OR Isnull(A.VerificationStatus, 0) <> Isnull(V.VerificationStatus, 0)
OR Isnull(A.PayorCode, '') <> Isnull(V.PayorCode, '')
OR Isnull(A.PayorName, '') <> Isnull(V.PayorName, '')
OR Isnull(A.ServiceFieldCode, '') <> Isnull(V.ServiceFieldCode, '')
OR Isnull(A.ResidualBalance, 0) <> Isnull(V.ResidualBalance, 0)
OR Isnull(A.IsScheduled, 0) <> Isnull(V.IsScheduled, 0)
OR Isnull(A.IsAdmitted, 0) <> Isnull(V.IsAdmitted, 0)
OR Isnull(A.IsDischarged, 0) <> Isnull(V.IsDischarged, 0)
OR Isnull(A.IsFinalBilled, 0) <> Isnull(V.IsFinalBilled, 0)
OR Isnull(A.BilledDate, '1/1/1900') <> Isnull(V.BilledDate, '1/1/1900')
OR Isnull(A.BilledAmount, 0) <> Isnull(V.BilledAmount, 0)
OR Isnull(A.TotalBalance, 0) <> Isnull(V.TotalBalance, 0)
OR Isnull(A.PatientBalance, 0) <> Isnull(V.PatientBalance, 0)
OR Isnull(A.PayorBalance, 0) <> Isnull(V.PayorBalance, 0)
OR Isnull(A.WriteOff, 0) <> Isnull(V.WriteOff, 0)
OR Isnull(A.PriorBalance, 0) <> Isnull(V.PriorBalance, 0)
OR Isnull(A.Collected, 0) <> Isnull(V.Collected, 0)
OR Isnull(A.CollectionDate, '') <> Isnull(V.CollectionDate, '')
OR Isnull(A.CollectionMethod, '') <> Isnull(V.CollectionMethod, '')
OR Isnull(A.NonCollectionReasonId, 0) <> Isnull(V.NonCollectionReasonId, 0)
OR Isnull(A.CustomerSatisfaction, 0) <> Isnull(V.CustomerSatisfaction, 0)
OR Isnull(A.CollectedBy, 0) <> Isnull(V.CollectedBy, 0)
OR Isnull(A.EstimatedResidual, 0) <> Isnull(V.EstimatedResidual, 0)
OR Isnull(A.TaskStatus_P, 0) <> Isnull(V.TaskStatus_P, 0)
OR Isnull(A.TaskStatus_C, 0) <> Isnull(V.TaskStatus_C, 0)
OR Isnull(A.TaskStatus_S, 0) <> Isnull(V.TaskStatus_S, 0)
OR Isnull(A.TaskStatus_R, 0) <> Isnull(V.TaskStatus_R, 0)
OR Isnull(A.TaskStatus_MN, 0) <> Isnull(V.TaskStatus_MN, 0)
OR Isnull(A.TaskStatus_ATH, 0) <> Isnull(V.TaskStatus_ATH, 0)
OR Isnull(A.TaskStatus_HIS, 0) <> Isnull(V.TaskStatus_HIS, 0)
OR Isnull(A.InsertDate, '1/1/1900') <> Isnull(V.InsertDate, '1/1/1900')
OR Isnull(A.PlanType, '') <> Isnull(V.PlanType, '')
OR Isnull(A.SubscriberCode, '') <> Isnull(V.SubscriberCode, '')
OR Isnull(A.ServicePointCode, '') <> Isnull(V.ServicePointCode, '')
OR Isnull(A.CurrentFinancialClass, '') <> Isnull(V.CurrentFinancialClass, '')
OR Isnull(A.DischargeDate, '') <> Isnull(V.DischargeDate, '')
OR Isnull(A.BusinessRuleID, '') <> Isnull(V.BusinessRuleID, '')
OR Isnull(A.TaskExceptionID, '') <> Isnull(V.TaskExceptionID, '')
OR Isnull(A.TotalCharges, 0) <> Isnull(V.TotalCharges, 0)
OR Isnull(A.BadDebt, 0) <> Isnull(V.BadDebt, 0) )
--rollback tran