.ad 8
.bm 8
.fm 4
.bt $Copyright (c) 2000-2005 SAP AG$$Page %$
.tm 12
.hm 6
.hs 3
.tt 1 $SQL$Project Distributed Database System$VBD53$
.tt 2 $$$
.tt 3 $JuergenP$indexing$1999-07-14$
***********************************************************
.nf
 
 .nf
 
    ========== licence begin  GPL
    Copyright (c) 2000-2005 SAP AG
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    ========== licence end
.fo
 
 
.fo
.nf
.sp
Module  : indexing
=========
.sp
Purpose : determination of separators
.CM *-END-* purpose -------------------------------------
.sp
.cp 3
Define  :
 
        PROCEDURE
              bd53NewLeafIndex (VAR Nptr : tbd_nodeptr;
                    VAR Nnptr        : tbd_nodeptr;
                    VAR NewSeparator : tgg00_Lkey;
                    t                : tgg00_TransContextPtr);
 
        PROCEDURE
              bd53NextLeafIndex (VAR Nptr : tbd_nodeptr;
                    RecIndex         : tsp00_Int4;
                    VAR Key          : tgg00_Lkey;
                    VAR NewSeparator : tgg00_Lkey;
                    t                : tgg00_TransContextPtr);
 
.CM *-END-* define --------------------------------------
.sp;.cp 3
Use     :
 
        FROM
              error_text_handling : VBD06;
 
        PROCEDURE
              b06dump_bad_page (pid : tsp00_TaskId;
                    page_type_flag : char;
                    file_ext       : tsp00_C4;
                    bad_pno        : tsp00_Int4;
                    buf_ptr        : tbd_nodeptr;
                    curr_buf_cnt   : integer);
 
      ------------------------------ 
 
        FROM
              entryhandling : VBD35;
 
        PROCEDURE
              b35get_entrykey (VAR nptr : tbd_nodeptr;
                    index   : integer;
                    VAR sep : tgg00_Lkey;
                    t       : tgg00_TransContextPtr);
 
      ------------------------------ 
 
        FROM
              Configuration_Parameter : VGG01;
 
        PROCEDURE
              g01key_assign (VAR source_key : tgg00_Lkey;
                    VAR target_key : tgg00_Lkey;
                    VAR e          : tgg00_BasisError);
 
        PROCEDURE
              g01opmsg (msg_prio : tsp3_priority;
                    msg_type  : tsp3_msg_type;
                    msg_no    : tsp00_Int4;
                    msg_label : tsp00_C8;
                    msg_text  : tsp00_C24;
                    msg_value : tsp00_Int4);
&       ifdef TRACE
 
      ------------------------------ 
 
        FROM
              Test_Procedures : VTA01;
 
        PROCEDURE
              t01buf1 (debug  : tgg00_Debug;
                    VAR buf  : tsp00_Key;
                    startpos : integer;
                    endpos   : integer);
 
        PROCEDURE
              t01lkey (layer : tgg00_Debug;
                    VAR k : tgg00_Lkey);
&       endif
 
.CM *-END-* use -----------------------------------------
.sp;.cp 3
Synonym :
 
        PROCEDURE
              b06dump_bad_page;
 
              tbd_univ_ptr tbd_nodeptr
&             ifdef TRACE
 
        PROCEDURE
              t01buf1;
 
              tsp00_Buf tsp00_Key
&             endif
 
.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  : JuergenP
.sp
.cp 3
Created : 1980-02-28
.sp
.cp 3
.sp
.cp 3
Release :      Date : 1999-07-14
.sp
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Specification:
 
This module combines the routines used to produce the separators
for the branches of the B* index when the current B* tree is
reorganized.
.sp
For each node n of a nonempty B* tree (not including the root or purely
appended leaves) there is a branch v in the parent node of n; n is
'indexed' by the separator sep of the branch v, i.e. sep defines the
lower limit of the left closed right open key interval for which the
subtree whose root is formed by n is responsible.
.br;(The lower limit of a left closed right open interval belongs to the
interval whereas the higher limit does not.)
.br;The routines that issue the orders for modifying the B* index are
responsible for the correct indexing of the nodes!
.sp 2
   b53newleafindex (nptr,nnptr,sep)
.sp
This routine requires that 'nptr' and 'nnptr' address leaves in
which at least one record entry begins and that the key s1 of the
last entry that begins in n be lower than the key s2 of the first
entry that begins in nn.
.br
It supplies in sep a separator for which s1 < sep <= s2.
.sp 2
   b53nextleafindex (nptr,index,nextsep,sep)
.sp
This routine requires that the last record entry in the leaf addressed
by 'nptr' begins at a position referenced by 'index'
and that the key s of this record entry
be lower than 'nextsep'.
.br
It supplies in 'sep' a separator for which s < sep <= nextsep.
.sp 2
   b53newinvindex (nptr,nnptr,sep)
.sp
Same as b53newleafindex, but the leaves contain inversion lists
instead of record keys.
.sp 2
   b53next_invleaf_index (nptr,index,sep)
.sp
This routine requires that the last record entry in the leaf addressed
by 'nptr' begins at a position referenced by 'index'
and that the key s of this record entry
be lower than 'sep'(= nextsep).
.br
It supplies in 'sep' a separator for which s < sep <= nextsep.
.CM *-END-* specification -------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Description:
 
