Switch to CRC-32C in WAL and other places.
Heikki Linnakangas <heikki.linnakangas@iki.fi>
Switch to CRC-32C in WAL and other places. The old algorithm was found to not be the usual CRC-32 algorithm, used by Ethernet et al. We were using a non-reflected lookup table with code meant for a reflected lookup table. That's a strange combination that AFAICS does not correspond to any bit-wise CRC calculation, which makes it difficult to reason about its properties. Although it has worked well in practice, seems safer to use a well-known algorithm. Since we're changing the algorithm anyway, we might as well choose a different polynomial. The Castagnoli polynomial has better error-correcting properties than the traditional CRC-32 polynomial, even if we had implemented it correctly. Another reason for picking that is that some new CPUs have hardware support for calculating CRC-32C, but not CRC-32, let alone our strange variant of it. This patch doesn't add any support for such hardware, but a future patch could now do that. The old algorithm is kept around for tsquery and pg_trgm, which use the values in indexes that need to remain compatible so that pg_upgrade works. While we're at it, share the old lookup table for CRC-32 calculation between hstore, ltree and core. They all use the same table, so might as well.
Files
| Path | Change | +/− |
|---|---|---|
| contrib/hstore/crc32.c | deleted | +0 −106 |
| contrib/hstore/crc32.h | deleted | +0 −13 |
| contrib/hstore/hstore_gist.c | modified | +15 −1 |
| contrib/hstore/Makefile | modified | +1 −1 |
| contrib/ltree/crc32.c | modified | +21 −93 |
| contrib/pg_trgm/trgm_op.c | modified | +3 −3 |
| src/backend/access/transam/twophase.c | modified | +12 −12 |
| src/backend/access/transam/xlog.c | modified | +25 −25 |
| src/backend/access/transam/xlogreader.c | modified | +6 −6 |
| src/backend/replication/logical/snapbuild.c | modified | +14 −14 |
| src/backend/replication/slot.c | modified | +10 −10 |
| src/backend/utils/adt/tsgistidx.c | modified | +3 −3 |
| src/backend/utils/adt/tsquery.c | modified | +6 −6 |
| src/backend/utils/cache/relmapper.c | modified | +8 −8 |
| src/bin/pg_controldata/pg_controldata.c | modified | +6 −6 |
| src/bin/pg_resetxlog/pg_resetxlog.c | modified | +15 −15 |
| src/include/access/xlog_internal.h | modified | +1 −1 |
| src/include/catalog/catversion.h | modified | +1 −1 |
| src/include/utils/pg_crc.h | modified | +79 −14 |
| src/include/utils/pg_crc_tables.h | modified | +74 −3 |