From 8f71433da2daa37bfca1a15a21a18f735199ffa9 Mon Sep 17 00:00:00 2001 From: cwy-p8d-u1 <sven-ove.haensel@stud.hs-hannover.de> Date: Fri, 15 Mar 2024 17:35:37 +0100 Subject: [PATCH] update queries --- .../eval/query/memgraph/queries/queries.txt | 2 +- .../eval/query/neo4j/queries/queries.txt | 4 +- .../eval/query/ongdb/queries/queries.txt | 4 +- .../eval/query/pg/queries/queries.txt | 51 ++++++++++++------- 4 files changed, 39 insertions(+), 22 deletions(-) diff --git a/code/infrastructure/eval/query/memgraph/queries/queries.txt b/code/infrastructure/eval/query/memgraph/queries/queries.txt index 4d0b895..b07ff75 100644 --- a/code/infrastructure/eval/query/memgraph/queries/queries.txt +++ b/code/infrastructure/eval/query/memgraph/queries/queries.txt @@ -1,4 +1,4 @@ -count|MATCH (n) return count(n); +count|MATCH (n) return n; anc|MATCH path=(node:Host)-[*]->(ancestor) RETURN ancestor, size(path) AS distance_upstream ORDER BY distance_upstream; desc|MATCH path=(node:Host)<-[*]-(descendant) RETURN descendant, size(path) AS distance_downstream ORDER BY distance_downstream; path|MATCH path = ((a {_uuid: 'A6A7C956-0132-5506-96D1-2A7DE97CB400'})-[*ALLSHORTEST(r,n|1)]->(b {_uuid:'8DA367BF-36C2-11E8-BF66-D9AA8AFF4A69'})) RETURN path; diff --git a/code/infrastructure/eval/query/neo4j/queries/queries.txt b/code/infrastructure/eval/query/neo4j/queries/queries.txt index d93ecc1..d07bb80 100644 --- a/code/infrastructure/eval/query/neo4j/queries/queries.txt +++ b/code/infrastructure/eval/query/neo4j/queries/queries.txt @@ -1,5 +1,5 @@ -count|MATCH (n) return count(n); +count|MATCH (n) return n; anc|MATCH path=(node:Host)-[*]->(ancestor) RETURN ancestor, length(path) AS distance_upstream ORDER BY distance_upstream; desc|MATCH path=(node:Host)<-[*]-(descendant) RETURN descendant, length(path) AS distance_downstream ORDER BY distance_downstream; -path|MATCH path = shortestPath((a:Subject WHERE a._uuid='0CF2BB3E-36B8-11E8-BF66-D9AA8AFF4A69') -[*]- (b:FileObject WHERE b._uuid = '586C56DA-CB56-745E-96CB-52069E742598')) RETURN path; +path|MATCH path = shortestPath((a WHERE a._uuid='A6A7C956-0132-5506-96D1-2A7DE97CB400') -[*]-> (b:FileObject WHERE b._uuid = '8DA367BF-36C2-11E8-BF66-D9AA8AFF4A69')) RETURN path; 2-hop|MATCH (startNode WHERE startNode._uuid = '9FF334BB-9072-D756-B290-556656D73728')-[*1..2]-(neighborhood) RETURN neighborhood; diff --git a/code/infrastructure/eval/query/ongdb/queries/queries.txt b/code/infrastructure/eval/query/ongdb/queries/queries.txt index 629bfb3..fab9261 100644 --- a/code/infrastructure/eval/query/ongdb/queries/queries.txt +++ b/code/infrastructure/eval/query/ongdb/queries/queries.txt @@ -1,5 +1,5 @@ -count|MATCH (n) return count(n); +count|MATCH (n) return n; anc|MATCH path=(node:Host)-[*]->(ancestor) RETURN ancestor, length(path) AS distance_upstream ORDER BY distance_upstream; desc|MATCH path=(node:Host)<-[*]-(descendant) RETURN descendant, length(path) AS distance_downstream ORDER BY distance_downstream; -path|MATCH (a:Subject) WHERE a._uuid = '0CF2BB3E-36B8-11E8-BF66-D9AA8AFF4A69' MATCH (b:FileObject) where b._uuid='586C56DA-CB56-745E-96CB-52069E742598' WITH a, b MATCH path = shortestPath((a)-[*]-(b)) RETURN path +path|MATCH (a) WHERE a._uuid = 'A6A7C956-0132-5506-96D1-2A7DE97CB400' MATCH (b:FileObject) where b._uuid='8DA367BF-36C2-11E8-BF66-D9AA8AFF4A69' WITH a, b MATCH path = shortestPath((a)-[*]->(b)) RETURN path 2-hop|MATCH (startNode) -[*1..2]-(neighborhood) WHERE startNode._uuid = '9FF334BB-9072-D756-B290-556656D73728' RETURN neighborhood \ No newline at end of file diff --git a/code/infrastructure/eval/query/pg/queries/queries.txt b/code/infrastructure/eval/query/pg/queries/queries.txt index 10b02a9..13e7a8d 100644 --- a/code/infrastructure/eval/query/pg/queries/queries.txt +++ b/code/infrastructure/eval/query/pg/queries/queries.txt @@ -1,4 +1,6 @@ -ancestors|WITH RECURSIVE AncestorCTE AS ( +count|select * from node_list; +--- +anc|WITH RECURSIVE AncestorCTE AS ( SELECT n.node_no, e.dest, n.type, 1 AS Level FROM node_list n JOIN edge_list e ON n.uuid = e.source @@ -14,21 +16,36 @@ ancestors|WITH RECURSIVE AncestorCTE AS ( ) SELECT DISTINCT node_no, dest, type, Level FROM AncestorCTE; --- -descendant|WITH RECURSIVE DescendantCTE AS ( - SELECT n.node_no, e.source, 1 AS Level - FROM node_list n - JOIN edge_list e ON n.uuid = e.dest - WHERE n.node_no = 1 -- Replace with the desired starting node_no - - UNION ALL - - SELECT n.node_no, e.source, a.Level + 1 - FROM node_list n - JOIN edge_list e ON n.uuid = e.dest - JOIN DescendantCTE a ON e.source = n.uuid - WHERE a.Level < 3 -- Replace with the desired level +desc|WITH RECURSIVE NodeCTE AS ( + -- Initial selection + SELECT + n.node_no, + e.source, + e.dest, + 1 AS Level + FROM + node_list n + JOIN + edge_list e ON n.uuid = e.dest + WHERE + n.node_no = 1 -- Replace with the desired starting node_no + + UNION ALL + + -- Recursive selection + SELECT + n.node_no, + e.source, + e.dest, + c.Level + 1 AS Level + FROM + edge_list e + JOIN + NodeCTE c ON e.dest = c.source + JOIN + node_list n ON e.dest = n.uuid ) -SELECT DISTINCT node_no, source, Level FROM DescendantCTE; +SELECT * FROM NodeCTE; --- path|WITH RECURSIVE search_path(edge_no, path, dest, visited, depth) AS ( SELECT @@ -73,7 +90,7 @@ SELECT FROM shortest_paths; --- -k-hop|WITH hop1 AS ( +2-hop|WITH hop1 AS ( SELECT DISTINCT e.source, e.dest FROM edge_list e WHERE e.source = '9FF334BB-9072-D756-B290-556656D73728' @@ -95,4 +112,4 @@ FROM ( UNION ALL SELECT dest FROM hop2 ) AS all_nodes ---WHERE node <> '9FF334BB-9072-D756-B290-556656D73728' +WHERE node <> '9FF334BB-9072-D756-B290-556656D73728' -- GitLab