| 8 | #include "./optimizations.h" |
| 9 | |
| 10 | void optimizePlan(ExecutionPlan *plan) { |
| 11 | // tries to compact filter trees, and remove redundant filters |
| 12 | compactFilters(plan); |
| 13 | |
| 14 | // scan optimizations order: |
| 15 | // 1. remove redundant scans which checks for the same node |
| 16 | // 2. try to use the indices |
| 17 | // given a label scan and an indexed property, apply index scan |
| 18 | // 3. given a filter which checks id condition, and full or label scan |
| 19 | // reduce it to id scan or label with id scan |
| 20 | // note: due to the scan optimization order |
| 21 | // label scan will be replaced with index scan when possible |
| 22 | // so the id filter remains |
| 23 | |
| 24 | // remove redundant SCAN operations |
| 25 | reduceScans(plan); |
| 26 | |
| 27 | // when possible, replace label scan and filter ops with index scans |
| 28 | utilizeIndices(plan); |
| 29 | |
| 30 | // scan label with least entities |
| 31 | optimizeLabelScan(plan); |
| 32 | |
| 33 | // try to reduce SCAN + FILTER to a node seek operation |
| 34 | seekByID(plan); |
| 35 | |
| 36 | // migrate filters on variable-length edges into the traversal operations |
| 37 | filterVariableLengthEdges(plan); |
| 38 | |
| 39 | // try to optimize cartesian product |
| 40 | reduceCartesianProductStreamCount(plan); |
| 41 | |
| 42 | // try to match disjoint entities by applying a join |
| 43 | applyJoin(plan); |
| 44 | |
| 45 | // try to reduce a number of filters into a single filter op |
| 46 | reduceFilters(plan); |
| 47 | |
| 48 | // reduce traversals where both src and dest nodes are already resolved |
| 49 | // into an expand into operation |
| 50 | reduceTraversal(plan); |
| 51 | |
| 52 | // try to reduce distinct if it follows aggregation |
| 53 | reduceDistinct(plan); |
| 54 | |
| 55 | // try to reduce execution plan incase it perform node or edge counting |
| 56 | reduceCount(plan); |
| 57 | |
| 58 | // let operations know about specified limit(s) |
| 59 | applyLimit(plan); |
| 60 | |
| 61 | // let operations know about specified skip(s) |
| 62 | applySkip(plan); |
| 63 | } |
| 64 |
no test coverage detected