Debian Codegraph @

contrib/pageinspect/sql/checksum.sql

raw
1 --
2 -- Verify correct calculation of checksums
3 --
4 -- Postgres' checksum algorithm produces different answers on little-endian
5 -- and big-endian machines. The results of this test also vary depending
6 -- on the configured block size. This test has several different expected
7 -- results files to handle the following possibilities:
8 --
9 -- BLCKSZ end file
10 -- 8K LE checksum.out
11 -- 8K BE checksum_1.out
12 --
13 -- In future we might provide additional expected-results files for other
14 -- block sizes, but there seems little point as long as so many other
15 -- test scripts also show false failures for non-default block sizes.
16 --
17
18 -- This is to label the results files with blocksize:
19 SHOW block_size;
20
21 SHOW block_size \gset
22
23 -- Apply page_checksum() to some different data patterns and block numbers
24 SELECT blkno,
25 page_checksum(decode(repeat('01', :block_size), 'hex'), blkno) AS checksum_01,
26 page_checksum(decode(repeat('04', :block_size), 'hex'), blkno) AS checksum_04,
27 page_checksum(decode(repeat('ff', :block_size), 'hex'), blkno) AS checksum_ff,
28 page_checksum(decode(repeat('abcd', :block_size / 2), 'hex'), blkno) AS checksum_abcd,
29 page_checksum(decode(repeat('e6d6', :block_size / 2), 'hex'), blkno) AS checksum_e6d6,
30 page_checksum(decode(repeat('4a5e', :block_size / 2), 'hex'), blkno) AS checksum_4a5e
31 FROM generate_series(0, 100, 50) AS a (blkno);