We have a somewhat complicated SQL update request that runs several times a month. In most cases this works very fast, but in some databases it takes a very long time. After starting UPDATE STATISTICS in the corresponding tables, the update immediately quickly starts quickly. Finally, we created a night task that calls UPDATE STATISTICS on all tables in the database. But this did not help solve the problem. We still have to run the “STATISTICS UPDATE” manually each time. Why are statistics so outdated so quickly?
Here's what the request looks like:
UPDATE DataTableA SET DataTableA.IndexedColumn1 = 123456789, DataTableA.Flag1 = 1 FROM DataTableA WITH (INDEX(IX_DataTableA)) INNER JOIN GroupingTableA ON GroupingTableA.ForeignKey1 = GroupingTableA.PrimaryKey INNER JOIN LookupTableA ON DataTableA.ForeignKey3 = LookupTableA.PrimaryKey LEFT OUTER JOIN GroupingTableB ON DataTableA.IndexedColumn2 = GroupingTableB.IndexedColumn2 WHERE GroupingTableB.IndexedColumn1 = 123456789 AND DataTableA.IndexedColumn1 IS NULL AND DataTableA.IndexedColumn2 IN ( ... 300 entries here ... ) AND DataTableA.Deleted = 0 AND GroupingTableA.Date <= GroupingTableB.EndDate AND GroupingTableA.Date >= DATEADD(month, -1, GroupingTableB.StartDate) AND LookupTableA.Column2 = 1 AND DataTableA.Status1 IN (1, 3) AND DataTableA.Status2 NOT IN (1, 3, 9)
DataTableA contains millions of rows.
GroupingTableA and GroupingTableB contain tens of thousands of rows.
LookupTableA contains dozens of rows.
Index IX_DataTableA is the index on (IndexedColumn1 ASC, IndexedColumn2 ASC)
sql-server statistics sql-server-2000
Bryce wagner
source share