19 #define DBTUX_SEARCH_CPP
35 Dbtux::findNodeToUpdate(TuxCtx& ctx, Frag& frag,
const KeyDataC& searchKey, TreeEnt searchEnt, NodeHandle& currNode)
37 const Index&
index = *c_indexPool.
getPtr(frag.m_indexId);
38 const Uint32 numAttrs = index.m_numAttrs;
39 const Uint32 prefAttrs = index.m_prefAttrs;
40 const Uint32 prefBytes = index.m_prefBytes;
41 KeyData entryKey(index.m_keySpec,
false, 0);
42 entryKey.set_buf(ctx.c_entryKey, MaxAttrDataSize << 2);
43 KeyDataC prefKey(index.m_keySpec,
false);
44 NodeHandle glbNode(frag);
46 thrjam(ctx.jamBuffer);
47 selectNode(currNode, currNode.m_loc);
48 prefKey.set_buf(currNode.getPref(), prefBytes, prefAttrs);
51 thrjam(ctx.jamBuffer);
52 ret = cmpSearchKey(ctx, searchKey, prefKey, prefAttrs);
54 if (ret == 0 && prefAttrs < numAttrs) {
55 thrjam(ctx.jamBuffer);
57 readKeyAttrs(ctx, frag, currNode.getEnt(0), entryKey, numAttrs);
58 ret = cmpSearchKey(ctx, searchKey, entryKey, numAttrs);
61 thrjam(ctx.jamBuffer);
63 ret = searchEnt.cmp(currNode.getEnt(0));
66 thrjam(ctx.jamBuffer);
67 const TupLoc loc = currNode.getLink(0);
68 if (loc != NullTupLoc) {
69 thrjam(ctx.jamBuffer);
74 if (! glbNode.isNull()) {
75 thrjam(ctx.jamBuffer);
82 thrjam(ctx.jamBuffer);
83 const TupLoc loc = currNode.getLink(1);
84 if (loc != NullTupLoc) {
85 thrjam(ctx.jamBuffer);
95 thrjam(ctx.jamBuffer);
105 Dbtux::findPosToAdd(TuxCtx& ctx, Frag& frag,
const KeyDataC& searchKey, TreeEnt searchEnt, NodeHandle& currNode, TreePos& treePos)
107 const Index& index = *c_indexPool.
getPtr(frag.m_indexId);
109 int hi = (int)currNode.getOccup();
110 KeyData entryKey(index.m_keySpec,
false, 0);
111 entryKey.set_buf(ctx.c_entryKey, MaxAttrDataSize << 2);
112 while (hi - lo > 1) {
113 thrjam(ctx.jamBuffer);
115 int j = (hi + lo) / 2;
117 readKeyAttrs(ctx, frag, currNode.getEnt(j), entryKey, index.m_numAttrs);
118 int ret = cmpSearchKey(ctx, searchKey, entryKey, index.m_numAttrs);
120 thrjam(ctx.jamBuffer);
122 ret = searchEnt.cmp(currNode.getEnt(j));
125 thrjam(ctx.jamBuffer);
127 }
else if (ret > 0) {
128 thrjam(ctx.jamBuffer);
136 ndbrequire(hi - lo == 1);
147 Dbtux::findPosToRemove(TuxCtx& ctx, Frag& frag,
const KeyDataC& searchKey, TreeEnt searchEnt, NodeHandle& currNode, TreePos& treePos)
149 const unsigned occup = currNode.getOccup();
150 for (
unsigned j = 0; j < occup; j++) {
151 thrjam(ctx.jamBuffer);
153 if (searchEnt.eq(currNode.getEnt(j))) {
154 thrjam(ctx.jamBuffer);
159 treePos.m_pos = occup;
168 Dbtux::searchToAdd(TuxCtx& ctx, Frag& frag,
const KeyDataC& searchKey, TreeEnt searchEnt, TreePos& treePos)
170 const TreeHead& tree = frag.m_tree;
171 NodeHandle currNode(frag);
172 currNode.m_loc = tree.m_root;
173 if (unlikely(currNode.m_loc == NullTupLoc)) {
175 thrjam(ctx.jamBuffer);
178 findNodeToUpdate(ctx, frag, searchKey, searchEnt, currNode);
179 treePos.m_loc = currNode.m_loc;
180 if (! findPosToAdd(ctx, frag, searchKey, searchEnt, currNode, treePos)) {
181 thrjam(ctx.jamBuffer);
191 Dbtux::searchToRemove(TuxCtx& ctx, Frag& frag,
const KeyDataC& searchKey, TreeEnt searchEnt, TreePos& treePos)
193 const TreeHead& tree = frag.m_tree;
194 NodeHandle currNode(frag);
195 currNode.m_loc = tree.m_root;
196 if (unlikely(currNode.m_loc == NullTupLoc)) {
198 thrjam(ctx.jamBuffer);
201 findNodeToUpdate(ctx, frag, searchKey, searchEnt, currNode);
202 treePos.m_loc = currNode.m_loc;
203 if (! findPosToRemove(ctx, frag, searchKey, searchEnt, currNode, treePos)) {
204 thrjam(ctx.jamBuffer);
216 Dbtux::findNodeToScan(Frag& frag,
unsigned idir,
const KeyBoundC& searchBound, NodeHandle& currNode)
218 const int jdir = 1 - 2 * int(idir);
219 const Index& index = *c_indexPool.
getPtr(frag.m_indexId);
220 const Uint32 numAttrs = searchBound.get_data().get_cnt();
221 const Uint32 prefAttrs = min(index.m_prefAttrs, numAttrs);
222 const Uint32 prefBytes = index.m_prefBytes;
223 KeyData entryKey(index.m_keySpec,
false, 0);
224 entryKey.set_buf(c_ctx.c_entryKey, MaxAttrDataSize << 2);
225 KeyDataC prefKey(index.m_keySpec,
false);
226 NodeHandle glbNode(frag);
229 selectNode(currNode, currNode.m_loc);
230 prefKey.set_buf(currNode.getPref(), prefBytes, prefAttrs);
236 ret = cmpSearchBound(c_ctx, searchBound, prefKey, prefAttrs);
241 readKeyAttrs(c_ctx, frag, currNode.getEnt(0), entryKey, numAttrs);
242 ret = cmpSearchBound(c_ctx, searchBound, entryKey, numAttrs);
243 ndbrequire(ret != 0);
252 const TupLoc loc = currNode.getLink(0);
253 if (loc != NullTupLoc) {
256 currNode.m_loc = loc;
259 if (! glbNode.isNull()) {
269 const TupLoc loc = currNode.getLink(1);
270 if (loc != NullTupLoc) {
275 currNode.m_loc = loc;
290 Dbtux::findPosToScan(Frag& frag,
unsigned idir,
const KeyBoundC& searchBound, NodeHandle& currNode, Uint16* pos)
292 const int jdir = 1 - 2 * int(idir);
293 const Index& index = *c_indexPool.
getPtr(frag.m_indexId);
294 const Uint32 numAttrs = searchBound.get_data().get_cnt();
296 int hi = (int)currNode.getOccup();
297 KeyData entryKey(index.m_keySpec,
false, 0);
298 entryKey.set_buf(c_ctx.c_entryKey, MaxAttrDataSize << 2);
299 while (hi - lo > 1) {
302 int j = (hi + lo) / 2;
303 int ret = (-1) * jdir;
306 readKeyAttrs(c_ctx, frag, currNode.getEnt(j), entryKey, numAttrs);
307 ret = cmpSearchBound(c_ctx, searchBound, entryKey, numAttrs);
308 ndbrequire(ret != 0);
313 }
else if (ret > 0) {
329 Dbtux::searchToScan(Frag& frag,
unsigned idir,
const KeyBoundC& searchBound, TreePos& treePos)
331 const TreeHead& tree = frag.m_tree;
332 NodeHandle currNode(frag);
333 currNode.m_loc = tree.m_root;
334 if (unlikely(currNode.m_loc == NullTupLoc)) {
339 findNodeToScan(frag, idir, searchBound, currNode);
340 treePos.m_loc = currNode.m_loc;
342 findPosToScan(frag, idir, searchBound, currNode, &pos);
343 const unsigned occup = currNode.getOccup();
351 treePos.m_pos = ZNIL;
358 treePos.m_pos = pos - 1;
361 treePos.m_pos = ZNIL;