MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / _reduceScans

Function _reduceScans

src/execution_plan/optimizations/reduce_scans.c:29–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27}
28
29static void _reduceScans(ExecutionPlan *plan, OpBase *scan) {
30 // Return early if the scan has no child operations.
31 if(scan->childCount == 0) return;
32
33 // The scan operation should be operating on a single alias.
34 ASSERT(array_len(scan->modifies) == 1);
35 const char *scanned_alias = scan->modifies[0];
36
37 // Collect variables bound before this operation.
38 rax *bound_vars = raxNew();
39 for(int i = 0; i < scan->childCount; i ++) {
40 ExecutionPlan_BoundVariables(scan->children[i], bound_vars,
41 scan->children[i]->plan);
42 }
43
44 if(raxFind(bound_vars, (unsigned char *)scanned_alias, strlen(scanned_alias)) != raxNotFound) {
45 // If the alias the scan operates on is already bound, the scan operation is redundant.
46 if(scan->type == OPType_NODE_BY_LABEL_SCAN) {
47 // If we are performing a label scan, introduce a conditional traversal to filter by label.
48 OpBase *traverse = _LabelScanToConditionalTraverse((NodeByLabelScan *)scan);
49 ExecutionPlan_ReplaceOp(plan, scan, traverse);
50 } else {
51 // Remove the redundant scan op.
52 ExecutionPlan_RemoveOp(plan, scan);
53 }
54 OpBase_Free(scan);
55 }
56 raxFree(bound_vars);
57}
58
59void reduceScans(ExecutionPlan *plan) {
60 // Collect all SCAN operations within the execution plan.

Callers 1

reduceScansFunction · 0.85

Calls 6

array_lenFunction · 0.85
ExecutionPlan_ReplaceOpFunction · 0.85
ExecutionPlan_RemoveOpFunction · 0.85
OpBase_FreeFunction · 0.85

Tested by

no test coverage detected