2

Given a DB view with 2.5 million entries. Following query executes in ~57 seconds:

SELECT 

Extent1.AniAliNumber AS AniAliNumber, 

Extent1.Apartment AS Apartment, 

Extent1.Area AS Area, 

Extent1.CallId AS CallId, 

Extent1.CallSource AS CallSource, 

Extent1.CallerCityStateZipCode AS CallerCityStateZipCode, 

Extent1.CallerName AS CallerName, 

Extent1.CallerPhone AS CallerPhone, 

Extent1.CallerPhoneLong AS CallerPhoneLong, 

Extent1.CallerStreetAddress AS CallerStreetAddress, 

Extent1.CommonEventCustom1 AS CommonEventCustom1, 

Extent1.CommonEventCustom2 AS CommonEventCustom2, 

Extent1.CommonEventCustom3 AS CommonEventCustom3, 

Extent1.CommonEventCustom4 AS CommonEventCustom4, 

Extent1.CommonEventId AS CommonEventId, 

Extent1.CommonplaceName AS CommonplaceName, 

Extent1.CreatedEmployeeId AS CreatedEmployeeId, 

Extent1.CreatedTerminal AS CreatedTerminal, 

convert(varchar(40),Extent1.CreatedTime,121) AS CreatedTime, 

Extent1.CrossStreet1 AS CrossStreet1, 

Extent1.CrossStreet2 AS CrossStreet2, 

Extent1.DirectionPrefix AS DirectionPrefix, 

Extent1.DirectionSuffix AS DirectionSuffix, 

Extent1.EreignisSw AS EreignisSw, 

Extent1.HasInformerLoiData AS HasInformerLoiData, 

Extent1.HasLoiData AS HasLoiData, 

Extent1.HasSpecialSituatonLoiData AS HasSpecialSituatonLoiData, 

Extent1.HasTemporaryLock AS HasTemporaryLock, 

Extent1.IsLocationVerified AS IsLocationVerified, 

Extent1.Location1 AS Location1, 

Extent1.Location2 AS Location2, 

Extent1.Location3 AS Location3, 

Extent1.Location4 AS Location4, 

Extent1.LocationComment AS LocationComment, 

Extent1.LockingTerminal AS LockingTerminal, 

Extent1.MapLevels AS MapLevels, 

Extent1.MapSegmentId AS MapSegmentId, 

Extent1.Municipality AS Municipality, 

Extent1.ParseType AS ParseType, 

Extent1.PatientName AS PatientName, 

Extent1.ProQACadCaseId AS ProQACadCaseId, 

Extent1.RevisionEmployeeId AS RevisionEmployeeId, 

Extent1.RevisionNumber AS RevisionNumber, 

Extent1.RevisionTerminal AS RevisionTerminal, 

convert(varchar(40),Extent1.RevisionTime,121) AS RevisionTime, 

Extent1.StreetName AS StreetName, 

Extent1.StreetNameHash AS StreetNameHash, 

Extent1.StreetNumber AS StreetNumber, 

Extent1.StreetType AS StreetType, 

Extent1.SystemEsz AS SystemEsz, 

Extent1.UpdatedEmployeeId AS UpdatedEmployeeId, 

Extent1.UpdatedTerminal AS UpdatedTerminal, 

convert(varchar(40),Extent1.UpdatedTime,121) AS UpdatedTime, 

Extent1.XCoordinate AS XCoordinate, 

Extent1.YCoordinate AS YCoordinate, 

Extent1.ZipCode AS ZipCode

FROM cmvCommonEvent Extent1

