r/SQLServer • ‪ ‪Microsoft Employee ‪ • Oct 23 '26

Community Share Friday Feedback: Offload statistics updates

The Fall Friday Feedbacks continue and this week I want to ask about updating statistics. Poll is below, but as always, if you have interesting challenges or scenarios you want to share, please comment below. I've seen a lot, but I know I haven't seen everything...

2 Upvotes

12 comments sorted by

3

u/xerxes716 Oct 23 '26

What do you mean by "offload" when it comes to statistics updates?

3

u/erinstellato ‪ ‪Microsoft Employee ‪ Oct 23 '26

The statistic update would run on the replica, rather than the primary, and then we would persist the updated stats info back on the primary.

1

u/shaadowbrker Oct 23 '26

Sorry for the question how would it persist back to primary node is that built in to the engine or do we have to schedule that, and thanks in advance.

2

u/erinstellato ‪ ‪Microsoft Employee ‪ Oct 27 '26

u/shaadowbrker It would be persisted back through the same channels we use for persisting other information (e.g. Query Store enabled for read-only replicas) - it would be built in, nothing required from the user/customer.

1

u/Lufdo Oct 23 '26

Would it be applicable to UPDATE STATISTICS command? Is that what you mean with "scheduled updates"? In one of my last projects we had a few ETL processes and as last step we were running UPDATE STATISTICS command to ensure queries on the affected tables would work smoothly.

2

u/erinstellato ‪ ‪Microsoft Employee ‪ Oct 27 '26

u/Lufdo Yes, it would be applicable to UPDATE STATISTICS (which can be run ad hoc in something like SSMS, or as part of a scheduled update (e.g. Agent job))

2

u/Lufdo Oct 27 '26

Grea, thanks for the answer u/erinstellato. It would be a great feature in general. In our system at some point we needed to update stats every 4 hs for some tables withchigh sampme rates and it was pushing hard on IO. We finally had to remove it and hint the queries that used to fail. Offloading stats calculation should help importantly on heavy instances.

1

u/Lost_Term_8080 Oct 27 '26

Still don't quite understand the question - being able to update stats on the primary by scanning the secondary would be absolutely massive as long as it doesn't require the secondary to be licensed. Many more of my SQL servers would be full scan all the time and the biggest ones could be much larger samples.

When I work with databases that are small or I have a maintenance window that I can hammer them, I do fullscan daily as a starting point. Typically, where stats are the most challenging to maintain are in larger databases that don't have a maintenance window to do hundreds of gb or terabytes of reads ever, and change so fast they can't rely on waiting for a maintenance window anyways.

I try very hard to not let autostats ever need to run so update them with maintenance solution configured for percentage change threshold and usually end up needing to break it out by 30 minutes, hour, 4 hour, Daily, biweekly and weekly

Would a larger histogram come with it too pretty please?

1

u/erinstellato ‪ ‪Microsoft Employee ‪ Oct 27 '26

u/Lost_Term_8080 In terms of licensing on the secondary, that's TBD. Obviously, I'd like to make it possible to not be an additional cost, but I don't get to make those decisions arbitrarily! And yes, the idea is to help the scenarios where customers have giant tables (hundreds of millions or billions of rows). In terms of a larger histogram, did you have a specific request for number of steps? (and if so, what number and why)

2

u/Lost_Term_8080 Oct 27 '26

Theoretical, but under the generalization that SQL Server needs estimates to be within about 5x accuracy on very large tables and about 8 or 10x on say, sub 20m rows (obviously there is a whole bunch of "it depends" in that), The cases where I deal with the 201 buckets problem that get fixed with a filtered statistic/filtered index (that is not being for selectivity reasons) keep falling within the range of indicating that a 2x to 4x increase in the number of steps would bring them to within 5-10x accuracy. I can't test that, when I've added filtered stats or indexes it usually ends up making them just about perfect so it's an extrapolation that getting them to within 5-10x would fix it. If it ends up 4x or more, I think it would make most sense to make the histograms 8x larger so the engine can stream read them

1

u/AngryPets Oct 24 '26

What would the licensing impacts of this be?
i.e., you say offload, and I assume that non-DR/non-read-only-secondary(ies) licenses would be required for this.
more specifically, this would OBVIOUSLY be done as a scale-out operation - to offload resource usage on to a secondary.

For orgs already paying the licensing costs for offloads, this feels like a natural fit - i.e., handing over enough pesos to account for scale-out almost FEELS like this is something that could/should be covered.

More importantly, the LICENSING implications of this feature would really need to be made VERY clear (i.e., covered/allowed on 'failover only' licenses? or requires full-blown scale-out licensing?)

1

u/erinstellato ‪ ‪Microsoft Employee ‪ Oct 27 '26

u/AngryPets In terms of licensing on the secondary, that's TBD. I need to understand interest. Yes, the value here would be offloading resource use. If you have a secondary that you use for other purposes and this could take on that load, great. If you have a secondary that is just for DR, and you're not actively using, that's something I have to figure out. Heard on making the licensing VERY CLEAR. :)