all groups > sql server replication > may 2007 >
You're in the

sql server replication

group:

Snapshot Agent Updates statistics on all PK indexes even when there is NOTHING to do!!


Snapshot Agent Updates statistics on all PK indexes even when there is NOTHING to do!! isyourfriend NO[at]SPAM gmail.com
5/1/2007 9:29:50 AM
sql server replication:
On SQL Server 2005 SP2 we got this "new feature" which I am probaly
aware of why you do need the update statistics but what I can't tell
is WHY you run the update statistics if there is NOTHING to do? Thanks
M$.

Does any one knows how or if it is possible, to turn that "feature"
OFF?

-Noel
Sr. DBA
Re: Snapshot Agent Updates statistics on all PK indexes even when there is NOTHING to do!! Raymond Mak [MSFT]
5/1/2007 10:31:26 AM
Noel, the snapshot agent will only attempt to update the statistics on the
clustered index (primary key) if the statistics on it has not been populated
(as indicated by a null date returned from DBCC SHOW_STATISTICS). This can
happen if 1) the table is empty or 2) statistics has never been populated
since the creation of the table. For case 1), updating statistics will be a
trivial operation, and for case 2), updating statistics generally allows the
query optimizer to choose better query plans as well as enables the snapshot
agent to partition large tables more evenly for parallel processing. You can
disable this behavior by specifying the unofficial
"-EnableArticleBcpPartitioning 0" option on the snapshot agent command line.

Hope that helps,

-Raymond
[quoted text, click to view]

Re: Snapshot Agent Updates statistics on all PK indexes even when there is NOTHING to do!! isyourfriend NO[at]SPAM gmail.com
5/1/2007 11:07:49 AM
On May 1, 1:31 pm, "Raymond Mak [MSFT]" <r...@online.microsoft.com>
[quoted text, click to view]

Raymond, Thanks you very much for your prompt reply.

The reason that I am complaining is that it can potentially invalidate
my queries plan cache if it is run on a schedule, causing unnecessary
recompilations. I do understand that it helps with the parallel
processing; I went through that (with you) before, thanks again. It is
my opinion though that the check to determine that there is nothing to
do should be done before updating statistics no matter how trivial it
may be. --- And yes it *does* helps :-)

Regards,

-Noel
Sr. DBA
Re: Snapshot Agent Updates statistics on all PK indexes even when there is NOTHING to do!! Raymond Mak [MSFT]
5/1/2007 11:31:08 AM
Just out of curiousity, do you routinely have empty tables in your publisher
database that are heavily queried by your application? That is the case
where I can see how the snapshot agent update stats behavior will affect you
(of course I may be wrong).

-Raymond

[quoted text, click to view]

Re: Snapshot Agent Updates statistics on all PK indexes even when there is NOTHING to do!! isyourfriend NO[at]SPAM gmail.com
5/1/2007 12:14:52 PM
On May 1, 2:31 pm, "Raymond Mak [MSFT]" <r...@online.microsoft.com>
[quoted text, click to view]

Raymond,

There are tables that get "cleared" (moved to history) at the end of a
daily session (for performance and other reasons we don't want to
accumulate history there) and there are others configuration tables
that are populated or cleared by agents adaptively. This process
repeats at different timezones and 24x7 with very narrow windows in
between *used* by archivers, reports,etc.

I am worried that my cache gets trashed in the middle of a heavy
activity if I leave the agent running. Are you saying that the minute
those tables get populated I won't get the "update statistics"
behaviour ?

-Noel

Re: Snapshot Agent Updates statistics on all PK indexes even when there is NOTHING to do!! isyourfriend NO[at]SPAM gmail.com
5/1/2007 12:16:38 PM
On May 1, 2:31 pm, "Raymond Mak [MSFT]" <r...@online.microsoft.com>
[quoted text, click to view]


Raymond,

There are tables that get "cleared" (moved to history) at the end of a
daily session (for performance and other reasons we don't want to
accumulate history there) and there are others configuration tables
that are populated or cleared by agents adaptively. This process
repeats at different timezones and 24x7 with very narrow windows in
between *used* by archivers, reports,etc.

I am worried that my cache gets trashed in the middle of a heavy
activity if I leave the agent running. Are you saying that the minute
those tables get populated I won't get the "update statistics"
behaviour ?

-Noel


Re: Snapshot Agent Updates statistics on all PK indexes even when there is NOTHING to do!! Raymond Mak [MSFT]
5/1/2007 12:41:12 PM
Like I mentioned before, the snapshot agent will only run update stats if it
couldn't find any *statistics* on the leading clustered index column but I
don't really know if the storage engine will actively *remove* statistics
that already exists if you delete all rows in a table (I will try that). You
can definitely try to minimize the impact that update statistics from the
snapshot agent may have by scheduling it to run no more often then
necessary. That said, I can't help but notice that with the way tables are
emptied and repopulated everyday, the statistics will basically get
out-dated on a daily basis which will in turn mislead the query optimizer.
Wouldn't plan guides be a better solution to ensure more stable\robust
(hence no-recompilation) plans for your critical queries?

-Raymond

[quoted text, click to view]

Re: Snapshot Agent Updates statistics on all PK indexes even when there is NOTHING to do!! Raymond Mak [MSFT]
5/1/2007 12:57:42 PM
Just a brief update: It doesn't look like delete all rows or truncate table
will "empty" populated statistics.

-Raymond

[quoted text, click to view]

Re: Snapshot Agent Updates statistics on all PK indexes even when there is NOTHING to do!! isyourfriend NO[at]SPAM gmail.com
5/1/2007 1:03:24 PM
On May 1, 3:41 pm, "Raymond Mak [MSFT]" <r...@online.microsoft.com>
[quoted text, click to view]

Thanks, Raymond.

I believe that plan guides may help us in the long run. We are
migrating still many servers and I was doing my due dilligence and
testing to minimize the number of "surprises"; that's why I asked
about this. Now that we are at it how does the "database snapshot" for
initialization affects (in terms of performace ) the "main" database ?
Re: Snapshot Agent Updates statistics on all PK indexes even when there is NOTHING to do!! Raymond Mak [MSFT]
5/1/2007 3:24:15 PM
A database snapshot (not to be confused with replication snapshot) generally
increases the number of I/Os per update of the originating database as well
as the storage requirement for the duration of its existence up to what is
required for an extra copy of the originating database when the database
snapshot is created. It is basically a copy-on-write mechanism where the
"original" data page is saved off "to the snapshot" when it is first
modified after the snapshot is created. As such, you would want to make sure
that:

1) database snapshots do not hang around for longer than necessary
2) database snapshots be ideally created at times when updates to the
originating database are limited to a relatively small subset of data pages:
frequent updates to the same subset of rows are fine, as are inserts that
cluster around the same range of data pages (new pages are not "saved off"
to the database snapshot)
3) the number of outstanding database snapshots be kept at a minimum as the
processing\resource overhead for maintaining database snapshots scales
roughly linearly with their number

The same considerations apply if you are using sync_method = 'database
snapshot' for generating replication snapshots as the replication snapshot
agent will create a database snapshot under the cover for generating a
consistent point-in-time set of replication snapshot data (or files). Notice
that the throughput for reading from a database snapshot (think the snapshot
agent bulk-copy out data) may be lower compared with reading from the
originating database because of the extra processing required for traversing
between saved data pages in the database snapshot and unmodified pages in
the originating database . However, reading from a database snapshot imposes
almost no locking contention (except perhaps short-duration internal
latches) on the originating database.

-Raymond

[quoted text, click to view]
AddThis Social Bookmark Button