WHERE (((((((((3562574 = Extent1.CommonEventId) OR (3563557 = Extent1.CommonEventId)) OR ((3563586 = Extent1.CommonEventId) OR (3563611 = Extent1.CommonEventId))) OR (((3563633 = Extent1.CommonEventId) OR (3563639 = Extent1.CommonEventId)) OR ((3563651 = Extent1.CommonEventId) OR (3563679 = Extent1.CommonEventId)))) OR ((((3563701 = Extent1.CommonEventId) OR (3563720 = Extent1.CommonEventId)) OR ((3563722 = Extent1.CommonEventId) OR (3563723 = Extent1.CommonEventId))) OR (((3563735 = Extent1.CommonEventId) OR (3563744 = Extent1.CommonEventId)) OR ((3563756 = Extent1.CommonEventId) OR (3563763 = Extent1.CommonEventId))))) OR (((((3563764 = Extent1.CommonEventId) OR (3563772 = Extent1.CommonEventId)) OR ((3563776 = Extent1.CommonEventId) OR (3563777 = Extent1.CommonEventId))) OR (((3563783 = Extent1.CommonEventId) OR (3563786 = Extent1.CommonEventId)) OR ((3563796 = Extent1.CommonEventId) OR (3563801 = Extent1.CommonEventId)))) OR ((((3563803 = Extent1.CommonEventId) OR (3563804 = Extent1.CommonEventId)) OR ((3563807 = Extent1.CommonEventId) OR (3563816 = Extent1.CommonEventId))) OR (((3563820 = Extent1.CommonEventId) OR (3563824 = Extent1.CommonEventId)) OR ((3563830 = Extent1.CommonEventId) OR (3563837 = Extent1.CommonEventId)))))) OR ((((((3563843 = Extent1.CommonEventId) OR (3563847 = Extent1.CommonEventId)) OR ((3563850 = Extent1.CommonEventId) OR (3563856 = Extent1.CommonEventId))) OR (((3563862 = Extent1.CommonEventId) OR (3563871 = Extent1.CommonEventId)) OR ((3563874 = Extent1.CommonEventId) OR (3563888 = Extent1.CommonEventId)))) OR ((((3563893 = Extent1.CommonEventId) OR (3563899 = Extent1.CommonEventId)) OR ((3563915 = Extent1.CommonEventId) OR (3563919 = Extent1.CommonEventId))) OR (((3563936 = Extent1.CommonEventId) OR (3563938 = Extent1.CommonEventId)) OR ((3563944 = Extent1.CommonEventId) OR (3563950 = Extent1.CommonEventId))))) OR (((((3563961 = Extent1.CommonEventId) OR (3563962 = Extent1.CommonEventId)) OR ((3563963 = Extent1.CommonEventId) OR (3563972 = Extent1.CommonEventId))) OR (((3563979 = Extent1.CommonEventId) OR (3563993 = Extent1.CommonEventId)) OR ((3563997 = Extent1.CommonEventId) OR (3564001 = Extent1.CommonEventId)))) OR ((((3564008 = Extent1.CommonEventId) OR (3564009 = Extent1.CommonEventId)) OR ((3564019 = Extent1.CommonEventId) OR (3564025 = Extent1.CommonEventId))) OR (((3564031 = Extent1.CommonEventId) OR (3564038 = Extent1.CommonEventId)) OR ((3564042 = Extent1.CommonEventId) OR (3564043 = Extent1.CommonEventId))))))) OR (((((((3564046 = Extent1.CommonEventId) OR (3564060 = Extent1.CommonEventId)) OR ((3564089 = Extent1.CommonEventId) OR (3564099 = Extent1.CommonEventId))) OR (((3564100 = Extent1.CommonEventId) OR (3564104 = Extent1.CommonEventId)) OR ((3564109 = Extent1.CommonEventId) OR (3564110 = Extent1.CommonEventId)))) OR ((((3564125 = Extent1.CommonEventId) OR (3564128 = Extent1.CommonEventId)) OR ((3564145 = Extent1.CommonEventId) OR (3564146 = Extent1.CommonEventId))) OR (((3564152 = Extent1.CommonEventId) OR (3564159 = Extent1.CommonEventId)) OR ((3564174 = Extent1.CommonEventId) OR (3564175 = Extent1.CommonEventId))))) OR (((((3564180 = Extent1.CommonEventId) OR (3564190 = Extent1.CommonEventId)) OR ((3564196 = Extent1.CommonEventId) OR (3564213 = Extent1.CommonEventId))) OR (((3564218 = Extent1.CommonEventId) OR (3564222 = Extent1.CommonEventId)) OR ((3564223 = Extent1.CommonEventId) OR (3564241 = Extent1.CommonEventId)))) OR ((((3564245 = Extent1.CommonEventId) OR (3564250 = Extent1.CommonEventId)) OR ((3564282 = Extent1.CommonEventId) OR (3564295 = Extent1.CommonEventId))) OR (((3564319 = Extent1.CommonEventId) OR (3564322 = Extent1.CommonEventId)) OR ((3564328 = Extent1.CommonEventId) OR (3564329 = Extent1.CommonEventId)))))) OR ((((((3564340 = Extent1.CommonEventId) OR (3564352 = Extent1.CommonEventId)) OR ((3564356 = Extent1.CommonEventId) OR (3564357 = Extent1.CommonEventId))) OR (((3564366 = Extent1.CommonEventId) OR (3564371 = Extent1.CommonEventId)) OR ((3564390 = Extent1.CommonEventId) OR (3564391 = Extent1.CommonEventId)))) OR ((((3564394 = Extent1.CommonEventId) OR (3564395 = Extent1.CommonEventId)) OR ((3564404 = Extent1.CommonEventId) OR (3564407 = Extent1.CommonEventId))) OR (((3564416 = Extent1.CommonEventId) OR (3564418 = Extent1.CommonEventId)) OR ((3564421 = Extent1.CommonEventId) OR (3564425 = Extent1.CommonEventId))))) OR (((((3564429 = Extent1.CommonEventId) OR (3564433 = Extent1.CommonEventId)) OR ((3564445 = Extent1.CommonEventId) OR (3564452 = Extent1.CommonEventId))) OR (((3564455 = Extent1.CommonEventId) OR (3564464 = Extent1.CommonEventId)) OR ((3564469 = Extent1.CommonEventId) OR (3564471 = Extent1.CommonEventId)))) OR ((((3564484 = Extent1.CommonEventId) OR (3564486 = Extent1.CommonEventId)) OR ((3564498 = Extent1.CommonEventId) OR (3564507 = Extent1.CommonEventId))) OR (((3564514 = Extent1.CommonEventId) OR (3564518 = Extent1.CommonEventId)) OR ((3564523 = Extent1.CommonEventId) OR (3564527 = Extent1.CommonEventId)))))))) OR ((((((((3564534 = Extent1.CommonEventId) OR (3564546 = Extent1.CommonEventId)) OR ((3564555 = Extent1.CommonEventId) OR (3564584 = Extent1.CommonEventId))) OR (((3564610 = Extent1.CommonEventId) OR (3564615 = Extent1.CommonEventId)) OR ((3564617 = Extent1.CommonEventId) OR (3564625 = Extent1.CommonEventId)))) OR ((((3564628 = Extent1.CommonEventId) OR (3564646 = Extent1.CommonEventId)) OR ((3564650 = Extent1.CommonEventId) OR (3564654 = Extent1.CommonEventId))) OR (((3564657 = Extent1.CommonEventId) OR (3564661 = Extent1.CommonEventId)) OR ((3564666 = Extent1.CommonEventId) OR (3564672 = Extent1.CommonEventId))))) OR (((((3564682 = Extent1.CommonEventId) OR (3564685 = Extent1.CommonEventId)) OR ((3564701 = Extent1.CommonEventId) OR (3564719 = Extent1.CommonEventId))) OR (((3564727 = Extent1.CommonEventId) OR (3564734 = Extent1.CommonEventId)) OR ((3564736 = Extent1.CommonEventId) OR (3564737 = Extent1.CommonEventId)))) OR ((((3564748 = Extent1.CommonEventId) OR (3564762 = Extent1.CommonEventId)) OR ((3564766 = Extent1.CommonEventId) OR (3564775 = Extent1.CommonEventId))) OR (((3564782 = Extent1.CommonEventId) OR (3564789 = Extent1.CommonEventId)) OR ((3564804 = Extent1.CommonEventId) OR (3564805 = Extent1.CommonEventId)))))) OR ((((((3564811 = Extent1.CommonEventId) OR (3564821 = Extent1.CommonEventId)) OR ((3564831 = Extent1.CommonEventId) OR (3564836 = Extent1.CommonEventId))) OR (((3564841 = Extent1.CommonEventId) OR (3564870 = Extent1.CommonEventId)) OR ((3564871 = Extent1.CommonEventId) OR (3564880 = Extent1.CommonEventId)))) OR ((((3564898 = Extent1.CommonEventId) OR (3564906 = Extent1.CommonEventId)) OR ((3564909 = Extent1.CommonEventId) OR (3564929 = Extent1.CommonEventId))) OR (((3564937 = Extent1.CommonEventId) OR (3564944 = Extent1.CommonEventId)) OR ((3564959 = Extent1.CommonEventId) OR (3564968 = Extent1.CommonEventId))))) OR (((((3564991 = Extent1.CommonEventId) OR (3565004 = Extent1.CommonEventId)) OR ((3565009 = Extent1.CommonEventId) OR (3565011 = Extent1.CommonEventId))) OR (((3565016 = Extent1.CommonEventId) OR (3565019 = Extent1.CommonEventId)) OR ((3565029 = Extent1.CommonEventId) OR (3565030 = Extent1.CommonEventId)))) OR ((((3565031 = Extent1.CommonEventId) OR (3565034 = Extent1.CommonEventId)) OR ((3565036 = Extent1.CommonEventId) OR (3565043 = Extent1.CommonEventId))) OR (((3565044 = Extent1.CommonEventId) OR (3565046 = Extent1.CommonEventId)) OR ((3565061 = Extent1.CommonEventId) OR (3565068 = Extent1.CommonEventId))))))) OR (((((((3565073 = Extent1.CommonEventId) OR (3565074 = Extent1.CommonEventId)) OR ((3565083 = Extent1.CommonEventId) OR (3565099 = Extent1.CommonEventId))) OR (((3565106 = Extent1.CommonEventId) OR (3565108 = Extent1.CommonEventId)) OR ((3565110 = Extent1.CommonEventId) OR (3565113 = Extent1.CommonEventId)))) OR ((((3565119 = Extent1.CommonEventId) OR (3565123 = Extent1.CommonEventId)) OR ((3565132 = Extent1.CommonEventId) OR (3565136 = Extent1.CommonEventId))) OR (((3565158 = Extent1.CommonEventId) OR (3565159 = Extent1.CommonEventId)) OR ((3565169 = Extent1.CommonEventId) OR (3565170 = Extent1.CommonEventId))))) OR (((((3565174 = Extent1.CommonEventId) OR (3565179 = Extent1.CommonEventId)) OR ((3565184 = Extent1.CommonEventId) OR (3565190 = Extent1.CommonEventId))) OR (((3565210 = Extent1.CommonEventId) OR (3565216 = Extent1.CommonEventId)) OR ((3565227 = Extent1.CommonEventId) OR (3565229 = Extent1.CommonEventId)))) OR ((((3565235 = Extent1.CommonEventId) OR (3565242 = Extent1.CommonEventId)) OR ((3565252 = Extent1.CommonEventId) OR (3565254 = Extent1.CommonEventId))) OR (((3565260 = Extent1.CommonEventId) OR (3565262 = Extent1.CommonEventId)) OR ((3565263 = Extent1.CommonEventId) OR (3565279 = Extent1.CommonEventId)))))) OR ((((((3565283 = Extent1.CommonEventId) OR (3565287 = Extent1.CommonEventId)) OR ((3565288 = Extent1.CommonEventId) OR (3565290 = Extent1.CommonEventId))) OR (((3565292 = Extent1.CommonEventId) OR (3565316 = Extent1.CommonEventId)) OR ((3565318 = Extent1.CommonEventId) OR (3565344 = Extent1.CommonEventId)))) OR ((((3565390 = Extent1.CommonEventId) OR (3565395 = Extent1.CommonEventId)) OR ((3565404 = Extent1.CommonEventId) OR (3565409 = Extent1.CommonEventId))) OR (((3565428 = Extent1.CommonEventId) OR (3565431 = Extent1.CommonEventId)) OR ((3565434 = Extent1.CommonEventId) OR (3565436 = Extent1.CommonEventId))))) OR (((((3565440 = Extent1.CommonEventId) OR (3565442 = Extent1.CommonEventId)) OR ((3565446 = Extent1.CommonEventId) OR (3565464 = Extent1.CommonEventId))) OR (((3565472 = Extent1.CommonEventId) OR (3565487 = Extent1.CommonEventId)) OR ((3565488 = Extent1.CommonEventId) OR (3565493 = Extent1.CommonEventId)))) OR ((((3565498 = Extent1.CommonEventId) OR (3565509 = Extent1.CommonEventId)) OR ((3565512 = Extent1.CommonEventId) OR (3565516 = Extent1.CommonEventId))) OR (((3565538 = Extent1.CommonEventId) OR (3565545 = Extent1.CommonEventId)) OR ((3565547 = Extent1.CommonEventId) OR (3565555 = Extent1.CommonEventId))))))))) OR (((((((((3565559 = Extent1.CommonEventId) OR (3565562 = Extent1.CommonEventId)) OR ((3565572 = Extent1.CommonEventId) OR (3565575 = Extent1.CommonEventId))) OR (((3565576 = Extent1.CommonEventId) OR (3565595 = Extent1.CommonEventId)) OR ((3565605 = Extent1.CommonEventId) OR (3565610 = Extent1.CommonEventId)))) OR ((((3565624 = Extent1.CommonEventId) OR (3565630 = Extent1.CommonEventId)) OR ((3565639 = Extent1.CommonEventId) OR (3565660 = Extent1.CommonEventId))) OR (((3565679 = Extent1.CommonEventId) OR (3565685 = Extent1.CommonEventId)) OR ((3565689 = Extent1.CommonEventId) OR (3565698 = Extent1.CommonEventId))))) OR (((((3565706 = Extent1.CommonEventId) OR (3565709 = Extent1.CommonEventId)) OR ((3565716 = Extent1.CommonEventId) OR (3565721 = Extent1.CommonEventId))) OR (((3565737 = Extent1.CommonEventId) OR (3565740 = Extent1.CommonEventId)) OR ((3565748 = Extent1.CommonEventId) OR (3565758 = Extent1.CommonEventId)))) OR ((((3565769 = Extent1.CommonEventId) OR (3565776 = Extent1.CommonEventId)) OR ((3565785 = Extent1.CommonEventId) OR (3565794 = Extent1.CommonEventId))) OR (((3565797 = Extent1.CommonEventId) OR (3565799 = Extent1.CommonEventId)) OR ((3565805 = Extent1.CommonEventId) OR (3565818 = Extent1.CommonEventId)))))) OR ((((((3565846 = Extent1.CommonEventId) OR (3565847 = Extent1.CommonEventId)) OR ((3565848 = Extent1.CommonEventId) OR (3565865 = Extent1.CommonEventId))) OR (((3565873 = Extent1.CommonEventId) OR (3565885 = Extent1.CommonEventId)) OR ((3565893 = Extent1.CommonEventId) OR (3565895 = Extent1.CommonEventId)))) OR ((((3565896 = Extent1.CommonEventId) OR (3565902 = Extent1.CommonEventId)) OR ((3565935 = Extent1.CommonEventId) OR (3565946 = Extent1.CommonEventId))) OR (((3565952 = Extent1.CommonEventId) OR (3565953 = Extent1.CommonEventId)) OR ((3565988 = Extent1.CommonEventId) OR (3566001 = Extent1.CommonEventId))))) OR (((((3566005 = Extent1.CommonEventId) OR (3566011 = Extent1.CommonEventId)) OR ((3566013 = Extent1.CommonEventId) OR (3566017 = Extent1.CommonEventId))) OR (((3566028 = Extent1.CommonEventId) OR (3566031 = Extent1.CommonEventId)) OR ((3566034 = Extent1.CommonEventId) OR (3566042 = Extent1.CommonEventId)))) OR ((((3566051 = Extent1.CommonEventId) OR (3566055 = Extent1.CommonEventId)) OR ((3566059 = Extent1.CommonEventId) OR (3566066 = Extent1.CommonEventId))) OR (((3566069 = Extent1.CommonEventId) OR (3566075 = Extent1.CommonEventId)) OR ((3566077 = Extent1.CommonEventId) OR (3566079 = Extent1.CommonEventId))))))) OR (((((((3566086 = Extent1.CommonEventId) OR (3566088 = Extent1.CommonEventId)) OR ((3566094 = Extent1.CommonEventId) OR (3566102 = Extent1.CommonEventId))) OR (((3566114 = Extent1.CommonEventId) OR (3566123 = Extent1.CommonEventId)) OR ((3566127 = Extent1.CommonEventId) OR (3566136 = Extent1.CommonEventId)))) OR ((((3566151 = Extent1.CommonEventId) OR (3566154 = Extent1.CommonEventId)) OR ((3566162 = Extent1.CommonEventId) OR (3566179 = Extent1.CommonEventId))) OR (((3566223 = Extent1.CommonEventId) OR (3566228 = Extent1.CommonEventId)) OR ((3566248 = Extent1.CommonEventId) OR (3566255 = Extent1.CommonEventId))))) OR (((((3566256 = Extent1.CommonEventId) OR (3566258 = Extent1.CommonEventId)) OR ((3566268 = Extent1.CommonEventId) OR (3566272 = Extent1.CommonEventId))) OR (((3566281 = Extent1.CommonEventId) OR (3566289 = Extent1.CommonEventId)) OR ((3566290 = Extent1.CommonEventId) OR (3566301 = Extent1.CommonEventId)))) OR ((((3566308 = Extent1.CommonEventId) OR (3566312 = Extent1.CommonEventId)) OR ((3566314 = Extent1.CommonEventId) OR (3566328 = Extent1.CommonEventId))) OR (((3566340 = Extent1.CommonEventId) OR (3566352 = Extent1.CommonEventId)) OR ((3566363 = Extent1.CommonEventId) OR (3566370 = Extent1.CommonEventId)))))) OR ((((((3566386 = Extent1.CommonEventId) OR (3566387 = Extent1.CommonEventId)) OR ((3566388 = Extent1.CommonEventId) OR (3566402 = Extent1.CommonEventId))) OR (((3566403 = Extent1.CommonEventId) OR (3566410 = Extent1.CommonEventId)) OR ((3566420 = Extent1.CommonEventId) OR (3566430 = Extent1.CommonEventId)))) OR ((((3566445 = Extent1.CommonEventId) OR (3566448 = Extent1.CommonEventId)) OR ((3566462 = Extent1.CommonEventId) OR (3566477 = Extent1.CommonEventId))) OR (((3566507 = Extent1.CommonEventId) OR (3566510 = Extent1.CommonEventId)) OR ((3566515 = Extent1.CommonEventId) OR (3566519 = Extent1.CommonEventId))))) OR (((((3566520 = Extent1.CommonEventId) OR (3566529 = Extent1.CommonEventId)) OR ((3566534 = Extent1.CommonEventId) OR (3566536 = Extent1.CommonEventId))) OR (((3566537 = Extent1.CommonEventId) OR (3566546 = Extent1.CommonEventId)) OR ((3566547 = Extent1.CommonEventId) OR (3566565 = Extent1.CommonEventId)))) OR ((((3566584 = Extent1.CommonEventId) OR (3566595 = Extent1.CommonEventId)) OR ((3566599 = Extent1.CommonEventId) OR (3566629 = Extent1.CommonEventId))) OR (((3566640 = Extent1.CommonEventId) OR (3566645 = Extent1.CommonEventId)) OR ((3566647 = Extent1.CommonEventId) OR (3566675 = Extent1.CommonEventId)))))))) OR ((((((((3566693 = Extent1.CommonEventId) OR (3566694 = Extent1.CommonEventId)) OR ((3566701 = Extent1.CommonEventId) OR (3566704 = Extent1.CommonEventId))) OR (((3566708 = Extent1.CommonEventId) OR (3566715 = Extent1.CommonEventId)) OR ((3566728 = Extent1.CommonEventId) OR (3566745 = Extent1.CommonEventId)))) OR ((((3566757 = Extent1.CommonEventId) OR (3566763 = Extent1.CommonEventId)) OR ((3566780 = Extent1.CommonEventId) OR (3566805 = Extent1.CommonEventId))) OR (((3566808 = Extent1.CommonEventId) OR (3566813 = Extent1.CommonEventId)) OR ((3566817 = Extent1.CommonEventId) OR (3566826 = Extent1.CommonEventId))))) OR (((((3566835 = Extent1.CommonEventId) OR (3566838 = Extent1.CommonEventId)) OR ((3566846 = Extent1.CommonEventId) OR (3566857 = Extent1.CommonEventId))) OR (((3566874 = Extent1.CommonEventId) OR (3566880 = Extent1.CommonEventId)) OR ((3566890 = Extent1.CommonEventId) OR (3566894 = Extent1.CommonEventId)))) OR ((((3566902 = Extent1.CommonEventId) OR (3566915 = Extent1.CommonEventId)) OR ((3566927 = Extent1.CommonEventId) OR (3566929 = Extent1.CommonEventId))) OR (((3566936 = Extent1.CommonEventId) OR (3566948 = Extent1.CommonEventId)) OR ((3566952 = Extent1.CommonEventId) OR (3566960 = Extent1.CommonEventId)))))) OR ((((((3566970 = Extent1.CommonEventId) OR (3566976 = Extent1.CommonEventId)) OR ((3566977 = Extent1.CommonEventId) OR (3566980 = Extent1.CommonEventId))) OR (((3566984 = Extent1.CommonEventId) OR (3566989 = Extent1.CommonEventId)) OR ((3566996 = Extent1.CommonEventId) OR (3567002 = Extent1.CommonEventId)))) OR ((((3567014 = Extent1.CommonEventId) OR (3567035 = Extent1.CommonEventId)) OR ((3567042 = Extent1.CommonEventId) OR (3567050 = Extent1.CommonEventId))) OR (((3567061 = Extent1.CommonEventId) OR (3567062 = Extent1.CommonEventId)) OR ((3567074 = Extent1.CommonEventId) OR (3567082 = Extent1.CommonEventId))))) OR (((((3567086 = Extent1.CommonEventId) OR (3567089 = Extent1.CommonEventId)) OR ((3567090 = Extent1.CommonEventId) OR (3567094 = Extent1.CommonEventId))) OR (((3567103 = Extent1.CommonEventId) OR (3567108 = Extent1.CommonEventId)) OR ((3567113 = Extent1.CommonEventId) OR (3567117 = Extent1.CommonEventId)))) OR ((((3567130 = Extent1.CommonEventId) OR (3567134 = Extent1.CommonEventId)) OR ((3567137 = Extent1.CommonEventId) OR (3567139 = Extent1.CommonEventId))) OR (((3567142 = Extent1.CommonEventId) OR (3567168 = Extent1.CommonEventId)) OR ((3567169 = Extent1.CommonEventId) OR (3567186 = Extent1.CommonEventId))))))) OR (((((((3567192 = Extent1.CommonEventId) OR (3567196 = Extent1.CommonEventId)) OR ((3567209 = Extent1.CommonEventId) OR (3567210 = Extent1.CommonEventId))) OR (((3567233 = Extent1.CommonEventId) OR (3567234 = Extent1.CommonEventId)) OR ((3567239 = Extent1.CommonEventId) OR (3567240 = Extent1.CommonEventId)))) OR ((((3567244 = Extent1.CommonEventId) OR (3567264 = Extent1.CommonEventId)) OR ((3567285 = Extent1.CommonEventId) OR (3567288 = Extent1.CommonEventId))) OR (((3567296 = Extent1.CommonEventId) OR (3567302 = Extent1.CommonEventId)) OR ((3567308 = Extent1.CommonEventId) OR (3567312 = Extent1.CommonEventId))))) OR (((((3567330 = Extent1.CommonEventId) OR (3567336 = Extent1.CommonEventId)) OR ((3567344 = Extent1.CommonEventId) OR (3567347 = Extent1.CommonEventId))) OR (((3567361 = Extent1.CommonEventId) OR (3567374 = Extent1.CommonEventId)) OR ((3567382 = Extent1.CommonEventId) OR (3567384 = Extent1.CommonEventId)))) OR ((((3567394 = Extent1.CommonEventId) OR (3567401 = Extent1.CommonEventId)) OR ((3567412 = Extent1.CommonEventId) OR (3567415 = Extent1.CommonEventId))) OR (((3567425 = Extent1.CommonEventId) OR (3567427 = Extent1.CommonEventId)) OR ((3567434 = Extent1.CommonEventId) OR (3567444 = Extent1.CommonEventId)))))) OR (((((3567451 = Extent1.CommonEventId) OR (3567465 = Extent1.CommonEventId)) OR ((3567474 = Extent1.CommonEventId) OR (3567487 = Extent1.CommonEventId))) OR (((3567491 = Extent1.CommonEventId) OR (3567496 = Extent1.CommonEventId)) OR ((3567497 = Extent1.CommonEventId) OR (3567507 = Extent1.CommonEventId)))) OR (((((3567519 = Extent1.CommonEventId) OR (3567523 = Extent1.CommonEventId)) OR ((3567533 = Extent1.CommonEventId) OR (3567554 = Extent1.CommonEventId))) OR (((3567594 = Extent1.CommonEventId) OR (3567611 = Extent1.CommonEventId)) OR ((3567621 = Extent1.CommonEventId) OR (3567630 = Extent1.CommonEventId)))) OR (((3567633 = Extent1.CommonEventId) OR (3567640 = Extent1.CommonEventId)) OR ((3567647 = Extent1.CommonEventId) OR (3567664 = Extent1.CommonEventId))))))))

