mirror of
https://github.com/postgres/postgres.git
synced 2025-10-16 17:07:43 +03:00
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.
This commit is contained in:
@@ -280,9 +280,9 @@ pushValue(TSQueryParserState state, char *strval, int lenval, int16 weight, bool
|
||||
errmsg("word is too long in tsquery: \"%s\"",
|
||||
state->buffer)));
|
||||
|
||||
INIT_CRC32(valcrc);
|
||||
COMP_CRC32(valcrc, strval, lenval);
|
||||
FIN_CRC32(valcrc);
|
||||
INIT_LEGACY_CRC32(valcrc);
|
||||
COMP_LEGACY_CRC32(valcrc, strval, lenval);
|
||||
FIN_LEGACY_CRC32(valcrc);
|
||||
pushValue_internal(state, valcrc, state->curop - state->op, lenval, weight, prefix);
|
||||
|
||||
/* append the value string to state.op, enlarging buffer if needed first */
|
||||
@@ -883,9 +883,9 @@ tsqueryrecv(PG_FUNCTION_ARGS)
|
||||
|
||||
/* Looks valid. */
|
||||
|
||||
INIT_CRC32(valcrc);
|
||||
COMP_CRC32(valcrc, val, val_len);
|
||||
FIN_CRC32(valcrc);
|
||||
INIT_LEGACY_CRC32(valcrc);
|
||||
COMP_LEGACY_CRC32(valcrc, val, val_len);
|
||||
FIN_LEGACY_CRC32(valcrc);
|
||||
|
||||
item->qoperand.weight = weight;
|
||||
item->qoperand.prefix = (prefix) ? true : false;
|
||||
|
Reference in New Issue
Block a user