We were testing an upgrade from version 20.3.7 to 20.5.2 on one set of four replicas.  There were many stack traces like on columns that use the `AggregateFunction(avg, UInt32)` data type.  This exception happened only on that data type, but it appears to affect all of our tables that have it.

Is this possibly an issue with inconsistent parts?  We are using zstd compression and are seeing the "checksum does not match" errors as well.  Those errors continued even after all four replicas were upgraded, which was not expected.

Unfortunately this is a show stopping bug for us.

Possibly relevant updated server settings:
```
index_granularity_bytes                                   │ 10485760   
enable_mixed_granularity_parts                            │ 1      
```

Example table definition (from zookeeper):

```columns format version: 1
16 columns:
`datetime` DateTime(\'Etc/UTC\')
`svc_type` String
`svc` String
`host` String
`pssc` UInt16
`crc` String
`sssc` UInt16
`pqsn` String
`event_count` UInt64
`served_bytes` UInt64
`parent_bytes` UInt64
`ttms_avg` AggregateFunction(avg, UInt32)
`ttms_quants` AggregateFunction(quantilesTDigest(0.99, 0.95, 0.9), UInt32)
`chi_count` AggregateFunction(uniq, FixedString(16))
`manifest_count` UInt64
`fragment_count` UInt64

metadata format version: 1
date column: 
sampling expression: 
index granularity: 8192
mode: 2
sign column: 
primary key: datetime, svc_type, svc, host, pssc, crc, sssc, pqsn
data format version: 1
partition key: toDate(datetime)
granularity bytes: 10485760

```


Stack trace:

```
2020.07.09 16:34:59.968849 [ 397374 ] {} <Error> rogers.atsmid_svc_host_1m_v2: DB::StorageReplicatedMergeTree::queueTask()::<lambda(DB::StorageReplicatedMergeTree::LogEntry
Ptr&)>: Code: 33, e.displayText() = DB::Exception: Cannot read all data. Bytes read: 5. Bytes expected: 8.: (while reading column ttms_avg): (while reading from part /opt/d
ata/clickhouse/data/rogers/atsmid_svc_host_1m_v2/20200709_3390_3390_0/ from mark 0 with max_rows_to_read = 8192), Stack trace (when copying this message, always include the
 lines below):

0. Poco::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int) @ 0x10ed0da0 in /usr/bin/clickhouse
1. DB::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int) @ 0x95c923d in /usr/bin/clickhouse
2. DB::ReadBuffer::readStrict(char*, unsigned long) @ 0x960c90f in /usr/bin/clickhouse
3. DB::AggregateFunctionAvgBase<unsigned int, DB::AggregateFunctionAvgData<unsigned long, unsigned long>, DB::AggregateFunctionAvg<unsigned int, DB::AggregateFunctionAvgDat
a<unsigned long, unsigned long> > >::deserialize(char*, DB::ReadBuffer&, DB::Arena*) const @ 0x97705bd in /usr/bin/clickhouse
4. DB::DataTypeAggregateFunction::deserializeBinaryBulk(DB::IColumn&, DB::ReadBuffer&, unsigned long, double) const @ 0xd9bdaa5 in /usr/bin/clickhouse
5. DB::MergeTreeReaderWide::readData(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::IDataType const&, DB::IColumn&, unsig
ned long, bool, unsigned long, bool) @ 0xe51d774 in /usr/bin/clickhouse
6. DB::MergeTreeReaderWide::readRows(unsigned long, bool, unsigned long, std::__1::vector<COW<DB::IColumn>::immutable_ptr<DB::IColumn>, std::__1::allocator<COW<DB::IColumn>
::immutable_ptr<DB::IColumn> > >&) @ 0xe51dbcc in /usr/bin/clickhouse
7. DB::MergeTreeSequentialSource::generate() @ 0xe54519b in /usr/bin/clickhouse
8. DB::ISource::work() @ 0xe6dd3ab in /usr/bin/clickhouse
9. DB::SourceWithProgress::work() @ 0xe91f337 in /usr/bin/clickhouse
10. DB::TreeExecutorBlockInputStream::execute(bool, bool) @ 0xe71fb0e in /usr/bin/clickhouse
11. DB::TreeExecutorBlockInputStream::readImpl() @ 0xe71fe7f in /usr/bin/clickhouse
12. DB::IBlockInputStream::read() @ 0xd999b1d in /usr/bin/clickhouse
13. DB::MergeTreeDataMergerMutator::mergePartsToTemporaryPart(DB::FutureMergedMutatedPart const&, DB::MergeListEntry&, DB::TableStructureReadLockHolder&, long, std::__1::un
ique_ptr<DB::IReservation, std::__1::default_delete<DB::IReservation> > const&, bool, bool) @ 0xe42d37c in /usr/bin/clickhouse
14. DB::StorageReplicatedMergeTree::tryExecuteMerge(DB::ReplicatedMergeTreeLogEntry const&) @ 0xe28c04a in /usr/bin/clickhouse
15. DB::StorageReplicatedMergeTree::executeLogEntry(DB::ReplicatedMergeTreeLogEntry&) @ 0xe2bb57b in /usr/bin/clickhouse
16. ? @ 0xe2bb97d in /usr/bin/clickhouse
17. DB::ReplicatedMergeTreeQueue::processEntry(std::__1::function<std::__1::shared_ptr<zkutil::ZooKeeper> ()>, std::__1::shared_ptr<DB::ReplicatedMergeTreeLogEntry>&, std::
__1::function<bool (std::__1::shared_ptr<DB::ReplicatedMergeTreeLogEntry>&)>) @ 0xe5a99b2 in /usr/bin/clickhouse
18. DB::StorageReplicatedMergeTree::queueTask() @ 0xe26e52e in /usr/bin/clickhouse
19. DB::BackgroundProcessingPool::workLoopFunc() @ 0xe39f763 in /usr/bin/clickhouse
20. ? @ 0xe3a0092 in /usr/bin/clickhouse
21. ThreadPoolImpl<std::__1::thread>::worker(std::__1::__list_iterator<std::__1::thread, void*>) @ 0x95f6e97 in /usr/bin/clickhouse
22. ? @ 0x95f5383 in /usr/bin/clickhouse
23. start_thread @ 0x7dd5 in /usr/lib64/libpthread-2.17.so
24. clone @ 0xfdead in /usr/lib64/libc-2.17.so
```


#pragma once
#include <IO/ReadHelpers.h>
#include <IO/WriteHelpers.h>
#include <Columns/ColumnsNumber.h>
#include <DataTypes/DataTypesDecimal.h>
#include <DataTypes/DataTypesNumber.h>
#include <AggregateFunctions/IAggregateFunction.h>
namespace DB
{
namespace ErrorCodes
{
}
template <typename T, typename Denominator>
struct AggregateFunctionAvgData
{
    using NumeratorType = T;
    T numerator = 0;
    Denominator denominator = 0;
    template <typename ResultT>
    ResultT NO_SANITIZE_UNDEFINED result() const