Execution plan OR

Following query executes in ~0 seconds with the same result:

SELECT 

//same as above

FROM cmvCommonEvent Extent1

WHERE Extent1.CommonEventId in (3562574,3563557,3563586,3563611,3563633,3563639,3563651,3563679,3563701,3563720,3563722,3563723,3563735,3563744,3563756,3563763,3563764,3563772,3563776,3563777,3563783,3563786,3563796,3563801,3563803,3563804,3563807,3563816,3563820,3563824,3563830,3563837,3563843,3563847,3563850,3563856,3563862,3563871,3563874,3563888,3563893,3563899,3563915,3563919,3563936,3563938,3563944,3563950,3563961,3563962,3563963,3563972,3563979,3563993,3563997,3564001,3564008,3564009,3564019,3564025,3564031,3564038,3564042,3564043,3564046,3564060,3564089,3564099,3564100,3564104,3564109,3564110,3564125,3564128,3564145,3564146,3564152,3564159,3564174,3564175,3564180,3564190,3564196,3564213,3564218,3564222,3564223,3564241,3564245,3564250,3564282,3564295,3564319,3564322,3564328,3564329,3564340,3564352,3564356,3564357,3564366,3564371,3564390,3564391,3564394,3564395,3564404,3564407,3564416,3564418,3564421,3564425,3564429,3564433,3564445,3564452,3564455,3564464,3564469,3564471,3564484,3564486,3564498,3564507,3564514,3564518,3564523,3564527,3564534,3564546,3564555,3564584,3564610,3564615,3564617,3564625,3564628,3564646,3564650,3564654,3564657,3564661,3564666,3564672,3564682,3564685,3564701,3564719,3564727,3564734,3564736,3564737,3564748,3564762,3564766,3564775,3564782,3564789,3564804,3564805,3564811,3564821,3564831,3564836,3564841,3564870,3564871,3564880,3564898,3564906,3564909,3564929,3564937,3564944,3564959,3564968,3564991,3565004,3565009,3565011,3565016,3565019,3565029,3565030,3565031,3565034,3565036,3565043,3565044,3565046,3565061,3565068,3565073,3565074,3565083,3565099,3565106,3565108,3565110,3565113,3565119,3565123,3565132,3565136,3565158,3565159,3565169,3565170,3565174,3565179,3565184,3565190,3565210,3565216,3565227,3565229,3565235,3565242,3565252,3565254,3565260,3565262,3565263,3565279,3565283,3565287,3565288,3565290,3565292,3565316,3565318,3565344,3565390,3565395,3565404,3565409,3565428,3565431,3565434,3565436,3565440,3565442,3565446,3565464,3565472,3565487,3565488,3565493,3565498,3565509,3565512,3565516,3565538,3565545,3565547,3565555,3565559,3565562,3565572,3565575,3565576,3565595,3565605,3565610,3565624,3565630,3565639,3565660,3565679,3565685,3565689,3565698,3565706,3565709,3565716,3565721,3565737,3565740,3565748,3565758,3565769,3565776,3565785,3565794,3565797,3565799,3565805,3565818,3565846,3565847,3565848,3565865,3565873,3565885,3565893,3565895,3565896,3565902,3565935,3565946,3565952,3565953,3565988,3566001,3566005,3566011,3566013,3566017,3566028,3566031,3566034,3566042,3566051,3566055,3566059,3566066,3566069,3566075,3566077,3566079,3566086,3566088,3566094,3566102,3566114,3566123,3566127,3566136,3566151,3566154,3566162,3566179,3566223,3566228,3566248,3566255,3566256,3566258,3566268,3566272,3566281,3566289,3566290,3566301,3566308,3566312,3566314,3566328,3566340,3566352,3566363,3566370,3566386,3566387,3566388,3566402,3566403,3566410,3566420,3566430,3566445,3566448,3566462,3566477,3566507,3566510,3566515,3566519,3566520,3566529,3566534,3566536,3566537,3566546,3566547,3566565,3566584,3566595,3566599,3566629,3566640,3566645,3566647,3566675,3566693,3566694,3566701,3566704,3566708,3566715,3566728,3566745,3566757,3566763,3566780,3566805,3566808,3566813,3566817,3566826,3566835,3566838,3566846,3566857,3566874,3566880,3566890,3566894,3566902,3566915,3566927,3566929,3566936,3566948,3566952,3566960,3566970,3566976,3566977,3566980,3566984,3566989,3566996,3567002,3567014,3567035,3567042,3567050,3567061,3567062,3567074,3567082,3567086,3567089,3567090,3567094,3567103,3567108,3567113,3567117,3567130,3567134,3567137,3567139,3567142,3567168,3567169,3567186,3567192,3567196,3567209,3567210,3567233,3567234,3567239,3567240,3567244,3567264,3567285,3567288,3567296,3567302,3567308,3567312,3567330,3567336,3567344,3567347,3567361,3567374,3567382,3567384,3567394,3567401,3567412,3567415,3567425,3567427,3567434,3567444,3567451,3567465,3567474,3567487,3567491,3567496,3567497,3567507,3567519,3567523,3567533,3567554,3567594,3567611,3567621,3567630,3567633,3567640,3567647,3567664)