The indexing of leaves occurs as follows:
.br
From the key of the first entry beginning in a leaf, the shortest prefix
that is higher than the key of the entry immediately preceeding it is
identified and used as the separator for the leaf.
.br;(As trailing zero bytes are not allowed the shortest prefix ending
with a zero byte is extended until the first non zero byte inclusively
which must exist.)
.br;The immediately preceeding entry is generally the last entry that
begins in the left neighbor leaf (if this leaf is not a purely appended
leaf). For the leaf that is responsible for the lowest key, in this case
a key with a length of 0 is used as a separator.
.sp
When the branch nodes are indexed, the separator of the first
branch is used as the separator.
.CM *-END-* description ---------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.nf
.oc _/1
Structure:
 
.CM *-END-* structure -----------------------------------
.sp 2
**********************************************************
.sp
.cp 10
.nf
.oc _/1
.CM -lll-
Code    :
 
 
(*------------------------------*) 
 
PROCEDURE
      bd53NewLeafIndex (VAR Nptr : tbd_nodeptr;
            VAR Nnptr        : tbd_nodeptr;
            VAR NewSeparator : tgg00_Lkey;
            t                : tgg00_TransContextPtr);
 
VAR
      PredSeparator : tgg00_Lkey;
 
BEGIN
b35get_entrykey (Nnptr, FIRST_REC_INDEX_BD00, NewSeparator, t);
b35get_entrykey (Nptr, Nptr^.nd_record_cnt - 1 , PredSeparator, t);
WITH t^ DO
    BEGIN
    IF  trError_gg00 <> e_data_page_corrupted
    THEN
        BEGIN
&       ifdef TRACE
        t01lkey (bd_inv, PredSeparator);
        t01lkey (bd_inv, NewSeparator);
&       endif
        bd53_shortestprefix (PredSeparator, NewSeparator, trError_gg00);
        IF  trError_gg00 = e_invalid_leaves_structure
        THEN
            BEGIN
            b06dump_bad_page (trTaskId_gg00, 'd', FILE_EXT_COR_BD00,
                  Nptr^.nd_id, Nptr, 1);
            b06dump_bad_page (trTaskId_gg00, 'd', FILE_EXT_COR_BD00,
                  Nnptr^.nd_id, Nnptr, 1); (* PTS 1102693 UH 19990517 *)
            END
        (*ENDIF*) 
        END
    (*ENDIF*) 
    END
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      bd53NextLeafIndex (VAR Nptr : tbd_nodeptr;
            RecIndex         : tsp00_Int4;
            VAR Key          : tgg00_Lkey;
            VAR NewSeparator : tgg00_Lkey;
            t                : tgg00_TransContextPtr);
 
VAR
      PredSeparator : tgg00_Lkey;
 
BEGIN
WITH t^ DO
    BEGIN
    g01key_assign (Key, NewSeparator, trError_gg00);
    IF  trError_gg00 <> e_move_error
    THEN
        b35get_entrykey (Nptr, RecIndex, PredSeparator, t);
    (*ENDIF*) 
    IF  trError_gg00 <> e_data_page_corrupted
    THEN
        BEGIN
&       ifdef TRACE
        t01lkey (bd_inv, PredSeparator);
        t01lkey (bd_inv, NewSeparator);
&       endif
        bd53_shortestprefix (PredSeparator, NewSeparator, trError_gg00);
        IF  trError_gg00 = e_invalid_leaves_structure
        THEN
            b06dump_bad_page (trTaskId_gg00, 'd', FILE_EXT_COR_BD00,
                  Nptr^.nd_id, Nptr, 1)
        (*ENDIF*) 
        END
    (*ENDIF*) 
    END
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      bd53_shortestprefix (VAR predsep : tgg00_Lkey;
            VAR sep : tgg00_Lkey;
            VAR e   : tgg00_BasisError);
 
VAR
      i       : integer;
      min_len : integer;
 
BEGIN
(*predsep < sep*)
IF  predsep.keyLen_gg00 <= sep.keyLen_gg00
THEN
    min_len := predsep.keyLen_gg00
ELSE
    min_len := sep.keyLen_gg00;
(*ENDIF*) 
i := 1;
WHILE (i <= min_len) AND (predsep.keyVal_gg00 [i] = sep.keyVal_gg00 [i]) DO
    i := succ(i); (* PTS 1116852 TS 2002-07-24 *)
(*ENDWHILE*) 
IF  i <= min_len
THEN
    BEGIN
    IF  predsep.keyVal_gg00 [i] > sep.keyVal_gg00 [i]
    THEN
        BEGIN
        g01opmsg (sp3p_console, sp3m_error,
              csp3_b53x1_invalid_separator, csp3_n_btree,
              'BD53: predsep.k > sep.k ', 0);
        e := e_invalid_leaves_structure
        END
    (*ENDIF*) 
    END
ELSE
    IF  min_len = sep.keyLen_gg00
    THEN
        BEGIN
        g01opmsg (sp3p_console, sp3m_error,
              csp3_b53x2_invalid_separator, csp3_n_btree,
              'BD53: min_len = sep.len ', 0);
        e := e_invalid_leaves_structure
        END;
    (* include the next nonzero byte: *)
    (*ENDIF*) 
(*ENDIF*) 
IF  (e <> e_invalid_leaves_structure) AND (i < sizeof (sep.keyVal_gg00))
THEN
    BEGIN
    WHILE (i < sep.keyLen_gg00) AND (sep.keyVal_gg00 [i] = chr(0)) DO
        i := succ(i); (* PTS 1116852 TS 2002-07-24 *)
    (*ENDWHILE*) 
    sep.keyLen_gg00 := i
    END
(*ENDIF*) 
END;
 
.CM *-END-* code ----------------------------------------
.SP 2 
***********************************************************
.PA 
