Skip to content

Commit

Permalink
Bind Argument ops to the subplan they belong to (#2167)
Browse files Browse the repository at this point in the history
Co-authored-by: Roi Lipman <swilly22@users.noreply.github.com>
  • Loading branch information
jeffreylovitz and swilly22 committed Feb 27, 2022
1 parent aec17ed commit c6d9f18
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Expand Up @@ -268,7 +268,7 @@ OpBase *ExecutionPlan_LocateReferences
rax *refs_to_resolve
) {
return ExecutionPlan_LocateReferencesExcludingOps(
root, recurse_limit, NULL, 0, refs_to_resolve);
root, recurse_limit, NULL, 0, refs_to_resolve);
}

void _ExecutionPlan_LocateTaps
Expand Down Expand Up @@ -368,7 +368,8 @@ OpBase *ExecutionPlan_BuildOpsFromPath(ExecutionPlan *plan, const char **bound_v
match_stream_plan->record_map = plan->record_map;

// If we have bound variables, build an Argument op that represents them.
if(bound_vars) match_stream_plan->root = NewArgumentOp(plan, bound_vars);
if(bound_vars) match_stream_plan->root = NewArgumentOp(match_stream_plan,
bound_vars);

AST *ast = QueryCtx_GetAST();
// Build a temporary AST holding a MATCH clause.
Expand Down
20 changes: 18 additions & 2 deletions tests/flow/test_optional_match.py
@@ -1,5 +1,4 @@
import os
import sys
import re
from RLTest import Env
from redisgraph import Graph, Node, Edge
from base import FlowTestsBase
Expand Down Expand Up @@ -275,3 +274,20 @@ def test21_optional_filters_without_references(self):
actual_result = redis_graph.query(query)
expected_result = [['v1', 'v2']]
self.env.assertEquals(actual_result.result_set, expected_result)

# validate that the correct plan is populated and executed when OPTIONAL
# does not introduce any new variables
def test22_optional_repeats_reference(self):
global redis_graph
query = """MATCH (n1) OPTIONAL MATCH (n1) WHERE n1.nonexistent > 0 RETURN n1.v ORDER BY n1.v"""
plan = redis_graph.execution_plan(query)
# the first child of the Apply op should be a scan and the
# second should be the OPTIONAL subtree
self.env.assertTrue(re.search('Apply\s+All Node Scan | (n1)\s+Optional\s+Filter\s+Argument', plan))

actual_result = redis_graph.query(query)
expected_result = [['v1'],
['v2'],
['v3'],
['v4']]
self.env.assertEquals(actual_result.result_set, expected_result)

0 comments on commit c6d9f18

Please sign in to comment.