From ec87f797ccf80a5e3c424485fdc94b7c50ad5ece Mon Sep 17 00:00:00 2001 From: Richard Chapman Date: Wed, 20 Nov 2024 14:58:30 +0000 Subject: [PATCH] HPCC-32856 CKeyCursor should link parent nodes as well as current node Changes following review Signed-off-by: Richard Chapman --- system/jhtree/jhtree.cpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/system/jhtree/jhtree.cpp b/system/jhtree/jhtree.cpp index 816d30d642a..14b6b15c743 100644 --- a/system/jhtree/jhtree.cpp +++ b/system/jhtree/jhtree.cpp @@ -1769,6 +1769,7 @@ bool CKeyCursor::_next(IContextLogger *ctx) if (node != NULL) { nodeKey = 0; + // Update the nodekey indexes of any parent nodes that are still relevant, and clear any that are not unsigned depth = key.getBranchDepth(); while (depth) { @@ -1779,7 +1780,7 @@ bool CKeyCursor::_next(IContextLogger *ctx) unsigned parentNodeKey = parentNodeKeys[depth]; if (parentNodeKey < numParentKeys-1) { - parentNodeKeys[depth] = parentNodeKey; + parentNodeKeys[depth] = parentNodeKey+1; break; } parents[depth].clear(); @@ -1871,7 +1872,6 @@ bool CKeyCursor::_gtEqual(IContextLogger *ctx) int rc = node->compareValueAt(recordBuffer, ++nodeKey); if (rc <= 0) { - // printf("Still in leaf node at level %u pos %u\n", depth, nodeKey); return true; } if (nodeKey < numKeys-1) @@ -1879,7 +1879,6 @@ bool CKeyCursor::_gtEqual(IContextLogger *ctx) rc = node->compareValueAt(recordBuffer, numKeys-1); if (rc <= 0) { - // printf("Still in leaf node at level %u\n", depth); lwm = nodeKey+1; } } @@ -1892,18 +1891,18 @@ bool CKeyCursor::_gtEqual(IContextLogger *ctx) depth--; if (depth < maxParentNodes) { - node.set(parents[depth]); - if (node) + const CJHSearchNode *startnode = parents[depth]; + if (startnode) { - unsigned numParentKeys = node->getNumKeys(); + unsigned numParentKeys = startnode->getNumKeys(); unsigned parentNodeKey = parentNodeKeys[depth]; if (parentNodeKey < numParentKeys-1) { - int rc = node->compareValueAt(recordBuffer, numParentKeys-1); + int rc = startnode->compareValueAt(recordBuffer, numParentKeys-1); if (rc <= 0) { lwm = parentNodeKey+1; - // printf("Still in parent node at level %u %u\n", depth, numParentKeys); + node.set(startnode); break; } } @@ -1994,18 +1993,18 @@ bool CKeyCursor::_ltEqual(IContextLogger *ctx) depth--; if (depth < maxParentNodes) { - node.set(parents[depth]); - if (node) + const CJHSearchNode *startnode = parents[depth]; + if (startnode) { - unsigned numParentKeys = node->getNumKeys(); + unsigned numParentKeys = startnode->getNumKeys(); unsigned parentNodeKey = parentNodeKeys[depth]; if (parentNodeKey < numParentKeys-1) { - int rc = node->compareValueAt(recordBuffer, numParentKeys-1); + int rc = startnode->compareValueAt(recordBuffer, numParentKeys-1); if (rc < 0) { lwm = parentNodeKey+1; - printf("Still in parent node at level %u %u\n", depth, numParentKeys); + node.set(startnode); break; } }