For the following error analysis, you specify the mode in which BCHECK further processes the check records. Two checking modes are possible: a summing check and a sort check.
For both modes, BCHECK makes use of the fact that in the various page types (DBTT pages, data pages etc.), information on the check objects is stored in redundant form. For example, from a DBTT page, the page address of the record can be determined for each DB key. If the database is consistent, both DB key and page address are also in the data page in which the record is stored. This means that from the various pages two identical check records are generated for each check object, and, depending on their origin, these will have either a positive or a negative sign.
BCHECK has two procedures for detecting consistency errors in the database:
The counter procedure
BCHECK sets up three counters:
It uses one to count whether precisely the same number of positive and negative check records exist, which is the case if the database is consistent.
In the other two, it adds the check records compressed to 6 bytes and the square of these values, respectively.
This technique, which is based on the theory of error detecting codes, ensures with a high degree of accuracy that an existing error will be detected because the corresponding sums do not match.
The counter procedure can detect and roughly locate consistency errors in the database but not pinpoint them. This checking method is also called summing check.
Sorting procedure
BCHECK collects all the check records in a file and sorts them so that associated sets of check records must be located next to one another if the database is correct. It then compares each set in turn; if sets do not match, there is a consistency error at that point in the database.
This means that BCHECK can use this checking method not only to detect consistency errors in the database but also to pinpoint them so that the consistency errors can be rectified. However, because the check records have to be sorted, this procedure is far more time-consuming than the counter procedure.
Summing check
Depending on the BCHECK statements, BCHECK uses the counter procedure, the sorting procedure or, as part of a summing check, a combination of the two. Since the sorting procedure in the summing check is only used for a restricted set of check records, the summing check takes very little time and is ideally suited for use during daily data saving activities. If global summation consistency errors are detected, a sort check would be needed to pinpoint the error location.
Sort check
Here BCHECK uses only the sorting procedure. If run unmodified, this check is considerably more time-consuming than the summing check.
You can greatly reduce this time requirement by performing an incremental check. This procedure is described below and can also be used for summing checks.