Execution plan IN

The problem is that EntityFramework generates the OR version.I thought there should'nt be any difference between an OR and IN statement regarding to performance?

Update:

EF 4 Query (EF cannot be updated):

var commonEventsLookup = cadEntities.CommonEventData.Where(c => commonEventIds.Contains(c.CommonEventId)).ToLookup(c => c.CommonEventId);
Chris
  • 234
  • 1
  • 11

1 Answers1

1

This is an issue with the SQL query optimiser in respect to the number of ORs. As you can see, the IN clause produces the "correct" plan whereby an index seek is performed on the CommonEventId column. The OR however does an index scan and then an horrifically expensive filter.

The root of the problem is the amount of OR clauses. If you strip away most of the ORs in the query you will find that SQL will perform an index seek as per the IN. However, from testing on a SQL 2014 instance it appears that once the number of ORs exceeds 64 (no doubt a significant number) then the optimiser decides to go down the scan/filter route, with devastating consequences for performance.

So short of bringing this up with the SQL Server team re. the optimiser or the EF team re. their SQL generation, you may need to run ExecuteSqlCommand when the array in your Contains exceeds a length of 64. Alternatively, you could use a LINQ Concat to force the SQL to perform UNIONs with chunks of 64 IDs.

strickt01
  • 3,959
  • 1
  • 17
  • 32