Logo Search packages:      
Sourcecode: maxdb-7.5.00 version File versions  Download package

void cbd400_InvTree::bd400AppendPrimKey ( tsp00_KeyPtr  pSecKey,
tsp00_Int4  SecKeyLen,
tsp00_KeyPtr  pPrimKey,
tsp00_Int4  PrimKeyLen,
bool  bNextSecKey,
bool  bInvListRefNeeded,
tsp00_Int4 &  RecIndex 
)

function: bd400AppendPrimKey arguments: SecKey [in] Specifies the InvList to append the PrimKey. PrimKey [in] The PrimKey to be appended. bNextSecKey [in] The incoming SecKey is greater than the prevoius SecKeys and therefore a new InvList must be created. bInvListRefNeeded [in] Indicates that more PrimKeys will be inserted as an InvListArray can hold. Therefore the new InvList is created as an InvListRef. Note that an InvListArray Overflow is possible furthermore. RecIndex [in/out] If given, the SecKey is not searched.

description: PrimKey is appended to the InvList specified by SecKey.

If RecIndex is NIL_RECINDEX_BD00, the InvList ist searched in the InvTree, If InvList is not found, it is created. RecIndex specifies the current InvList. The internal Node points to the last LeafNode.

Definition at line 1852 of file vbd400.cpp.

References cbd300_InvCurrentBasis::bd300RootRequestKind(), bd400_SetToNewSubRoot(), cbd450_InvListRefSubTree::bd450IncrNumPrimKeys(), cbd450_InvListArray::bd450InsertPrimKey(), cbd450_InvListRefSubTree::bd450NumLeaves(), cbd450_InvListRefSubTree::bd450SetNumLeaves(), cbd450_InvListRefSubTree::bd450SetSubRoot(), cbd450_InvListArray::bd450Size(), cbd450_InvListArray::bd450Update(), cbd500_Tree::bd500FindNode(), cbd500_Tree::bd500GetTheCurrent(), cbd500_Tree::bd500LeafCount(), cbd500_Tree::bd520LeafOverflow(), cbd500_Tree::bd530AppendRecordSpace(), cbd600_Node::bd600GetId(), cbd600_Node::bd600IsAccessable(), cbd600_Node::bd600IsLeaf(), cbd600_Node::bd600MaxRecIndex(), cbd600_Node::bd600RecPtr(), cbd600_Node::bd600SearchRecord(), cbd600_Node::bd600SpaceIsAvailable(), cbd600_Node::bd600UpdRecordSpace(), cbd600_Node::m_Current, and cbd600_Node::m_pNode.

