From 0fb733182f4831718aae1fea13a40091831e6226 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 e385ca0f7e3..8e99806eb74 100644 --- a/system/jhtree/jhtree.cpp +++ b/system/jhtree/jhtree.cpp @@ -1864,6 +1864,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) { @@ -1874,7 +1875,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(); @@ -1966,7 +1967,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) @@ -1974,7 +1974,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; } } @@ -1987,18 +1986,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; } } @@ -2089,18 +2088,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; } }