~jlukas79/+junk/mysql-server

« back to all changes in this revision

Viewing changes to storage/falcon/WalkIndex.cpp

manual merge 6.0-main --> 6.0-bka-review

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2008 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#include <memory.h>
 
17
#include "Engine.h"
 
18
#include "WalkIndex.h"
 
19
#include "Index.h"
 
20
#include "Transaction.h"
 
21
#include "Database.h"
 
22
#include "Dbb.h"
 
23
#include "WalkIndex.h"
 
24
#include "WalkIndex.h"
 
25
#include "IndexRootPage.h"
 
26
 
 
27
#ifdef _DEBUG
 
28
#undef THIS_FILE
 
29
static const char THIS_FILE[]=__FILE__;
 
30
#endif
 
31
 
 
32
//////////////////////////////////////////////////////////////////////
 
33
// Construction/Destruction
 
34
//////////////////////////////////////////////////////////////////////
 
35
 
 
36
WalkIndex::WalkIndex(Index *index, Transaction *transaction, int flags, IndexKey *lower, IndexKey *upper) : IndexWalker(index, transaction, flags)
 
37
{
 
38
        if (lower)
 
39
                lowerBound.setKey(lower);
 
40
        
 
41
        if (upper)
 
42
                upperBound.setKey(upper);
 
43
        
 
44
        nodes = new UCHAR[transaction->database->dbb->pageSize];
 
45
        key = indexKey.key;
 
46
}
 
47
 
 
48
WalkIndex::~WalkIndex(void)
 
49
{
 
50
        delete [] nodes;
 
51
}
 
52
 
 
53
void WalkIndex::setNodes(int32 nextIndexPage, int length, Btn* stuff)
 
54
{
 
55
        memcpy(nodes, stuff, length);
 
56
        endNodes = (Btn*) (nodes + length);
 
57
        node.parseNode((Btn*) nodes, endNodes);
 
58
        nextPage = nextIndexPage;
 
59
}
 
60
 
 
61
Record* WalkIndex::getNext(bool lockForUpdate)
 
62
{
 
63
        for (;;)
 
64
                {
 
65
                int32 recordNumber = getNextNode();
 
66
                
 
67
                if (recordNumber < 0)
 
68
                        {
 
69
                        currentRecord = NULL;
 
70
                        
 
71
                        return NULL;
 
72
                        }
 
73
                
 
74
                keyLength = indexKey.keyLength;
 
75
                
 
76
                if ( (currentRecord = getValidatedRecord(recordNumber, lockForUpdate)) )
 
77
                        return currentRecord;
 
78
                }
 
79
}
 
80
 
 
81
int32 WalkIndex::getNextNode(void)
 
82
{
 
83
        for (;; first = true)
 
84
                {
 
85
                if (first)
 
86
                        {
 
87
                        first = false;
 
88
                        recordNumber = node.getNumber();
 
89
                        
 
90
                        if (recordNumber >= 0)
 
91
                                return recordNumber;
 
92
                        else if (recordNumber == END_LEVEL)
 
93
                                return -1;
 
94
                        }
 
95
                        
 
96
                node.getNext(endNodes);
 
97
                
 
98
                if (node.node < endNodes)
 
99
                        {
 
100
                        recordNumber = node.getNumber();
 
101
                        node.expandKey(&indexKey);
 
102
                        
 
103
                        if (recordNumber >= 0)
 
104
                                return recordNumber;
 
105
                        }
 
106
                
 
107
                if (nextPage == 0)
 
108
                        return -1;
 
109
                        
 
110
                IndexRootPage::repositionIndex(index->dbb, index->indexId, this);
 
111
                }
 
112
        
 
113
}