{
    /* PTS 1104438 UH 03-12-1999 rewritten */

    ROUTINE_DBG_MEO00 ("bd400AppendPrimKey");

    if ( g01glob.treecheck )
    {
        // PTS 1109967 UH 2001-04-09
        if ( bd500GetTheCurrent().curr_action != m_create_index_parallel )
            g01abort (csp3_bd_msg, csp3_n_btree,
                      "CreIdxPar: wrong action.",
                      bd500GetTheCurrent().curr_action);
    }

    tgg00_RecPtr pRec; // InvListRecord

    if ( nr_for_update != m_Node.m_Current.bd300RootRequestKind() )
    {
        m_TrError = e_lock_dirty;
        return;
    }

#   if COMPILEMODE_MEO00 >= SLOW_MEO00
    t01sname   (bd_inv, "SecKey      ");
    t01moveobj (bd_inv, pSecKey,  POS_OFF_DIFF_BD00, SecKeyLen );
    t01sname   (bd_inv, "PrimKey     ");
    t01moveobj (bd_inv, pPrimKey, POS_OFF_DIFF_BD00, PrimKeyLen);
    t01bool    (bd_inv, "NextSecKey  ", bNextSecKey);
    t01bool    (bd_inv, "RefNeeded   ", bInvListRefNeeded);
    t01int4    (bd_inv, "RecIndex    ", RecIndex);
#   endif

    if ( NIL_RECINDEX_BD00 == RecIndex )
    {
        /* determine RecIndex => search InvList */

        if ( ! m_Node.bd600IsAccessable() ||
                ! m_Node.bd600IsLeaf()       ||
                (m_Node.m_pNode->nd_right() != NIL_PAGE_NO_GG00) )
        {
            bd500FindNode (pSecKey, SecKeyLen, LEAF_LEVEL_BD00);
            if (m_TrError != e_ok) return;
        }

        tbd_searchresult SecKeySearchResult;
        SecKeySearchResult.becomes  (nonefound);
        m_Node.bd600SearchRecord (pSecKey, SecKeyLen, RecIndex, SecKeySearchResult);

        if ( thisfound == SecKeySearchResult )
        {
            pRec = m_Node.bd600RecPtr (RecIndex);
        }
        else if ( nonefound == SecKeySearchResult )
        {
            /* if no record is found RecIndex is set to FIRST_REC_INDEX */
            --RecIndex;
        }
        else if ( nextfound == SecKeySearchResult )
        {
            /* this must not happen => SecKey order is wrong */
            m_TrError = e_not_implemented;
            return;
        }
        else if ( lastfound == SecKeySearchResult )
        {
            /* nothing to do, RecIndex is incremented by bNexSecKey */
        }
    }

    /* PRE: RecIndex is is set to last InvListRecord                            */
    /*      m_Node is pointing to the correct node = rightmost leaf in the tree */

    if (g01glob.treecheck)
    {
        tsp00_Int4 MaxRecIndex = m_Node.bd600MaxRecIndex();

#       if COMPILEMODE_MEO00 >= SLOW_MEO00
        t01p2int4 (bd_inv, "RecIndex    ", RecIndex, "MaxRecIndex ", MaxRecIndex);
#       endif

        if ( m_Node.m_pNode->nd_right() != NIL_PAGE_NO_GG00
                ||
                ((m_Node.m_pNode->nd_record_cnt() > 0) && (RecIndex != MaxRecIndex)) )
        {
#           if COMPILEMODE_MEO00 >= SLOW_MEO00
            t01p2int4      (bd_inv, "right       ", m_Node.m_pNode->nd_right(),
                            "record_cnt  ", m_Node.m_pNode->nd_record_cnt());
            t01basis_error (bd_inv, "AppendPrimKe", m_TrError);
#           endif
            g01abort (csp3_bd_msg, csp3_n_btree, "CreIdxPar: wrong RecInd.", RecIndex);
            m_TrError = e_not_implemented;
            return;
        }
    }

    if ( bNextSecKey )
    {
        /* a new InvList must be created */

        if ( bInvListRefNeeded )
        {
            const tsp00_Int4 ReqiredLen =
                cbd450_InvListRefSubTree::bd450NewSize (SecKeyLen);

            bd530AppendRecordSpace (pSecKey, SecKeyLen, ReqiredLen, pRec);
            if (e_ok != m_TrError) return;

            RecIndex = m_Node.bd600MaxRecIndex();

            /* create a new SubtreeRef record */
            cbd450_InvListRefSubTree InvList (*m_Node.m_Current.curr_trans,
                                              pRec, pSecKey, SecKeyLen,
                                              NIL_PAGE_NO_GG00 /* SubTreeRoot */,
                                              1                /* NumPrimKeys */,   // PTS 1131150 UH initialize with 1 instead of 0
                                              1                /* NumLeaves   */);

            ++(m_Node.m_pNode->ndLeafCount_bd00());

            bd400_SetToNewSubRoot ();
            if (e_ok != m_TrError) return;

            /* assign SubRootId to InvListReferenceRecord */
            InvList.bd450SetSubRoot (m_SubTreeLeaf.bd600GetId());

            /* create a new PrimKeyRecord */
            tgg00_RecPtr pPrimKeyRec;

            m_SubTree.bd530AppendRecordSpace (pPrimKey, PrimKeyLen,
                                              bd102RecAlign(cgg_rec_key_offset+PrimKeyLen), pPrimKeyRec);
            if (e_ok != m_TrError) return;
            bd400_ConstructSubTreeRecord (pPrimKeyRec, pPrimKey, PrimKeyLen, m_TrError);
        }
        else
        {
            ++RecIndex;
            bd400_CreateNewInvList (*this, m_Node, RecIndex,
                                    pSecKey, SecKeyLen, pPrimKey, PrimKeyLen, ! PROPAGATION_NEEDED);
        }
        return;
    }

    /* RecIndex is given, so m_Node is the correct/last LeafNode (RightNeighbor==nil) */
    /* The record may be an InvListArray or the last PrimKey in a SubTree.            */
    /* The append operation in the meaning of the words is done in the following.     */

    pRec = m_Node.bd600RecPtr(RecIndex);

    /* Check, if the SecKey is given ascending */
    if ( g01glob.treecheck ) // PTS 1109967 UH 2001-04-09
    {
        tsp00_LcompResult CompResult;

        s30cmp (pSecKey, POS_OFF_DIFF_BD00, SecKeyLen,
                pRec, POS_OFF_DIFF_BD00 + cgg_rec_key_offset,
                pRec->recKeyLen_gg00(),    CompResult);

        if ( l_less == CompResult )
        {
#           if COMPILEMODE_MEO00 >= SLOW_MEO00
            t01int4        (bd_inv, "CompResult  ", CompResult);
            t01basis_error (bd_inv, "AppendPrimKe", m_TrError);
            t01sname       (bd_inv, "SecKey      ");
            t01moveobj     (bd_inv, pSecKey, POS_OFF_DIFF_BD00, SecKeyLen );
            t01sname       (bd_inv, "RecKey      ");
            t01moveobj     (bd_inv, pRec, POS_OFF_DIFF_BD00 + cgg_rec_key_offset, pRec->recKeyLen_gg00());
#           endif
            g01abort (csp3_bd_msg, csp3_n_btree, "CreIdxPar: wrong SecKey ", RecIndex);
            m_TrError = e_not_implemented;
            return;
        }
    }

    if ( ilkSubTree_egg00 == pRec->recInvListKind_gg00() )
    {
        /* create new PrimKeyRecord */

        tgg00_RecPtr pPrimKeyRec;

        m_SubTree.bd530AppendRecordSpace (pPrimKey, PrimKeyLen,
                                          bd102RecAlign(cgg_rec_key_offset+PrimKeyLen), pPrimKeyRec);
        if (e_ok != m_TrError) return;
        bd400_ConstructSubTreeRecord     (pPrimKeyRec, pPrimKey, PrimKeyLen, m_TrError);

        /* update InvList-Record in InvTreeLeaf */
        cbd450_InvListRefSubTree InvList (pRec);
        InvList.bd450IncrNumPrimKeys ();

        /* update Leafcount Info in InvTreeLeaf */
        if ( InvList.bd450NumLeaves() < m_SubTree.bd500LeafCount() )
        {
            m_Node.m_pNode->ndLeafCount_bd00() -= InvList.bd450NumLeaves();
            m_Node.m_pNode->ndLeafCount_bd00() += m_SubTree.bd500LeafCount();
            InvList.bd450SetNumLeaves (m_SubTree.bd500LeafCount());
            /* it is propagated with a next AppendNode */
        }
    }
    else
    {
        /* append PrimKey to InvListArray */

        cbd450_InvListArray InvListArray (pRec);

        if ( InvListArray.bd450Size (PrimKeyLen) <= MAX_INVLISTLENGTH_BD00 )
        {
            const tsp00_Int4 RecSizeDelta = InvListArray.bd450Size(PrimKeyLen) -
                                            bd102RecAlign(pRec->recLen_gg00());

            if ( ! m_Node.bd600SpaceIsAvailable (RecSizeDelta) )
            {
                bd520LeafOverflow (pSecKey, SecKeyLen, ! FOR_INSERT_GBD500, RecSizeDelta, RecIndex);
                if (e_ok != m_TrError) return;
            }
            pRec = m_Node.bd600RecPtr (RecIndex);
            m_Node.bd600UpdRecordSpace (RecSizeDelta, RecIndex, pRec);
            if (e_ok != m_TrError) return;

            InvListArray.bd450Update (pRec);
            InvListArray.bd450InsertPrimKey (*(m_Node.m_Current.curr_trans),
                                             pRec->recNumPrimKeys_gg00(), pPrimKey, PrimKeyLen);
        }
        else
        {
            bd400_SetToNewSubRoot ();
            if (e_ok != m_TrError) return;
            bd400_InvListArrayOverflow (*this, m_Node, m_SubTree, m_SubTreeLeaf, RecIndex,
                                        pPrimKey, PrimKeyLen, pRec->recNumPrimKeys_gg00());
            /* no UnderFlowHandling for the InvTree, more appends are assumed */
        }
    }
}


Generated by  Doxygen 1.6.0   Back to index