diff options
author | unknown <pekka@mysql.com> | 2004-10-10 18:21:05 +0200 |
---|---|---|
committer | unknown <pekka@mysql.com> | 2004-10-10 18:21:05 +0200 |
commit | f5571c3def3ca43a120443207131fd07c4d04daa (patch) | |
tree | 133b1d543209bb4d3d705e81b5dfbaa2e814c921 /ndb | |
parent | cbd5ddc63fd841c89c9d0683a2b9809c1d51f3c7 (diff) | |
download | mariadb-git-f5571c3def3ca43a120443207131fd07c4d04daa.tar.gz |
NDB tux optim 16 - binary search on bounding node when adding entry
ndb/src/kernel/blocks/dbtux/DbtuxDebug.cpp:
tux optim 15 - binary search on bounding node when adding entry
ndb/src/kernel/blocks/dbtux/DbtuxMaint.cpp:
tux optim 15 - binary search on bounding node when adding entry
ndb/src/kernel/blocks/dbtux/DbtuxSearch.cpp:
tux optim 15 - binary search on bounding node when adding entry
ndb/src/kernel/blocks/dbtux/Times.txt:
tux optim 15 - binary search on bounding node when adding entry
Diffstat (limited to 'ndb')
-rw-r--r-- | ndb/src/kernel/blocks/dbtux/DbtuxDebug.cpp | 5 | ||||
-rw-r--r-- | ndb/src/kernel/blocks/dbtux/DbtuxMaint.cpp | 4 | ||||
-rw-r--r-- | ndb/src/kernel/blocks/dbtux/DbtuxSearch.cpp | 62 | ||||
-rw-r--r-- | ndb/src/kernel/blocks/dbtux/Times.txt | 5 |
4 files changed, 53 insertions, 23 deletions
diff --git a/ndb/src/kernel/blocks/dbtux/DbtuxDebug.cpp b/ndb/src/kernel/blocks/dbtux/DbtuxDebug.cpp index d88119976be..9207c938e3a 100644 --- a/ndb/src/kernel/blocks/dbtux/DbtuxDebug.cpp +++ b/ndb/src/kernel/blocks/dbtux/DbtuxDebug.cpp @@ -424,8 +424,9 @@ operator<<(NdbOut& out, const Dbtux::NodeHandle& node) } data = (const Uint32*)node.m_node + Dbtux::NodeHeadSize + tree.m_prefSize; const Dbtux::TreeEnt* entList = (const Dbtux::TreeEnt*)data; - for (unsigned pos = 0; pos < numpos; pos++) - out << " " << entList[pos]; + // print entries in logical order + for (unsigned pos = 1; pos <= numpos; pos++) + out << " " << entList[pos % numpos]; out << "]"; } out << "]"; diff --git a/ndb/src/kernel/blocks/dbtux/DbtuxMaint.cpp b/ndb/src/kernel/blocks/dbtux/DbtuxMaint.cpp index 24b030bf8ec..565e64f9aeb 100644 --- a/ndb/src/kernel/blocks/dbtux/DbtuxMaint.cpp +++ b/ndb/src/kernel/blocks/dbtux/DbtuxMaint.cpp @@ -120,7 +120,7 @@ Dbtux::execTUX_MAINT_REQ(Signal* signal) searchToAdd(signal, frag, c_searchKey, ent, treePos); #ifdef VM_TRACE if (debugFlags & DebugMaint) { - debugOut << treePos << endl; + debugOut << treePos << (treePos.m_match ? " - error" : "") << endl; } #endif if (treePos.m_match) { @@ -154,7 +154,7 @@ Dbtux::execTUX_MAINT_REQ(Signal* signal) searchToRemove(signal, frag, c_searchKey, ent, treePos); #ifdef VM_TRACE if (debugFlags & DebugMaint) { - debugOut << treePos << endl; + debugOut << treePos << (! treePos.m_match ? " - error" : "") << endl; } #endif if (! treePos.m_match) { diff --git a/ndb/src/kernel/blocks/dbtux/DbtuxSearch.cpp b/ndb/src/kernel/blocks/dbtux/DbtuxSearch.cpp index bffbb8f5594..7568e27ac74 100644 --- a/ndb/src/kernel/blocks/dbtux/DbtuxSearch.cpp +++ b/ndb/src/kernel/blocks/dbtux/DbtuxSearch.cpp @@ -31,10 +31,11 @@ Dbtux::searchToAdd(Signal* signal, Frag& frag, ConstData searchKey, TreeEnt sear const unsigned numAttrs = frag.m_numAttrs; NodeHandle currNode(frag); currNode.m_loc = tree.m_root; + // assume success + treePos.m_match = false; if (currNode.m_loc == NullTupLoc) { // empty tree jam(); - treePos.m_match = false; return; } NodeHandle glbNode(frag); // potential g.l.b of final node @@ -93,6 +94,7 @@ Dbtux::searchToAdd(Signal* signal, Frag& frag, ConstData searchKey, TreeEnt sear jam(); treePos.m_loc = currNode.m_loc; treePos.m_pos = 0; + // failed treePos.m_match = true; return; } @@ -100,9 +102,16 @@ Dbtux::searchToAdd(Signal* signal, Frag& frag, ConstData searchKey, TreeEnt sear } // access rest of current node accessNode(signal, currNode, AccFull); - for (unsigned j = 0, occup = currNode.getOccup(); j < occup; j++) { + // anticipate + treePos.m_loc = currNode.m_loc; + // binary search + int lo = -1; + int hi = currNode.getOccup(); + int ret; + while (1) { jam(); - int ret; + // hi - lo > 1 implies lo < j < hi + int j = (hi + lo) / 2; // read and compare attributes unsigned start = 0; readKeyAttrs(frag, currNode.getEnt(j), start, c_entryKey); @@ -113,25 +122,38 @@ Dbtux::searchToAdd(Signal* signal, Frag& frag, ConstData searchKey, TreeEnt sear // keys are equal, compare entry values ret = searchEnt.cmp(currNode.getEnt(j)); } - if (ret <= 0) { - jam(); - treePos.m_loc = currNode.m_loc; + if (ret < 0) + hi = j; + else if (ret > 0) + lo = j; + else { treePos.m_pos = j; - treePos.m_match = (ret == 0); + // failed + treePos.m_match = true; return; } + if (hi - lo == 1) + break; } - if (! bottomNode.isNull()) { + if (ret < 0) { jam(); - // backwards compatible for now - treePos.m_loc = bottomNode.m_loc; - treePos.m_pos = 0; - treePos.m_match = false; + treePos.m_pos = hi; return; } - treePos.m_loc = currNode.m_loc; - treePos.m_pos = currNode.getOccup(); - treePos.m_match = false; + if (hi < currNode.getOccup()) { + jam(); + treePos.m_pos = hi; + return; + } + if (bottomNode.isNull()) { + jam(); + treePos.m_pos = hi; + return; + } + jam(); + // backwards compatible for now + treePos.m_loc = bottomNode.m_loc; + treePos.m_pos = 0; } /* @@ -150,9 +172,12 @@ Dbtux::searchToRemove(Signal* signal, Frag& frag, ConstData searchKey, TreeEnt s const unsigned numAttrs = frag.m_numAttrs; NodeHandle currNode(frag); currNode.m_loc = tree.m_root; + // assume success + treePos.m_match = true; if (currNode.m_loc == NullTupLoc) { // empty tree jam(); + // failed treePos.m_match = false; return; } @@ -206,27 +231,26 @@ Dbtux::searchToRemove(Signal* signal, Frag& frag, ConstData searchKey, TreeEnt s jam(); treePos.m_loc = currNode.m_loc; treePos.m_pos = 0; - treePos.m_match = true; return; } break; } // access rest of current node accessNode(signal, currNode, AccFull); + // anticipate + treePos.m_loc = currNode.m_loc; // pos 0 was handled above for (unsigned j = 1, occup = currNode.getOccup(); j < occup; j++) { jam(); // compare only the entry if (searchEnt.eq(currNode.getEnt(j))) { jam(); - treePos.m_loc = currNode.m_loc; treePos.m_pos = j; - treePos.m_match = true; return; } } - treePos.m_loc = currNode.m_loc; treePos.m_pos = currNode.getOccup(); + // failed treePos.m_match = false; } diff --git a/ndb/src/kernel/blocks/dbtux/Times.txt b/ndb/src/kernel/blocks/dbtux/Times.txt index 698e93b80ef..8fbb695ef82 100644 --- a/ndb/src/kernel/blocks/dbtux/Times.txt +++ b/ndb/src/kernel/blocks/dbtux/Times.txt @@ -115,4 +115,9 @@ optim 15 mc02/a 34 ms 60 ms 72 pct [ corrected wasted space in index node ] +optim 16 mc02/a 34 ms 53 ms 53 pct + mc02/b 42 ms 75 ms 75 pct + +[ case a, b: binary search of bounding node when adding entry ] + vim: set et: |