This is an automated email from the ASF dual-hosted git repository.

joshinnis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-age.git


The following commit(s) were added to refs/heads/master by this push:
     new e4205f0  Improve performance of VLE cases
e4205f0 is described below

commit e4205f0cda11d542cacd9d1613c4e386763aebe5
Author: Josh Innis <[email protected]>
AuthorDate: Fri Mar 25 12:27:57 2022 -0700

    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;
---
 regress/expected/cypher_vle.out    | 10 +++++++
 regress/sql/cypher_vle.sql         |  5 ++++
 src/backend/parser/cypher_clause.c | 55 +++++++++++---------------------------
 3 files changed, 31 insertions(+), 39 deletions(-)

diff --git a/regress/expected/cypher_vle.out b/regress/expected/cypher_vle.out
index f461ee4..3bf7086 100644
--- a/regress/expected/cypher_vle.out
+++ b/regress/expected/cypher_vle.out
@@ -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);
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
              [...]
diff --git a/regress/sql/cypher_vle.sql b/regress/sql/cypher_vle.sql
index df80722..d184eec 100644
--- a/regress/sql/cypher_vle.sql
+++ b/regress/sql/cypher_vle.sql
@@ -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
diff --git a/src/backend/parser/cypher_clause.c 
b/src/backend/parser/cypher_clause.c
index 92d049d..fb6502d 100644
--- a/src/backend/parser/cypher_clause.c
+++ b/src/backend/parser/cypher_clause.c
@@ -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);

Reply via email to