Skip to content
Permalink
Browse files
Improve performance of VLE cases
For some MATCH queries that use the VLE, there where unecessary
comparisons to ensure the correct output was generated. When the vertex
after the vle edge is not included in the query, the
age_match_vle_terminal_edge function does not need to be called.

Example:
MATCH (a)-[e*1..5]->() RETURN a, e;
  • Loading branch information
JoshInnis committed Mar 25, 2022
1 parent 6df5efb commit e4205f0cda11d542cacd9d1613c4e386763aebe5
Showing 3 changed files with 31 additions and 39 deletions.
@@ -449,6 +449,16 @@ $$) AS (e1 agtype);
13
(1 row)

SELECT count(*)
FROM cypher('cypher_vle', $$
MATCH (a)-[e*1..1]->()
RETURN a, e
$$) AS (e1 agtype, e2 agtype);
count
-------
13
(1 row)

-- Should return 1 path
SELECT * FROM cypher('cypher_vle', $$ MATCH p=()<-[e1*]-(:end)-[e2*]->(:begin) RETURN p $$) AS (result agtype);
result
@@ -157,6 +157,11 @@ SELECT count(*) FROM cypher('cypher_vle', $$
MATCH (a) MATCH ()-[e1*1..1]->(a)
RETURN e1
$$) AS (e1 agtype);
SELECT count(*)
FROM cypher('cypher_vle', $$
MATCH (a)-[e*1..1]->()
RETURN a, e
$$) AS (e1 agtype, e2 agtype);
-- Should return 1 path
SELECT * FROM cypher('cypher_vle', $$ MATCH p=()<-[e1*]-(:end)-[e2*]->(:begin) RETURN p $$) AS (result agtype);
-- Each should return 3
@@ -2686,17 +2686,6 @@ static List *make_directed_edge_join_conditions(
return quals;
}

static Node *make_null_const(int location)
{
A_Const *n;

n = makeNode(A_Const);
n->val.type = T_Null;
n->location = location;

return (Node *)n;
}

/*
* The joins are driven by edges. Under specific conditions, it becomes
* necessary to have knowledge about the previous edge and vertex and
@@ -2734,43 +2723,31 @@ static List *make_join_condition_for_edge(cypher_parsestate *cpstate,
List *args = NIL;
List *quals = NIL;

/*
* If the next node is not in the join tree, we don't need to make any
* quals.
*/
if (!next_node->in_join_tree)
{
return NIL;
}

/*
* If either the previous node or the next node are in the join tree,
* we need to create the age_match_vle_terminal_edge to compare the vle
* returned results against the two nodes.
*
* If the previous node and the next node are in the join tree, we need
* to create the age_match_vle_terminal_edge to compare the vle returned
* results against the two nodes.
*/
if (prev_node->in_join_tree || next_node->in_join_tree)
if (prev_node->in_join_tree)
{
func_name = makeString("age_match_vle_terminal_edge");
qualified_func_name = list_make2(ag_catalog, func_name);

/*
* When the previous node is in the join tree, get the vertex's id
* and pass to the function. Pass in NULL otherwise.
* Get the vertex's id and pass to the function. Pass in NULL
* otherwise.
*/
if (prev_node->in_join_tree)
{
left_id = (Node *)make_qual(cpstate, prev_node, "id");
}
else
{
left_id = make_null_const(-1);
}

/*
* When the next node is in the join tree, get the vertex's id and
* pass to the function. Pass in NULL otherwise.
*/
if (next_node->in_join_tree)
{
right_id = (Node *)make_qual(cpstate, next_node, "id");
}
else
{
right_id = make_null_const(-1);
}
left_id = (Node *)make_qual(cpstate, prev_node, "id");
right_id = (Node *)make_qual(cpstate, next_node, "id");

// create the argument list
args = list_make3(left_id, right_id, entity->expr);

0 comments on commit e4205f0

Please sign in to comment.