SQL Server: extremely slow results when increasing top by 1 -
i've query joins several views , 1 table using inner joins. no sub-queries involved, joined fields indexed, , joins on int fields. using "top 342" in select clause results in query executes in ~2 seconds. if use same query , "top 343", query doesn't finish executing within 7 minutes. tried several other values below 342 worked expected.
removing joined table query causes query complete within few seconds no matter value used top.
i tried updating statistics on table using full-scan, didn't change anything.
within same context of sql execution use:
dbcc freeproccache go checkpoint; go dbcc dropcleanbuffers; go what types of things might cause slow execution?
changing value of top alter row goal.
this can have significant effect on rest of plan. might find top 342 happens produce plan non blocking operators such nested loops favoured top 343 sql server's costing model reckons cheaper use blocking operator such hash join consumes whole sub tree first example.
you experiment constructs such
select top 363 * your_view option (fast 362) or
declare @top int = 363 select top (@top) * your_view option (optimize (@top = 362)) but these last resort me if unable satisfactory plan other way.
Comments
Post a Comment