From 7bf37672c41c84182063e6a25cb3ca4306dd142f Mon Sep 17 00:00:00 2001 From: danielhanrahan Date: Mon, 12 Jun 2023 16:24:55 +0100 Subject: Fix for recursive SQL returning extra level of descendants Recursive SQL queries are incorrectly returning maxDepth + 1 levels of fragments due to incorrect comparison in the WHERE clause. This code is used by getDataNodes and queryDataNodes to prefetch the descendants before converting to datanodes. Prefetching extra descendants causes high memory usage. Issue-ID: CPS-1716 Signed-off-by: danielhanrahan Change-Id: Ie22215c0c7018cd293f73cf75adca2cd55f218a6 --- .../src/main/java/org/onap/cps/spi/repository/FragmentRepository.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cps-ri') diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java index 425a7267d..82c422f6f 100755 --- a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java +++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java @@ -119,7 +119,7 @@ public interface FragmentRepository extends JpaRepository, + " UNION " + " SELECT c.id, depth + 1 " + " FROM fragment c INNER JOIN parent_search p ON c.parent_id = p.id" - + " WHERE depth <= (SELECT CASE WHEN :maxDepth = -1 THEN " + Integer.MAX_VALUE + " ELSE :maxDepth END) " + + " WHERE depth < (SELECT CASE WHEN :maxDepth = -1 THEN " + Integer.MAX_VALUE + " ELSE :maxDepth END) " + ") " + "SELECT f.id, anchor_id AS anchorId, xpath, f.parent_id AS parentId, CAST(attributes AS TEXT) AS attributes " + "FROM fragment f INNER JOIN parent_search p ON f.id = p.id", @@ -142,7 +142,7 @@ public interface FragmentRepository extends JpaRepository, + " UNION " + " SELECT c.id, depth + 1 " + " FROM fragment c INNER JOIN parent_search p ON c.parent_id = p.id" - + " WHERE depth <= (SELECT CASE WHEN :maxDepth = -1 THEN " + Integer.MAX_VALUE + " ELSE :maxDepth END) " + + " WHERE depth < (SELECT CASE WHEN :maxDepth = -1 THEN " + Integer.MAX_VALUE + " ELSE :maxDepth END) " + ") " + "SELECT f.id, anchor_id AS anchorId, xpath, f.parent_id AS parentId, CAST(attributes AS TEXT) AS attributes " + "FROM fragment f INNER JOIN parent_search p ON f.id = p.id", -- cgit 1.2.3-korg